Merge branch 'SubDirectories'

This commit is contained in:
rljonesau 2018-12-19 19:40:04 +11:00
commit a90571ae5b
6 changed files with 168 additions and 54 deletions

View file

@ -889,9 +889,9 @@ void checkDebugCommands()
void updateJsonBT() void updateJsonBT()
{ {
char jsonStr[512]; char jsonStr[600];
if(makeJsonString(BTModerator, jsonStr, 512)) { if(makeJsonString(BTModerator, jsonStr, sizeof(jsonStr))) {
Bluetooth.send( jsonStr ); Bluetooth.send( jsonStr );
} }
} }

View file

@ -173,4 +173,5 @@ void setTime(const char* newTime)
DateTime newDateTime(currentDateTime.year(), currentDateTime.month(), currentDateTime.day(), hour, minute, second); DateTime newDateTime(currentDateTime.year(), currentDateTime.month(), currentDateTime.day(), hour, minute, second);
Clock.set(newDateTime); Clock.set(newDateTime);
} }
} }

View file

@ -0,0 +1,122 @@
/*
* This file is part of the "bluetoothheater" distribution
* (https://gitlab.com/mrjones.id.au/bluetoothheater)
*
* Copyright (C) 2018 Ray Jones <ray@mrjones.id.au>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#include <Arduino.h>
#include "Timers.h"
#include "../Utility/NVStorage.h"
#include "BTCDateTime.h"
void decodeTimerDays(int ID, const char* str)
{
sTimer timer;
NVstore.getTimerInfo(ID, timer);
unsigned char days = 0;
if(strstr(str, "Next")) {
days = 0x80;
}
else {
for(int i=0; i< 7; i++) {
int mask = 0x01 << i;
if(strstr(str, daysOfTheWeek[i]))
days |= mask;
}
}
timer.enabled = days;
NVstore.setTimerInfo(ID, timer);
}
void decodeTimerTime(int ID, int stop, const char* str)
{
sTimer timer;
NVstore.getTimerInfo(ID, timer);
int hour, minute;
if(2 == sscanf(str, "%d:%d", &hour, &minute)) {
if(stop) {
timer.stop.hour = hour;
timer.stop.min = minute;
}
else {
timer.start.hour = hour;
timer.start.min = minute;
}
NVstore.setTimerInfo(ID, timer);
}
}
void decodeTimerRepeat(int ID, int state)
{
sTimer timer;
NVstore.getTimerInfo(ID, timer);
timer.repeat = state;
NVstore.setTimerInfo(ID, timer);
}
const char* getTimerStr(int timer, int param)
{
sTimer timerInfo;
// due to how ArduinoJSON builds the JSON string, we need to create and store each string individually here.
static char StartStr[2][8];
static char StopStr[2][8];
static char DayStr[2][32];
static char RptStr[2][2];
NVstore.getTimerInfo(timer, timerInfo);
int i = 0;
int comma = 0;
switch(param) {
case 0:
sprintf(StartStr[timer], "%02d:%02d", timerInfo.start.hour, timerInfo.start.min);
return StartStr[timer];
case 1:
sprintf(StopStr[timer], "%02d:%02d", timerInfo.stop.hour, timerInfo.stop.min);
return StopStr[timer];
case 2:
if(timerInfo.enabled == 0) {
strcpy(DayStr[timer], "None");
}
else if(timerInfo.enabled & 0x80) {
strcpy(DayStr[timer], "Next");
}
else {
comma = 0;
DayStr[timer][0] = 0;
for(i=0; i<7; i++) {
if(timerInfo.enabled & (0x01<<i)) {
if(comma)
strcat(DayStr[timer], ",");
strcat(DayStr[timer], daysOfTheWeek[i]);
comma = 1;
}
}
}
return DayStr[timer];
case 3:
strcpy(RptStr[timer], timerInfo.repeat ? "1" : "0");
return RptStr[timer];
default:
return "BadParam";
}
}

View file

@ -0,0 +1,30 @@
/*
* This file is part of the "bluetoothheater" distribution
* (https://gitlab.com/mrjones.id.au/bluetoothheater)
*
* Copyright (C) 2018 Ray Jones <ray@mrjones.id.au>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#ifndef __BTC_TIMERS_H__
#define __BTC_TIMERS_H__
const char* getTimerStr(int timer, int param);
void decodeTimerDays(int timerID, const char* str);
void decodeTimerTime(int ID, int stop, const char*);
void decodeTimerRepeat(int ID, int state);
#endif

View file

@ -24,14 +24,11 @@
#include "../Protocol/helpers.h" #include "../Protocol/helpers.h"
#include "NVstorage.h" #include "NVstorage.h"
#include "../RTC/BTCDateTime.h" #include "../RTC/BTCDateTime.h"
#include "../RTC/Timers.h"
char defaultJSONstr[64]; char defaultJSONstr[64];
void decodeTimerDays(int timerID, const char* str);
void decodeTimerTime(int ID, int stop, const char*);
void decodeTimerRepeat(int ID, int state);
void interpretJsonCommand(char* pLine) void interpretJsonCommand(char* pLine)
{ {
@ -128,7 +125,7 @@ void interpretJsonCommand(char* pLine)
bool makeJsonString(CModerator& moderator, char* opStr, int len) bool makeJsonString(CModerator& moderator, char* opStr, int len)
{ {
StaticJsonBuffer<512> jsonBuffer; // create a JSON buffer on the stack StaticJsonBuffer<600> jsonBuffer; // create a JSON buffer on the stack
JsonObject& root = jsonBuffer.createObject(); // create object to add JSON commands to JsonObject& root = jsonBuffer.createObject(); // create object to add JSON commands to
bool bSend = false; // reset should send flag bool bSend = false; // reset should send flag
@ -155,6 +152,14 @@ bool makeJsonString(CModerator& moderator, char* opStr, int len)
bSend |= moderator.addJson("SystemVoltage", getHeaterInfo().getBattVoltage(), root ); bSend |= moderator.addJson("SystemVoltage", getHeaterInfo().getBattVoltage(), root );
bSend |= moderator.addJson("GlowVoltage", getHeaterInfo().getGlow_Voltage(), root ); bSend |= moderator.addJson("GlowVoltage", getHeaterInfo().getGlow_Voltage(), root );
bSend |= moderator.addJson("GlowCurrent", getHeaterInfo().getGlow_Current(), root ); bSend |= moderator.addJson("GlowCurrent", getHeaterInfo().getGlow_Current(), root );
bSend |= moderator.addJson("Timer1Start", getTimerStr(0, 0), root );
bSend |= moderator.addJson("Timer1Stop", getTimerStr(0, 1), root );
bSend |= moderator.addJson("Timer1Days", getTimerStr(0, 2), root );
bSend |= moderator.addJson("Timer1Repeat", getTimerStr(0, 3), root );
bSend |= moderator.addJson("Timer2Start", getTimerStr(1, 0), root );
bSend |= moderator.addJson("Timer2Stop", getTimerStr(1, 1), root );
bSend |= moderator.addJson("Timer2Days", getTimerStr(1, 2), root );
bSend |= moderator.addJson("Timer2Repeat", getTimerStr(1, 3), root );
if(bSend) { if(bSend) {
root.printTo(opStr, len); root.printTo(opStr, len);
@ -164,47 +169,3 @@ bool makeJsonString(CModerator& moderator, char* opStr, int len)
} }
void decodeTimerDays(int ID, const char* str)
{
sTimer timer;
NVstore.getTimerInfo(ID, timer);
unsigned char days = 0;
if(strstr(str, "Next")) {
days = 0x80;
}
else {
for(int i=0; i< 7; i++) {
int mask = 0x01 << i;
if(strstr(str, daysOfTheWeek[i]))
days |= mask;
}
}
timer.enabled = days;
NVstore.setTimerInfo(ID, timer);
}
void decodeTimerTime(int ID, int stop, const char* str)
{
sTimer timer;
NVstore.getTimerInfo(ID, timer);
int hour, minute;
if(2 == sscanf(str, "%d:%d", &hour, &minute)) {
if(stop) {
timer.stop.hour = hour;
timer.stop.min = minute;
}
else {
timer.start.hour = hour;
timer.start.min = minute;
}
NVstore.setTimerInfo(ID, timer);
}
}
void decodeTimerRepeat(int ID, int state)
{
sTimer timer;
NVstore.getTimerInfo(ID, timer);
timer.repeat = state;
NVstore.setTimerInfo(ID, timer);
}

View file

@ -98,9 +98,9 @@ bool doWebServer(void) {
lastTx = millis() + 100; lastTx = millis() + 100;
char jsonStr[512]; char jsonStr[600];
if(makeJsonString(WebModerator, jsonStr, 512)) { if(makeJsonString(WebModerator, jsonStr, sizeof(jsonStr))) {
bTxWebData = true; // OLED tx data animation flag bTxWebData = true; // OLED tx data animation flag
webSocket.broadcastTXT(jsonStr); webSocket.broadcastTXT(jsonStr);
} }