Changed graph render to match nightscout; constant NTP resync to avoid massive clock drift during deep sleep
This commit is contained in:
@@ -39,6 +39,8 @@ void setup() {
|
|||||||
while (!Serial) { delay(10); }
|
while (!Serial) { delay(10); }
|
||||||
Serial.println("Nightscout CGM BS Monitor starting...");
|
Serial.println("Nightscout CGM BS Monitor starting...");
|
||||||
|
|
||||||
|
print_wakeup_reason();
|
||||||
|
|
||||||
ConnectToWifi();
|
ConnectToWifi();
|
||||||
|
|
||||||
struct tm timeinfo;
|
struct tm timeinfo;
|
||||||
@@ -101,10 +103,26 @@ void setup() {
|
|||||||
SleepUntilNextReading(lastSyncTime);
|
SleepUntilNextReading(lastSyncTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void print_wakeup_reason(){
|
||||||
|
esp_sleep_wakeup_cause_t wakeup_reason;
|
||||||
|
|
||||||
|
wakeup_reason = esp_sleep_get_wakeup_cause();
|
||||||
|
|
||||||
|
switch(wakeup_reason)
|
||||||
|
{
|
||||||
|
case ESP_SLEEP_WAKEUP_EXT0 : Serial.println("Wakeup caused by external signal using RTC_IO"); break;
|
||||||
|
case ESP_SLEEP_WAKEUP_EXT1 : Serial.println("Wakeup caused by external signal using RTC_CNTL"); break;
|
||||||
|
case ESP_SLEEP_WAKEUP_TIMER : Serial.println("Wakeup caused by timer"); break;
|
||||||
|
case ESP_SLEEP_WAKEUP_TOUCHPAD : Serial.println("Wakeup caused by touchpad"); break;
|
||||||
|
case ESP_SLEEP_WAKEUP_ULP : Serial.println("Wakeup caused by ULP program"); break;
|
||||||
|
default : Serial.printf("Wakeup was not caused by deep sleep: %d\n",wakeup_reason); break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void initTime()
|
void initTime()
|
||||||
{
|
{
|
||||||
struct tm timeinfo;
|
struct tm timeinfo;
|
||||||
if(!getLocalTime(&timeinfo))
|
//if(!getLocalTime(&timeinfo))
|
||||||
configTime(0, 0, ntpServer);
|
configTime(0, 0, ntpServer);
|
||||||
while(!getLocalTime(&timeinfo)){
|
while(!getLocalTime(&timeinfo)){
|
||||||
Serial.println("Sleeping until time is set..");
|
Serial.println("Sleeping until time is set..");
|
||||||
@@ -137,7 +155,7 @@ void SleepUntilNextReading(time_t lastReading) {
|
|||||||
Serial.println(" seconds diff between lastReading and current time");
|
Serial.println(" seconds diff between lastReading and current time");
|
||||||
int secondsToSleep = 300 - (int)timeDiff;
|
int secondsToSleep = 300 - (int)timeDiff;
|
||||||
//Add one more to not jump the gun
|
//Add one more to not jump the gun
|
||||||
secondsToSleep += 3;
|
secondsToSleep += 20;
|
||||||
if(secondsToSleep > 0 && secondsToSleep < 300) {
|
if(secondsToSleep > 0 && secondsToSleep < 300) {
|
||||||
//secondsToSleep = secondsToSleep + 7;
|
//secondsToSleep = secondsToSleep + 7;
|
||||||
Serial.print("Sleeping ");
|
Serial.print("Sleeping ");
|
||||||
@@ -210,7 +228,10 @@ void TurnOffEPD() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SleepFiveMins() {
|
void SleepFiveMins() {
|
||||||
esp_sleep_enable_timer_wakeup(285 * uS_TO_S_FACTOR);
|
int secondsToSleep = 300;
|
||||||
|
Serial.print("Sleeping ");
|
||||||
|
Serial.println(secondsToSleep);
|
||||||
|
esp_sleep_enable_timer_wakeup(secondsToSleep * uS_TO_S_FACTOR);
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
TurnOffEPD();
|
TurnOffEPD();
|
||||||
esp_deep_sleep_start();
|
esp_deep_sleep_start();
|
||||||
@@ -220,18 +241,21 @@ void RenderGraph(JsonArray sgvRecords) {
|
|||||||
boolean redrawScreen = true;
|
boolean redrawScreen = true;
|
||||||
double x = 0;
|
double x = 0;
|
||||||
double y = 100;
|
double y = 100;
|
||||||
double cnt = 0;
|
double cnt = -45;
|
||||||
|
|
||||||
for(JsonVariant v : sgvRecords) {
|
//for(JsonVariant v : sgvRecords) {
|
||||||
|
for(int i=sgvRecords.size(); i >= 0; i--) {
|
||||||
|
|
||||||
JsonObject obj = v.as<JsonObject>();
|
JsonObject obj = sgvRecords[i].as<JsonObject>(); //v.as<JsonObject>();
|
||||||
Serial.println(obj["sgv"].as<String>());
|
Serial.println(obj["sgv"].as<String>());
|
||||||
if(obj["device"].as<String>().indexOf("xDrip") == -1)
|
if(obj["device"].as<String>().indexOf("xDrip") == -1)
|
||||||
continue;
|
continue;
|
||||||
if(cnt > 45)
|
if(cnt > 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Graph(display, cnt, obj["sgv"].as<double>(), 20, 110, 210, 105, 0,45, 5,60,180,10,"", "", "", COLOR1, COLOR1, COLOR2, COLOR1, COLOR0, redrawScreen);
|
//Graph(display, cnt, obj["sgv"].as<double>(), 20, 110, 210, 105, 0,45, 5,60,180,10,"", "", "", COLOR1, COLOR1, COLOR2, COLOR1, COLOR0, redrawScreen);
|
||||||
|
Graph(display, cnt, obj["sgv"].as<double>(), 20, 110, 210, 105, -45,0, 5,60,180,10,"", "", "", COLOR1, COLOR1, COLOR2, COLOR1, COLOR0, redrawScreen);
|
||||||
|
//GraphReversed(display, cnt, obj["sgv"].as<double>(), 20, 110, 210, 105, 0,45, 5,60,180,10,"", "", "", COLOR1, COLOR1, COLOR2, COLOR1, COLOR0, redrawScreen);
|
||||||
cnt += 5;
|
cnt += 5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -443,7 +467,7 @@ void Graph(ThinkInk_290_Tricolor_Z10 &d, double x, double y, double gx, double g
|
|||||||
d.setTextColor(tcolor, bcolor);
|
d.setTextColor(tcolor, bcolor);
|
||||||
d.setCursor(temp, gy + 5);
|
d.setCursor(temp, gy + 5);
|
||||||
// precision is default Arduino--this could really use some format control
|
// precision is default Arduino--this could really use some format control
|
||||||
d.println(int(i));
|
d.println(abs(int(i)));
|
||||||
}
|
}
|
||||||
|
|
||||||
//now draw the labels
|
//now draw the labels
|
||||||
|
|||||||
Reference in New Issue
Block a user