implement the encoding for eeprom

master
Peter Babič 3 years ago
parent 61ea4b084f
commit 2f314f95d7
Signed by: peter.babic
GPG Key ID: 4BB075BC1884BA40
  1. 44
      src/main.cpp

@ -6,12 +6,14 @@
#include <HX711.h>
#include <EepromAT24C32.h>
#define countof(a) (sizeof(a) / sizeof(a[0]))
RtcDS3231<TwoWire> Rtc(Wire);
EepromAt24c32<TwoWire> RtcEeprom(Wire);HX711 scale;
EepromAt24c32<TwoWire> 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();
}
/
Loading…
Cancel
Save