Browse Source

fixed const typo

Toby Chui 11 months ago
parent
commit
ae23fccfec
2 changed files with 25 additions and 37 deletions
  1. 24 34
      InkyDash/InkyDash.ino
  2. 1 3
      InkyDash/battery.ino

+ 24 - 34
InkyDash/InkyDash.ino

@@ -16,19 +16,15 @@
 // BUSY -> GPIO4, RST -> GPIO2, DC -> GPIO0, CS -> GPIO15, CLK -> GPIO14, DIN -> GPIO13, GND -> GND, 3.3V -> 3.3V
 // BUSY -> GPIO4, RST -> GPIO2, DC -> GPIO0, CS -> GPIO15, CLK -> GPIO14, DIN -> GPIO13, GND -> GND, 3.3V -> 3.3V
 
 
 /*
 /*
-  Power Settings
-
-  If your device is designed to be plugged in
-  set LOW_POWER_MODE to false
-
-  If your device is powered with battery and
-  GPIO16 / D0 is connected to RST with a resistor
-  (resistor value depends on development board)
-  set LOW_POWER_MODE to true
-
-  If yout are not sure, set it to false
+    Deep Sleep Mode
+    
+    Some ESP8266 can do deep sleep but most don't
+    deal to the use of CH340. Set it to true
+    if you are using the bare ESP8266 module and you
+    sure your module support deep sleep.
+    Otherwise, leave it as false
 */
 */
-#define LOW_POWER_MODE true
+#define USE_DEEP_SLEEP false
 
 
 /* 
 /* 
   Display refresh interval
   Display refresh interval
@@ -36,8 +32,8 @@
   Too frequent interval in low power mode might results getting ban by weather API / NTP servers 
   Too frequent interval in low power mode might results getting ban by weather API / NTP servers 
   If you are not using low power mode, edit the high pwr mode interval instead
   If you are not using low power mode, edit the high pwr mode interval instead
 */
 */
-#define REFRESH_INTERVAL 900e6 //900 seconds, aka 15 minutes
-#define REFRESH_INTERVAL_HIGH_PWR_MODE 900000 //900 ms, aka 15 minutes
+#define REFRESH_INTERVAL 900e6 //900 seconds, aka 15 minutes, only work on some ESP8266
+#define REFRESH_INTERVAL_HIGH_PWR_MODE 900000 //900 s, aka 15 minutes, work on all ESP8266
 
 
 #define SHOW_PREVIOUS_NEXT_MONTH_DAYS true //Show previous & next months days as well
 #define SHOW_PREVIOUS_NEXT_MONTH_DAYS true //Show previous & next months days as well
 
 
@@ -65,14 +61,10 @@
 #include <ESP8266WiFi.h>
 #include <ESP8266WiFi.h>
 #include <WiFiManager.h>
 #include <WiFiManager.h>
 #include <ESP8266TrueRandom.h>
 #include <ESP8266TrueRandom.h>
+#include <WiFiUdp.h>
 #include <NTPClient.h>
 #include <NTPClient.h>
 #include <ESP8266HTTPClient.h>
 #include <ESP8266HTTPClient.h>
-#include <WiFiUdp.h>
 #include <ArduinoJson.h>
 #include <ArduinoJson.h>
-#include <TaskScheduler.h>
-
-
-
 
 
 /* WiFi and Connections */
 /* WiFi and Connections */
 WiFiManager wifiManager;
 WiFiManager wifiManager;
@@ -123,11 +115,6 @@ float maxTemp = 0.0;
 float minTemp = 0.0;
 float minTemp = 0.0;
 int batRemain = 0; //In percentage
 int batRemain = 0; //In percentage
 
 
