PATCH: Responsitivity patch

This commit is contained in:
Robin Dietzel 2023-02-03 11:35:33 +01:00
parent 2a9e8efb3d
commit 15352ddfcd

View File

@ -218,57 +218,62 @@ int main(void) {
static uint16_t old_minute_counter = minute_counter; static uint16_t old_minute_counter = minute_counter;
static uint32_t dly_disp, dly_stats, dly_switch;
SendUartString(&huart1, "Hello from FloatPUMP Controller"); SendUartString(&huart1, "Hello from FloatPUMP Controller");
SendUartString(&huart1, {"Revision: " GIT_HASH}); SendUartString(&huart1, {"Revision: " GIT_HASH});
while (1) { while (1) {
display.LCDSetBacklight(S_backlight); //Execute this block each second only
if(HAL_GetTick() > dly_disp + 1000)
{
dly_disp = HAL_GetTick();
display.LCDSetBacklight(S_backlight);
char buf[20];
char buf[20]; display.LCDSetCursor(0, 0);
sprintf(buf, "Fuellstand %3d %%", tankLevel0.getPercent());
display.LCDSendCString(buf);
display.LCDSetCursor(0, 1);
if (S_tankempty) {
display.LCDSendCString(const_cast<char *>(std::string("Tank Wassermangel ").c_str()));
HAL_GPIO_WritePin(LED5_GPIO_Port, LED5_Pin, GPIO_PIN_SET);
display.LCDSetCursor(0, 0);
sprintf(buf, "Fuellstand %3d %%", tankLevel0.getPercent());
display.LCDSendCString(buf);
display.LCDSetCursor(0, 1);
if (S_tankempty) {
display.LCDSendCString(const_cast<char *>(std::string("Tank Wassermangel ").c_str()));
HAL_GPIO_WritePin(LED5_GPIO_Port, LED5_Pin, GPIO_PIN_SET);
} else {
display.LCDSendCString(const_cast<char *>(std::string("Tank Normal ").c_str()));
HAL_GPIO_WritePin(LED5_GPIO_Port, LED5_Pin, GPIO_PIN_RESET);
}
display.LCDSetCursor(0, 2);
if (S_refilling) {
display.LCDSendCString(const_cast<char *>(std::string("Nachspeisung laeuft ").c_str()));
HAL_GPIO_WritePin(LED4_GPIO_Port, LED4_Pin, GPIO_PIN_RESET);
} else {
display.LCDSendCString(const_cast<char *>(std::string("Nachspeisung inaktiv").c_str()));
HAL_GPIO_WritePin(LED4_GPIO_Port, LED4_Pin, GPIO_PIN_SET);
}
display.LCDSetCursor(0, 3);
if (S_refillcooldown > 0) {
int remaining_mins = S_refillcooldown / 60;
if (remaining_mins > 0) {
sprintf(buf, "Nsp. wartet: %3d min", S_refillcooldown / 60);
display.LCDSendCString(buf);
} else { } else {
sprintf(buf, "Nsp. wartet: %3d sec", S_refillcooldown); display.LCDSendCString(const_cast<char *>(std::string("Tank Normal ").c_str()));
display.LCDSendCString(buf); HAL_GPIO_WritePin(LED5_GPIO_Port, LED5_Pin, GPIO_PIN_RESET);
} }
} else if (S_refillempty) {
display.LCDSendCString(const_cast<char *>(std::string("Nachspeisung mangel ").c_str()));
HAL_GPIO_WritePin(LED3_GPIO_Port, LED3_Pin, GPIO_PIN_RESET);
} else {
display.LCDSendCString(const_cast<char *>(std::string("Nachspeisung ok ").c_str()));
HAL_GPIO_WritePin(LED3_GPIO_Port, LED3_Pin, GPIO_PIN_SET);
}
display.LCDSetCursor(0, 2);
if (S_refilling) {
display.LCDSendCString(const_cast<char *>(std::string("Nachspeisung laeuft ").c_str()));
HAL_GPIO_WritePin(LED4_GPIO_Port, LED4_Pin, GPIO_PIN_RESET);
} else {
display.LCDSendCString(const_cast<char *>(std::string("Nachspeisung inaktiv").c_str()));
HAL_GPIO_WritePin(LED4_GPIO_Port, LED4_Pin, GPIO_PIN_SET);
}
display.LCDSetCursor(0, 3);
if (S_refillcooldown > 0) {
int remaining_mins = S_refillcooldown / 60;
if (remaining_mins > 0) {
sprintf(buf, "Nsp. wartet: %3d min", S_refillcooldown / 60);
display.LCDSendCString(buf);
} else {
sprintf(buf, "Nsp. wartet: %3d sec", S_refillcooldown);
display.LCDSendCString(buf);
}
} else if (S_refillempty) {
display.LCDSendCString(const_cast<char *>(std::string("Nachspeisung mangel ").c_str()));
HAL_GPIO_WritePin(LED3_GPIO_Port, LED3_Pin, GPIO_PIN_RESET);
} else {
display.LCDSendCString(const_cast<char *>(std::string("Nachspeisung ok ").c_str()));
HAL_GPIO_WritePin(LED3_GPIO_Port, LED3_Pin, GPIO_PIN_SET);
}
}
//Check for rotation to enable display backlight //Check for rotation to enable display backlight
if (old_pos < rot_counter) { if (old_pos < rot_counter) {
@ -316,7 +321,7 @@ int main(void) {
old_pos = rot_counter; old_pos = rot_counter;
last_menu_retrigger = HAL_GetTick(); last_menu_retrigger = HAL_GetTick();
} }
HAL_Delay(100); HAL_Delay(10);
//Execute Calibrations if necessary //Execute Calibrations if necessary
if (a_caliblow) { if (a_caliblow) {
@ -350,53 +355,63 @@ int main(void) {
} }
} }
HAL_GPIO_WritePin(LED2_GPIO_Port, LED2_Pin, GPIO_PIN_RESET); //Execute this only each 5 seconds
if(HAL_GetTick() > dly_switch + 5000)
{
dly_switch = HAL_GetTick();
HAL_GPIO_WritePin(LED2_GPIO_Port, LED2_Pin, GPIO_PIN_RESET);
//Poll Sensors //Poll Sensors
tankLevel0.poll(); tankLevel0.poll();
refillBlocker0.poll(); refillBlocker0.poll();
//Check conditions //Check conditions
CheckTankConditions(Config_Store::getInstance(), tankLevel0, tankPump); CheckTankConditions(Config_Store::getInstance(), tankLevel0, tankPump);
CheckRefillConditions(Config_Store::getInstance(), tankLevel0, refillBlocker0, refillPump); CheckRefillConditions(Config_Store::getInstance(), tankLevel0, refillBlocker0, refillPump);
//Create history //Create history
if (old_minute_counter < minute_counter) { if (old_minute_counter < minute_counter) {
old_minute_counter = minute_counter; old_minute_counter = minute_counter;
history_h[minute_counter % 60] = tankLevel0.getPercent(); history_h[minute_counter % 60] = tankLevel0.getPercent();
history_d[minute_counter / 60] = tankLevel0.getPercent(); history_d[minute_counter / 60] = tankLevel0.getPercent();
//Calculate diff to value 1h ago -> minute_counter+1's entry is always 60mins ago ! //Calculate diff to value 1h ago -> minute_counter+1's entry is always 60mins ago !
diff_hist_hour = history_h[minute_counter % 60] - history_h[(minute_counter + 1) % 60]; diff_hist_hour = history_h[minute_counter % 60] - history_h[(minute_counter + 1) % 60];
//Same here for daily history //Same here for daily history
diff_hist_day = history_d[(minute_counter / 60) % 24] - history_d[((minute_counter + 60) / 60) % 24]; diff_hist_day = history_d[(minute_counter / 60) % 24] - history_d[((minute_counter + 60) / 60) % 24];
}
HAL_GPIO_WritePin(LED2_GPIO_Port, LED2_Pin, GPIO_PIN_SET);
} }
HAL_GPIO_WritePin(LED2_GPIO_Port, LED2_Pin, GPIO_PIN_SET);
HAL_Delay(1000); HAL_Delay(1000);
//Periodically send stats via uart in json format:
char buffer[400]; //Periodically send stats via uart in json format each minute
sprintf(buffer, "{" if(HAL_GetTick() > dly_stats + 60000)
"\"Status\": true, " {
"\"TankLevel\": %hhd, " dly_stats = HAL_GetTick();
"\"TankPump\": %s, " char buffer[400];
"\"RefillPump\": %s, " sprintf(buffer, "{"
"\"RefillEmpty\": %s, " "\"Status\": true, "
"\"RefillCooldown\": %hhd, " "\"TankLevel\": %hhd, "
"\"HourlyHist\": %hhd, " "\"TankPump\": %s, "
"\"DailyHist\": %hhd, " "\"RefillPump\": %s, "
"}", "\"RefillEmpty\": %s, "
tankLevel0.getPercent(), "\"RefillCooldown\": %hhd, "
(S_tankempty) ? "false" : "true", "\"HourlyHist\": %hhd, "
(S_refilling) ? "true" : "false", "\"DailyHist\": %hhd, "
(S_refillempty) ? "true" : "false", "}",
S_refillcooldown, tankLevel0.getPercent(),
diff_hist_hour, (S_tankempty) ? "false" : "true",
diff_hist_day); (S_refilling) ? "true" : "false",
SendUartString(&huart1, buffer); (S_refillempty) ? "true" : "false",
//HAL_UART_Transmit(&huart1, (uint8_t*) buffer, sizeof(buffer), 100); S_refillcooldown,
diff_hist_hour,
diff_hist_day);
SendUartString(&huart1, buffer);
}
} }