Bluetooth app updated for 14 timers, including conflict testing.

This commit is contained in:
rljonesau 2019-03-05 20:40:00 +11:00
parent f00a179f34
commit 459f15054d
6 changed files with 68 additions and 3 deletions

View file

@ -295,3 +295,19 @@ CTimerManager::setTimer(sTimer& timerInfo)
}
return 0;
}
int
CTimerManager::conflictTest(int ID)
{
if(!(ID >= 0 && ID < 14))
return 0;
sTimer timerInfo;
CTimerManager::getTimer(ID, timerInfo); // get info for selected timer
int conflictID = CTimerManager::conflictTest(timerInfo); // test against all others
if(conflictID) {
timerInfo.enabled = 0; // cancel enabled status if it conflicts with others
CTimerManager::setTimer(timerInfo); // stage the timer settings, without being enabled
}
return conflictID;
}

View file

@ -43,6 +43,7 @@ public:
static void condenseMap(uint16_t timerMap[_dayMinutes], int factor);
static void condenseMap(uint8_t timerMap[7][120]);
static int conflictTest(sTimer& timer);
static int conflictTest(int ID);
static int manageTime(int hour, int minute, int dow);
static int findNextTimer(int hour, int minute, int dow);
static int getNextTimer();

View file

@ -25,6 +25,7 @@
#include "NVstorage.h"
#include "../RTC/BTCDateTime.h"
#include "../RTC/Timers.h"
#include "../RTC/TimerManager.h"
#include "../Bluetooth/BluetoothAbstract.h"
#include "../WiFi/BTCWebServer.h"
#include "../cfg/BTCConfig.h"
@ -33,7 +34,9 @@
char defaultJSONstr[64];
CModerator JSONmoderator;
CTimerModerator TimerModerator;
int timerConflict = 0;
void validateTimer(int ID);
void interpretJsonCommand(char* pLine)
{
@ -128,6 +131,12 @@ void interpretJsonCommand(char* pLine)
}
else if(strcmp("TimerTemp", it->key) == 0) {
decodeTimerNumeric(1, it->value.as<const char*>());
}
else if(strcmp("TimerConflict", it->key) == 0) {
validateTimer(it->value.as<int>());
}
else if(strcmp("TimerRefresh", it->key) == 0) {
TimerModerator.reset();
}
else if(strcmp("FanSensor", it->key) == 0) {
setFanSensor(it->value.as<unsigned char>());
@ -135,7 +144,16 @@ void interpretJsonCommand(char* pLine)
}
}
void validateTimer(int ID)
{
ID--; // supplied as +1
if(!(ID >= 0 && ID < 14))
return;
timerConflict = CTimerManager::conflictTest(ID); // check targeted timer against other timers
TimerModerator.reset(ID); // ensure we fully update client with our understanding of selected timer
}
bool makeJsonString(CModerator& moderator, char* opStr, int len)
{
@ -209,9 +227,8 @@ bool makeJsonTimerString(int channel, char* opStr, int len)
void updateJSONclients(bool report)
{
// update general parameters
char jsonStr[800];
{
char jsonStr[800];
if(makeJsonString(JSONmoderator, jsonStr, sizeof(jsonStr))) {
if (report) {
DebugPort.print("JSON send: "); DebugPort.println(jsonStr);
@ -221,23 +238,41 @@ void updateJSONclients(bool report)
}
}
// update timer parameters
bool bNewTimerInfo = false;
for(int tmr=0; tmr<14; tmr++)
{
char jsonStr[800];
if(makeJsonTimerString(tmr, jsonStr, sizeof(jsonStr))) {
if (report) {
DebugPort.print("JSON send: "); DebugPort.println(jsonStr);
}
getBluetoothClient().send( jsonStr );
sendWebServerString( jsonStr );
bNewTimerInfo = true;
}
}
// request timer refesh upon clients
if(bNewTimerInfo) {
StaticJsonBuffer<800> jsonBuffer; // create a JSON buffer on the stack
JsonObject& root = jsonBuffer.createObject(); // create object to add JSON commands to
if(timerConflict) {
root.set("TimerConflict", timerConflict);
timerConflict = 0;
}
root.set("TimerRefresh", 1);
root.printTo(jsonStr, 800);
DebugPort.print("JSON send: "); DebugPort.println(jsonStr);
getBluetoothClient().send( jsonStr );
sendWebServerString( jsonStr );
}
}
void resetJSONmoderator()
{
JSONmoderator.reset();
TimerModerator.reset();
}

View file

@ -86,3 +86,15 @@ CTimerModerator::reset()
}
}
void
CTimerModerator::reset(int timer)
{
if(timer >= 0 && timer < 14) {
Memory[timer].start.hour = -1; // force full update
Memory[timer].stop.hour = -1; // force full update
Memory[timer].enabled = 0xff; // invalid combination - force full update
Memory[timer].repeat = 0xff;
Memory[timer].temperature = 0xff;
}
}

View file

@ -36,6 +36,7 @@ public:
CTimerModerator();
bool addJson(int channel, const sTimer& toSend, JsonObject& root);
void reset();
void reset(int channel);
};