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 <HX711.h>
#include <EepromAT24C32.h> #include <EepromAT24C32.h>
#define countof(a) (sizeof(a) / sizeof(a[0]))
RtcDS3231<TwoWire> Rtc(Wire); RtcDS3231<TwoWire> Rtc(Wire);
EepromAt24c32<TwoWire> RtcEeprom(Wire);HX711 scale; EepromAt24c32<TwoWire> RtcEeprom(Wire);
HX711 scale;
// void printDateTime(const RtcDateTime &dt); // void printDateTime(const RtcDateTime &dt);
const int rtcPowerPin = 4; const int rtcPowerPin = 4;
const int wakeUpPin = 7; const int wakeUpPin = 7;
const int ledPin = 17; const int ledPin = 17;
@ -125,8 +127,6 @@ void loop()
Rtc.SetAlarmOne(alarm1); Rtc.SetAlarmOne(alarm1);
Rtc.LatchAlarmsTriggeredFlags(); Rtc.LatchAlarmsTriggeredFlags();
RtcTemperature temp = Rtc.GetTemperature();
int lastA = -1; int lastA = -1;
int lastB = -1; int lastB = -1;
@ -174,26 +174,19 @@ void loop()
head = (head + 1) % pageCount; head = (head + 1) % pageCount;
// Serial.print("Last a: "); char memString[pageSize + 1];
// Serial.print(lastA); int16_t weight = scale.get_units(1) * 100.00f;
// Serial.print(", Last b: ");
// Serial.print(lastB); // b674250562+12744
// Serial.print(", HEAD: "); snprintf_P(memString,
// Serial.print(head); countof(memString),
// Serial.print(", next: "); PSTR("%c%ld%+6d"),
// Serial.println((char)next); next,
now.TotalSeconds(),
String buffer; weight);
buffer += String((char)next); // Serial.println(memString);
buffer += String(scale.get_units(1), 2);
buffer += F(" kg, "); RtcEeprom.SetMemory(head * pageSize, (const uint8_t *)memString, sizeof(memString) - 1);
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);
for (int i = 0; i <= pageCount; i++) for (int i = 0; i <= pageCount; i++)
{ {
@ -222,6 +215,3 @@ void loop()
sleepNow(); sleepNow();
} }
/
Loading…
Cancel
Save