Added functions to receive the tc data blocks as json and also to write the tc data blocks, json formatted, into the eeprom.

This commit is contained in:
Kai Lauterbach 2023-04-27 13:38:41 +02:00
parent 211b06ed62
commit 99042a9792

View file

@ -55,7 +55,7 @@ uint8_t example_timer_data_block[] = {
};
uint8_t test_timer_data_block[] = {
// state hour min ch1 ch2 ch3 ch3
// hour min ch1 ch2 ch3 ch3
9, 20, 0, 0, 0, 0, // 0: off
9, 30, 25, 0, 0, 0, // 1: 10% ch1 blues
9, 40, 25, 0, 25, 0, // 2: 10% all blues
@ -366,3 +366,50 @@ bool tc_check_no_data_block()
}
//********************************//
String tc_getJsonData()
{
String output = "[";
for (uint8_t i = 0; i < LENGTH_OF_TIMER_DATA_BLOCK; i++)
{
output += "{\"hour\":" + (String)(int)tc_data[i].hh + ",";
output += "\"min\":" + (String)(int)tc_data[i].mm + ",";
output += "\"ch1\":" + (String)(int)tc_data[i].ch1 + ",";
output += "\"ch2\":" + (String)(int)tc_data[i].ch2 + ",";
output += "\"ch3\":" + (String)(int)tc_data[i].ch3 + ",";
output += "\"ch4\":" + (String)(int)tc_data[i].ch4 + "}";
if (i < LENGTH_OF_TIMER_DATA_BLOCK-1)
{
output += ",";
}
}
output += "]";
return output;
}
tc_jsonDataBlockToEEPROM(String json_data_string)
{
StaticJsonDocument<512> doc;
deserializeJson(doc, json_data_string);
// Loop through each data block in the JSON data and store it in the tc_data array
for (uint8_t i = 0; i < LENGTH_OF_TIMER_DATA_BLOCK; i++)
{
JsonObject obj = doc[i];
tc_data[i].hh = obj["hour"];
tc_data[i].mm = obj["min"];
tc_data[i].ch1 = obj["ch1"];
tc_data[i].ch2 = obj["ch2"];
tc_data[i].ch3 = obj["ch3"];
tc_data[i].ch4 = obj["ch4"];
}
// Write the tc_data array to the EEPROM
for (uint16_t i = 0; i < (NUMBER_OF_TIMER_DATA_BLOCKS * LENGTH_OF_TIMER_DATA_BLOCK); i++)
{
EEPROM.write(EEPROM_TIMING_DATA_ADDRESS + i, *((uint8_t*)&tc_data + i));
}
EEPROM.commit();
}
//********************************//