mirror of
https://github.com/anklimov/lighthub
synced 2025-12-06 11:49:51 +03:00
config reload fix (caused by timer)
This commit is contained in:
@@ -23,6 +23,10 @@ e-mail anklimov@gmail.com
|
|||||||
#include "flashstream.h"
|
#include "flashstream.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#if defined(__SAM3X8E__)
|
||||||
|
#include "TimerInterrupt_Generic.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(FS_STORAGE)
|
#if defined(FS_STORAGE)
|
||||||
flashStream sysConfStream("config.bin");
|
flashStream sysConfStream("config.bin");
|
||||||
flashStream JSONStream("config.json");
|
flashStream JSONStream("config.json");
|
||||||
@@ -212,7 +216,7 @@ debugSerial<<F("Stopped")<<endl;
|
|||||||
#ifdef SYSLOG_ENABLE
|
#ifdef SYSLOG_ENABLE
|
||||||
syslogInitialized=false; //Garbage in memory
|
syslogInitialized=false; //Garbage in memory
|
||||||
#endif
|
#endif
|
||||||
|
configLoaded=false;
|
||||||
debugSerial<<F("Deleting conf. RAM was:")<<freeRam();
|
debugSerial<<F("Deleting conf. RAM was:")<<freeRam();
|
||||||
aJson.deleteItem(root);
|
aJson.deleteItem(root);
|
||||||
root = NULL;
|
root = NULL;
|
||||||
@@ -230,7 +234,7 @@ debugSerial<<F("Deleting conf. RAM was:")<<freeRam();
|
|||||||
modbusObj = NULL;
|
modbusObj = NULL;
|
||||||
#endif
|
#endif
|
||||||
debugSerial<<F(" is ")<<freeRam()<<endl;
|
debugSerial<<F(" is ")<<freeRam()<<endl;
|
||||||
configLoaded=false;
|
|
||||||
configOk=false;
|
configOk=false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1605,6 +1609,32 @@ void postTransmission() {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define TIMER_INTERVAL_MS 200 // 0.1s = 100ms
|
||||||
|
|
||||||
|
volatile unsigned long timerCount=0;
|
||||||
|
volatile int16_t timerNumber=-1;
|
||||||
|
|
||||||
|
void TimerHandler(void)
|
||||||
|
{
|
||||||
|
timerCount=millis();
|
||||||
|
if (configLoaded) inputLoop(CHECK_INTERRUPT);
|
||||||
|
timerCount=millis()-timerCount;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(__SAM3X8E__)
|
||||||
|
int16_t attachTimer(double microseconds, timerCallback callback, const char* TimerName)
|
||||||
|
{
|
||||||
|
if (timerNumber!=-1) return timerNumber;
|
||||||
|
|
||||||
|
DueTimerInterrupt dueTimerInterrupt = DueTimer.getAvailable();
|
||||||
|
dueTimerInterrupt.attachInterruptInterval(microseconds, callback);
|
||||||
|
timerNumber = dueTimerInterrupt.getTimerNumber();
|
||||||
|
debugSerial<<TimerName<<F(" attached to Timer(")<<timerNumber<<F(")")<<endl;
|
||||||
|
return timerNumber;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void setup_main() {
|
void setup_main() {
|
||||||
|
|
||||||
#if defined(__SAM3X8E__)
|
#if defined(__SAM3X8E__)
|
||||||
@@ -1697,6 +1727,7 @@ void setup_main() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
loadConfigFromEEPROM();
|
loadConfigFromEEPROM();
|
||||||
|
#if defined(__SAM3X8E__)
|
||||||
}
|
}
|
||||||
|
|
||||||
void printFirmwareVersionAndBuildOptions() {
|
void printFirmwareVersionAndBuildOptions() {
|
||||||
@@ -2099,29 +2130,7 @@ configLocked++;
|
|||||||
}
|
}
|
||||||
configLocked--;
|
configLocked--;
|
||||||
}
|
}
|
||||||
volatile unsigned long timerCount=0;
|
|
||||||
|
|
||||||
void TimerHandler(void)
|
|
||||||
{
|
|
||||||
timerCount=millis();
|
|
||||||
inputLoop(CHECK_INTERRUPT);
|
|
||||||
timerCount=millis()-timerCount;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#define TIMER_INTERVAL_MS 200 // 0.1s = 100ms
|
|
||||||
|
|
||||||
#if defined(__SAM3X8E__)
|
|
||||||
int16_t attachTimer(double microseconds, timerCallback callback, const char* TimerName)
|
|
||||||
{
|
|
||||||
int16_t timerNumber=-1;
|
|
||||||
DueTimerInterrupt dueTimerInterrupt = DueTimer.getAvailable();
|
|
||||||
dueTimerInterrupt.attachInterruptInterval(microseconds, callback);
|
|
||||||
timerNumber = dueTimerInterrupt.getTimerNumber();
|
|
||||||
debugSerial<<TimerName<<F(" attached to Timer(")<<timerNumber<<F(")")<<endl;
|
|
||||||
return timerNumber;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void inputSetup(void) {
|
void inputSetup(void) {
|
||||||
if (!inputs) return;
|
if (!inputs) return;
|
||||||
@@ -2135,10 +2144,9 @@ configLocked++;
|
|||||||
yield();
|
yield();
|
||||||
input = input->next;
|
input = input->next;
|
||||||
}
|
}
|
||||||
#if defined(__SAM3X8E__)
|
// Interval in microsecs
|
||||||
// Interval in microsecs
|
attachTimer(TIMER_INTERVAL_MS * 1000, TimerHandler, "ITimer");
|
||||||
attachTimer(TIMER_INTERVAL_MS * 1000, TimerHandler, "ITimer");
|
#endif
|
||||||
#endif
|
|
||||||
configLocked--;
|
configLocked--;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2260,9 +2268,9 @@ void thermoLoop(void) {
|
|||||||
publishStat();
|
publishStat();
|
||||||
#ifndef DISABLE_FREERAM_PRINT
|
#ifndef DISABLE_FREERAM_PRINT
|
||||||
(thermostatCheckPrinted) ? debugSerial<<F("\nRAM=")<<freeRam()<<F(" Locks:")<<configLocked: debugSerial<<F(" ")<<freeRam()<<F(" Locks:")<<configLocked;
|
(thermostatCheckPrinted) ? debugSerial<<F("\nRAM=")<<freeRam()<<F(" Locks:")<<configLocked: debugSerial<<F(" ")<<freeRam()<<F(" Locks:")<<configLocked;
|
||||||
|
debugSerial<<F(" Timer:")<<timerCount<<endl;
|
||||||
#endif
|
#endif
|
||||||
debugSerial<<F("Timer:")<<timerCount<<endl;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
//#include <DueFlashStorage.h>
|
//#include <DueFlashStorage.h>
|
||||||
#include <watchdog.h>
|
#include <watchdog.h>
|
||||||
#include <ArduinoHttpClient.h>
|
#include <ArduinoHttpClient.h>
|
||||||
#include "TimerInterrupt_Generic.h"
|
//#include "TimerInterrupt_Generic.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_AVR)
|
#if defined(ARDUINO_ARCH_AVR)
|
||||||
|
|||||||
Reference in New Issue
Block a user