From 2f314f95d7df23a0383aa9109e2af12c5d05d85e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Babi=C4=8D?= Date: Thu, 13 May 2021 20:12:51 +0200 Subject: [PATCH] implement the encoding for eeprom --- src/main.cpp | 44 +++++++++++++++++--------------------------- 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 4db8d36..cb9b273 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,12 +6,14 @@ #include #include +#define countof(a) (sizeof(a) / sizeof(a[0])) + RtcDS3231 Rtc(Wire); -EepromAt24c32 RtcEeprom(Wire);HX711 scale; +EepromAt24c32 RtcEeprom(Wire); +HX711 scale; // void printDateTime(const RtcDateTime &dt); - const int rtcPowerPin = 4; const int wakeUpPin = 7; const int ledPin = 17; @@ -125,8 +127,6 @@ void loop() Rtc.SetAlarmOne(alarm1); Rtc.LatchAlarmsTriggeredFlags(); - RtcTemperature temp = Rtc.GetTemperature(); - int lastA = -1; int lastB = -1; @@ -174,26 +174,19 @@ void loop() head = (head + 1) % pageCount; - // Serial.print("Last a: "); - // Serial.print(lastA); - // Serial.print(", Last b: "); - // Serial.print(lastB); - // Serial.print(", HEAD: "); - // Serial.print(head); - // Serial.print(", next: "); - // Serial.println((char)next); - - String buffer; - buffer += String((char)next); - buffer += String(scale.get_units(1), 2); - buffer += F(" kg, "); - buffer += String(temp.AsFloatDegC(), 2); - buffer += F(" °C"); - // Serial.println(buffer); - char data[pageSize]; - buffer.toCharArray(data, pageSize); - - RtcEeprom.SetMemory(head * pageSize, (const uint8_t *)data, sizeof(data) - 1); + char memString[pageSize + 1]; + int16_t weight = scale.get_units(1) * 100.00f; + + // b674250562+12744 + snprintf_P(memString, + countof(memString), + PSTR("%c%ld%+6d"), + next, + now.TotalSeconds(), + weight); + // Serial.println(memString); + + RtcEeprom.SetMemory(head * pageSize, (const uint8_t *)memString, sizeof(memString) - 1); for (int i = 0; i <= pageCount; i++) { @@ -222,6 +215,3 @@ void loop() sleepNow(); } - - -/ \ No newline at end of file