-/* Schedulers */
-void datetimeUpdateCallback();
-Task t_dt(REFRESH_INTERVAL_HIGH_PWR_MODE, TASK_FOREVER, &datetimeUpdateCallback); //Frame update
-Scheduler runner;
-
 void setup() {
 void setup() {
   //Start debug serial
   //Start debug serial
   Serial.begin(115200);
   Serial.begin(115200);
@@ -136,14 +123,16 @@ void setup() {
   display.init(115200);
   display.init(115200);
 
 
   //Set D0 to wakeup pin
   //Set D0 to wakeup pin
-  pinMode(D0,WAKEUP_PULLUP);
+  //pinMode(D0,WAKEUP_PULLUP);
   
   
   //Draw starting frame
   //Draw starting frame
   display.setRotation(3);
   display.setRotation(3);
-  if (!LOW_POWER_MODE) {
+  /*
+  if (!USE_DEEP_SLEEP) {
     display.drawPaged(drawStartingFrame);
     display.drawPaged(drawStartingFrame);
     delay(100);
     delay(100);
   }
   }
+  */
 
 
   // Connect to Wi-Fi
   // Connect to Wi-Fi
   /*
   /*
@@ -158,7 +147,6 @@ void setup() {
     Serial.print("IP address:\t");
     Serial.print("IP address:\t");
     Serial.println(WiFi.localIP());
     Serial.println(WiFi.localIP());
   */
   */
-
   wifiManager.setAPCallback(configModeCallback);
   wifiManager.setAPCallback(configModeCallback);
   wifiManager.autoConnect("InkyDash");
   wifiManager.autoConnect("InkyDash");
 
 
@@ -173,6 +161,7 @@ void setup() {
   delay(1000);
   delay(1000);
 
 
   //Randomly get one of the NTP server from the list and request time
   //Randomly get one of the NTP server from the list and request time
+  Serial.println("Resolving NTP server");
   const char* randomNtpServer = getRandomNtpServer(ntpServers);
   const char* randomNtpServer = getRandomNtpServer(ntpServers);
   Serial.println("Using NTP Server: " + String(randomNtpServer));
   Serial.println("Using NTP Server: " + String(randomNtpServer));
   NTPClient timeClient(UDPconn, randomNtpServer);
   NTPClient timeClient(UDPconn, randomNtpServer);
@@ -180,7 +169,7 @@ void setup() {
   ntpClient.setTimeOffset(28800);
   ntpClient.setTimeOffset(28800);
 
 
   //Draw home page
   //Draw home page
-  if (LOW_POWER_MODE) {
+  if (USE_DEEP_SLEEP) {
     //Get weather information from API
     //Get weather information from API
     updateCurrentWeatherInfo();
     updateCurrentWeatherInfo();
     //Render the calender page
     //Render the calender page
@@ -189,14 +178,15 @@ void setup() {
     ESP.deepSleep(REFRESH_INTERVAL);
     ESP.deepSleep(REFRESH_INTERVAL);
     delay(100);
     delay(100);
     //After deep sleep mode, device will reset and not entering the loop() session
     //After deep sleep mode, device will reset and not entering the loop() session
-  } else {
-    runner.init();
-    Serial.println("Initialized scheduler");
-    runner.addTask(t_dt); //Date-time update task
-    t_dt.enable();
   }
   }
 }
 }
 
 
 void loop() {
 void loop() {
-  runner.execute();
+  datetimeUpdateCallback();
+  Serial.println("Entering sleep mode");
+  int cc = REFRESH_INTERVAL_HIGH_PWR_MODE/1000;
+  for (int i = 0; i < cc; i++){
+    //Prevent delay overflow
+    delay(1000);
+  }
 }
 }

+ 1 - 3
InkyDash/battery.ino

@@ -21,10 +21,8 @@ void updateBatteryReading() {
 
 
   //Convert voltage to percentage
   //Convert voltage to percentage
   int percentage = mapfloat(voltage, 3.2, 4.2, 0, 100);
   int percentage = mapfloat(voltage, 3.2, 4.2, 0, 100);
+  percentage = constrain(percentage, 0, 100);
   batRemain = percentage;
   batRemain = percentage;
-  Serial.println(rawValue);
-  Serial.println(voltage);
-  Serial.println(batRemain);
 }
 }
 
 
 //Draw the battery icon at the bottom right hand corner
 //Draw the battery icon at the bottom right hand corner