Ver código fonte

Дабавил MAX7219, сделал вывод времени

Vladimir N. Shilov 9 anos atrás
pai
commit
be5f567780
2 arquivos alterados com 98 adições e 16 exclusões
  1. 87 16
      app/application.cpp
  2. 11 0
      include/configuration.h

+ 87 - 16
app/application.cpp

@@ -8,28 +8,35 @@
 ///////////////////////////////////////////////////////////////////
 
 #include "webserver.h"
+#include "max7219.h"
 
 DHT dht(DHT_PIN, DHT22);
 
 Timer procTimer;
+//Timer serialTimer;
 Timer displayTimer;
+
 bool state = false;
 // Sensors string values
 String StrT, StrRH, StrHI, StrCR, StrCF, StrTime;
 String StrVDD, StrADC;
 
+// date and time
+uint16_t Year, Month, Day, Hour, Minute, Second;
+
 Timer httpcTimer;
 HttpClient thingSpeak;
 
 /* FTPServer ftp; */
 
-void process();
-void showValues();
-void connectOk();
-void connectFail();
+void process(void);
+//void showValues(void);
+void connectOk(void);
+void connectFail(void);
 void onDataSent(HttpClient& client, bool successful);
-void sendData();
+void sendData(void);
 void onNtpReceive(NtpClient& client, time_t timestamp);
+void showTime(void);
 
 NtpClient ntpClient ("ntps1-0.cs.tu-berlin.de", 60, onNtpReceive);
 
@@ -49,14 +56,17 @@ void init()
 	digitalWrite(CONTROL_PIN, LOW);
 
 	// Restart main screen output
-	procTimer.restart();
-	displayTimer.stop();
+//	procTimer.restart();
+//	serialTimer.stop();
 
 	//wait for sensor startup
 	delay(1000);
 	// DHT sensor start
 	dht.begin();
 
+	// 7-segment output
+	MAX7219_Init();
+
 	// set timezone hourly difference to UTC
 	SystemClock.setTimeZone(ActiveConfig.AddTZ);
 
@@ -69,9 +79,68 @@ void init()
 	// ðàç â ìèíóòó?
 	procTimer.initializeMs(60000, process).start();
 	process();
+
+	// îáíîâëåíèå ýêðàíà äâà ðàçà â ñåêóíäó
+	displayTimer.initializeMs(500, showTime).start();
 }
 
-void showValues()
+void showTime(void)
+{
+	static String oldStrTime;
+	static uint16_t oldHour, oldMinute;
+
+	StrTime = SystemClock.getSystemTimeString();
+
+	if (oldStrTime != StrTime)
+	{
+		Vector<String> datetime;
+		int idx = splitString(StrTime, ' ' , datetime);
+		if (idx == 2)
+		{
+			// date
+			Vector<String> date;
+			int di = splitString(datetime[0], '-', date);
+			if(di == 3)
+			{
+				Year = date[0].toInt();
+				Month = date[1].toInt();
+				Day = date[2].toInt();
+			}
+			// time
+			Vector<String> time;
+			int ti = splitString(datetime[1], ':', time);
+			if(ti == 3)
+			{
+				Hour = time[0].toInt();
+				Minute = time[1].toInt();
+				Second = time[2].toInt();
+			}
+		}
+
+		oldStrTime = StrTime;
+		MAX7219_writeData(MAX7219_DIGIT2, SYM_Minus);
+		if (oldMinute != Minute)
+		{
+			oldMinute = Minute;
+			MAX7219_writeData(MAX7219_DIGIT3, Minute/10);
+			MAX7219_writeData(MAX7219_DIGIT4, Minute%10);
+			if (oldHour != Hour)
+			{
+				oldHour = Hour;
+				MAX7219_writeData(MAX7219_DIGIT0, Hour/10);
+				MAX7219_writeData(MAX7219_DIGIT1, Hour%10);
+			}
+		}
+	}
+	else // time the same, output blank for "hh mm"
+	{
+		MAX7219_writeData(MAX7219_DIGIT2, SYM_Minus);
+	}
+
+}
+
+/*
+void showValues(void)
 {
 	Serial.print("Date & Time: ");
 	Serial.println(SystemClock.getSystemTimeString());
@@ -101,11 +170,10 @@ void showValues()
 
 	Serial.println("");
 }
+*/
 
 void process()
 {
-	StrTime = SystemClock.getSystemTimeString();
-
 	float t = dht.readTemperature() + ActiveConfig.AddT;
 	float h = dht.readHumidity() + ActiveConfig.AddRH;
 	float hi = dht.getHeatIndex();
@@ -118,9 +186,9 @@ void process()
 		state = h < ActiveConfig.RangeMin || h > ActiveConfig.RangeMax;
 
 	digitalWrite(CONTROL_PIN, state);
-	StrT = String(t, 1);
-	StrRH = String(h, 1);
-	StrHI = String(hi, 1);
+	StrT = String(t, 0);
+	StrRH = String(h, 0);
+	StrHI = String(hi, 0);
 	StrCR = String(cr, 0);
 	switch(cf)
 	{
@@ -158,11 +226,13 @@ void process()
 
 	StrADC = String(system_adc_read());
 	StrVDD = String(system_get_vdd33());
-
-	if (!displayTimer.isStarted())
-		displayTimer.initializeMs(20000, showValues).start();
+/*
+	if (!serialTimer.isStarted())
+		serialTimer.initializeMs(20000, showValues).start();
 	// îáíîâëåíèå âûâîäà -- ðàç â 20 ñåê. îáíîâëåíèå äàííûõ -- ðàç â ìèíóòó.
+*/
 }
+
 /*
 void startFTP()
 {
@@ -175,6 +245,7 @@ void startFTP()
 	// You can also use special FTP comand: "fsformat" for clearing file system (for example from TotalCMD)
 }
 */
+
 void connectOk()
 {
 //	debugf("connected");

+ 11 - 0
include/configuration.h

@@ -10,12 +10,23 @@
 	#define WIFI_PWD "Heaven-32847"
 #endif
 
+#define PinSet(pin)		GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, pin)
+#define PinRes(pin)		GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, pin)
+#define Pin16Set		WRITE_PERI_REG(RTC_GPIO_OUT, (READ_PERI_REG(RTC_GPIO_OUT) & (uint32)0xffffffff))
+#define Pin16Res		WRITE_PERI_REG(RTC_GPIO_OUT, (READ_PERI_REG(RTC_GPIO_OUT) & (uint32)0xfffffffe))
+
 // Pin for communication with DHT sensor
 #define DHT_PIN 2
 
 // Pin for trigger control output
 #define CONTROL_PIN 16
 
+// MAX7219
+#define PIN_SCK		14
+#define PIN_MOSI	13
+#define PIN_SS		12
+
+
 #define METEO_CONFIG_FILE ".meteo.conf" // leading point for security reasons :)
 
 enum TriggerType