core Tested/Bugfixed. XON/XOFF, save/restore states

This commit is contained in:
2018-09-29 12:33:48 +03:00
parent df95bec241
commit 9275467052
7 changed files with 62 additions and 22 deletions

View File

@@ -10,11 +10,11 @@
export FLAGS="$FLAGS -DSERIAL_BAUD=115200" export FLAGS="$FLAGS -DSERIAL_BAUD=115200"
#export FLAGS="$FLAGS -DWiz5500" #export FLAGS="$FLAGS -DWiz5500"
#export FLAGS="$FLAGS -DDISABLE_FREERAM_PRINT" #export FLAGS="$FLAGS -DDISABLE_FREERAM_PRINT"
export FLAGS="$FLAGS -DCUSTOM_FIRMWARE_MAC=de:ad:be:ef:fe:ff" export FLAGS="$FLAGS -DCUSTOM_FIRMWARE_MAC=de:ad:be:ef:fe:fe"
# export FLAGS="$FLAGS -DDMX_DISABLE" # export FLAGS="$FLAGS -DDMX_DISABLE"
# export FLAGS="$FLAGS -DARTNET_ENABLE" # export FLAGS="$FLAGS -DARTNET_ENABLE"
# export FLAGS="$FLAGS -DMODBUS_DISABLE" # export FLAGS="$FLAGS -DMODBUS_DISABLE"
export FLAGS="$FLAGS -DOWIRE_DISABLE" # export FLAGS="$FLAGS -DOWIRE_DISABLE"
# export FLAGS="$FLAGS -DAVR_DMXOUT_PIN=18" # export FLAGS="$FLAGS -DAVR_DMXOUT_PIN=18"
# export FLAGS="$FLAGS -DLAN_INIT_DELAY=2000" # export FLAGS="$FLAGS -DLAN_INIT_DELAY=2000"
# export FLAGS="$FLAGS -DCONTROLLINO" # export FLAGS="$FLAGS -DCONTROLLINO"

View File

@@ -10,11 +10,11 @@
export FLAGS="$FLAGS -DSERIAL_BAUD=115200" export FLAGS="$FLAGS -DSERIAL_BAUD=115200"
#export FLAGS="$FLAGS -DWiz5500" #export FLAGS="$FLAGS -DWiz5500"
#export FLAGS="$FLAGS -DDISABLE_FREERAM_PRINT" #export FLAGS="$FLAGS -DDISABLE_FREERAM_PRINT"
export FLAGS="$FLAGS -DCUSTOM_FIRMWARE_MAC=de:ad:be:ef:fe:ff" export FLAGS="$FLAGS -DCUSTOM_FIRMWARE_MAC=de:ad:be:ef:fe:ed"
# export FLAGS="$FLAGS -DDMX_DISABLE" # export FLAGS="$FLAGS -DDMX_DISABLE"
# export FLAGS="$FLAGS -DARTNET_ENABLE" # export FLAGS="$FLAGS -DARTNET_ENABLE"
# export FLAGS="$FLAGS -DMODBUS_DISABLE" # export FLAGS="$FLAGS -DMODBUS_DISABLE"
# export FLAGS="$FLAGS -DOWIRE_DISABLE" export FLAGS="$FLAGS -DOWIRE_DISABLE"
# export FLAGS="$FLAGS -DAVR_DMXOUT_PIN=18" # export FLAGS="$FLAGS -DAVR_DMXOUT_PIN=18"
# export FLAGS="$FLAGS -DLAN_INIT_DELAY=2000" # export FLAGS="$FLAGS -DLAN_INIT_DELAY=2000"
# export FLAGS="$FLAGS -DCONTROLLINO" # export FLAGS="$FLAGS -DCONTROLLINO"

View File

@@ -57,6 +57,8 @@ int txt2cmd(char *payload) {
else if (strcmp(payload, "HALT") == 0) cmd = CMD_HALT; else if (strcmp(payload, "HALT") == 0) cmd = CMD_HALT;
else if (strcmp(payload, "XON") == 0) cmd = CMD_XON; else if (strcmp(payload, "XON") == 0) cmd = CMD_XON;
else if (strcmp(payload, "XOFF") == 0) cmd = CMD_XOFF; else if (strcmp(payload, "XOFF") == 0) cmd = CMD_XOFF;
else if (strcmp(payload, "INCREASE") == 0) cmd = CMD_UP;
else if (strcmp(payload, "DECREASE") == 0) cmd = CMD_DN;
else if (*payload == '-' || (*payload >= '0' && *payload <= '9')) cmd = 0; else if (*payload == '-' || (*payload >= '0' && *payload <= '9')) cmd = 0;
else if (*payload == '{') cmd = -2; else if (*payload == '{') cmd = -2;
else if (*payload == '#') cmd = -3; else if (*payload == '#') cmd = -3;
@@ -104,10 +106,12 @@ Item::Item(char *name) //Constructor
Parse(); Parse();
} }
uint8_t Item::getCmd() { uint8_t Item::getCmd(bool ext) {
aJsonObject *t = aJson.getArrayItem(itemArr, I_CMD); aJsonObject *t = aJson.getArrayItem(itemArr, I_CMD);
if (t) if (t)
if (ext)
return t->valueint; return t->valueint;
else return t->valueint & CMD_MASK;
else return -1; else return -1;
} }
@@ -115,7 +119,11 @@ uint8_t Item::getCmd() {
void Item::setCmd(uint8_t cmd) { void Item::setCmd(uint8_t cmd) {
aJsonObject *t = aJson.getArrayItem(itemArr, I_CMD); aJsonObject *t = aJson.getArrayItem(itemArr, I_CMD);
if (t) if (t)
{
t->valueint = cmd; t->valueint = cmd;
Serial.print(F("SetCmd:"));
Serial.println(cmd);
}
} }
int Item::getArg(short n) //Return arg int or first array element if Arg is array int Item::getArg(short n) //Return arg int or first array element if Arg is array
@@ -279,6 +287,7 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send) {
default: default:
return -3; return -3;
}//switch old cmd }//switch old cmd
break;
case CMD_XOFF: case CMD_XOFF:
if (itemType != CH_GROUP) //individual threating of channels. Ignore restore command for groups if (itemType != CH_GROUP) //individual threating of channels. Ignore restore command for groups
switch (t = getCmd()) { switch (t = getCmd()) {
@@ -288,8 +297,11 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send) {
cmd = CMD_OFF; //turning Off cmd = CMD_OFF; //turning Off
break; break;
default: default:
Serial.print(F("XOFF skipped. Prev cmd:"));
Serial.println(t);
return -3; return -3;
}//switch old cmd }//switch old cmd
break;
} //switch cmd } //switch cmd
switch (cmd) { switch (cmd) {
@@ -316,6 +328,7 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send) {
Par[0] = st.h; Par[0] = st.h;
Par[1] = st.s; Par[1] = st.s;
Par[2] = st.v; Par[2] = st.v;
n = 3;
} }
if (send) SendStatus(0,3,Par,true); // Send back triplet ? if (send) SendStatus(0,3,Par,true); // Send back triplet ?
break; break;
@@ -336,8 +349,19 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send) {
break; break;
case CMD_ON:
case CMD_XON: case CMD_XON:
if (!isActive()) //if channel was'nt active before CMD_XON
{
Serial.println(F("Turning XON"));
// setCmd(cmd);
}
else
{ //cmd = CMD_ON;
Serial.println(F("Already Active"));
if (itemType != CH_GROUP) return -3;
}
case CMD_ON:
if (itemType==CH_RGBW && getCmd() == CMD_ON && getEnableCMD(500)) { if (itemType==CH_RGBW && getCmd() == CMD_ON && getEnableCMD(500)) {
Serial.println(F("Force White")); Serial.println(F("Force White"));
itemType = CH_WHITE; itemType = CH_WHITE;
@@ -412,6 +436,7 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send) {
case CH_THERMO: case CH_THERMO:
Par[0] = 20; //20 degrees celsium - safe temperature Par[0] = 20; //20 degrees celsium - safe temperature
params = 1; params = 1;
setVal(20);
SendStatus(0, params, Par); SendStatus(0, params, Par);
break; break;
case CH_RGBW: case CH_RGBW:
@@ -420,16 +445,23 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send) {
Par[1] = 0; Par[1] = 0;
Par[2] = 100; Par[2] = 100;
params = 3; params = 3;
// Store
st.h = Par[0];
st.s = Par[1];
st.v = Par[2];
setVal(st.aslong);
SendStatus(0, params, Par,true); SendStatus(0, params, Par,true);
break; break;
case CH_RELAY: case CH_RELAY:
Par[0] = 100; Par[0] = 100;
params = 1; params = 1;
setVal(100);
if (send) SendStatus(CMD_ON); if (send) SendStatus(CMD_ON);
break; break;
default: default:
Par[0] = 100; Par[0] = 100;
params = 1; params = 1;
setVal(100);
SendStatus(0, params, Par); SendStatus(0, params, Par);
} }
} // default handler } // default handler
@@ -996,7 +1028,7 @@ int Item::checkFM() {
} }
boolean Item::checkModbusRetry() { boolean Item::checkModbusRetry() {
int cmd = getCmd(); int cmd = getCmd(true);
if (cmd & CMD_RETRY) { // if last sending attempt of command was failed if (cmd & CMD_RETRY) { // if last sending attempt of command was failed
int val = getVal(); int val = getVal();
Serial.println(F("Retrying CMD")); Serial.println(F("Retrying CMD"));
@@ -1074,7 +1106,7 @@ int Item::checkModbusDimmer(int data) {
if (d) { // Actually turned on if (d) { // Actually turned on
if (cmd == CMD_OFF || cmd == CMD_HALT) SendStatus(CMD_ON); //update OH with ON if it was turned off before if (cmd == CMD_OFF || cmd == CMD_HALT) SendStatus(CMD_ON); //update OH with ON if it was turned off before
SendStatus(0, 1, &d); //update OH with value SendStatus(0, 1, &d); //update OH with value
setCmd(CMD_ON); //store command if (cmd != CMD_XON && cmd != CMD_ON) setCmd(CMD_ON); //store command
setVal(d); //store value setVal(d); //store value
} else { } else {
if (cmd != CMD_HALT && cmd != CMD_OFF) { if (cmd != CMD_HALT && cmd != CMD_OFF) {
@@ -1110,7 +1142,7 @@ int Item::Poll() {
void Item::sendDelayedStatus(){ void Item::sendDelayedStatus(){
HSVstore st; HSVstore st;
int cmd=getCmd(); int cmd=getCmd(true);
short params = 0; short params = 0;
int Par[3]; int Par[3];
if (cmd & CMD_REPORT) if (cmd & CMD_REPORT)
@@ -1152,9 +1184,9 @@ void Item::sendDelayedStatus(){
int Item::SendStatus(short cmd, short n, int *Par, boolean deffered) { int Item::SendStatus(short cmd, short n, int *Par, boolean deffered) {
/// ToDo: relative patches, configuration /// ToDo: relative patches, configuration
int chancmd=getCmd(true);
if (deffered) { if (deffered) {
setCmd(cmd | CMD_REPORT); setCmd(chancmd | CMD_REPORT);
Serial.println(F("Status deffered")); Serial.println(F("Status deffered"));
// mqttClient.publish("/push", "1"); // mqttClient.publish("/push", "1");
return 0; return 0;

View File

@@ -33,13 +33,17 @@ e-mail anklimov@gmail.com
#define CMD_ON 1 #define CMD_ON 1
#define CMD_OFF 2 #define CMD_OFF 2
#define CMD_RESTORE 3 //on only if was turned off by CMD_HALT #define CMD_RESTORE 3 //on only if was turned off by CMD_HALT
#define CMD_TOGGLE 4 #define CMD_TOGGLE 4
#define CMD_HALT 5 //just Off #define CMD_HALT 5 //just Off
#define CMD_XON 6 //just on #define CMD_XON 6 //just on
#define CMD_XOFF 7 //off only if was previously turned on by CMD_XON #define CMD_XOFF 7 //off only if was previously turned on by CMD_XON
#define CMD_UP 8 //just on
#define CMD_DN 9 //off only if was previously turned on by CMD_XON
#define CMD_SET 0xe
#define CMD_MASK 0xf
#define CMD_CURTEMP 127 #define CMD_CURTEMP 127
#define CMD_SET 9
#define CMD_RETRY 64 #define CMD_RETRY 64
#define CMD_REPORT 32 #define CMD_REPORT 32
@@ -96,7 +100,7 @@ class Item
boolean getEnableCMD(int delta); boolean getEnableCMD(int delta);
//int getVal(short n); //From VAL array. Negative if no array //int getVal(short n); //From VAL array. Negative if no array
long int getVal(); //From int val OR array long int getVal(); //From int val OR array
uint8_t getCmd(); uint8_t getCmd(bool ext = false);
void setCmd(uint8_t cmd); void setCmd(uint8_t cmd);
//void setVal(uint8_t n, int par); //void setVal(uint8_t n, int par);
void setVal(long int par); void setVal(long int par);

View File

@@ -18,6 +18,7 @@ e-mail anklimov@gmail.com
*/ */
#ifndef OWIRE_DISABLE
#include "owTerm.h" #include "owTerm.h"
#include <Arduino.h> #include <Arduino.h>
@@ -204,3 +205,4 @@ void owAdd(DeviceAddress addr) {
t_count++; t_count++;
#endif #endif
} }
#endif

View File

@@ -32,16 +32,16 @@ e-mail anklimov@gmail.com
#define recheck_interval 5 #define recheck_interval 5
#define check_circle 2000/t_count #define check_circle 2000/t_count
#define SW_FIND 1 #define SW_FIND 1
#define SW_DOUBLECHECK 2 //Doublecheck required #define SW_DOUBLECHECK 2 //Doublecheck required
#define SW_PULSE0 4 //Pulse Reset started #define SW_PULSE0 4 //Pulse Reset started
#define SW_PULSE1 8 //Pulse Reset stsrted #define SW_PULSE1 8 //Pulse Reset stsrted
#define SW_PULSE_P0 0x10 //Pulse reset in process #define SW_PULSE_P0 0x10 //Pulse reset in process
#define SW_PULSE_P1 0x20 //Pulse reset in process #define SW_PULSE_P1 0x20 //Pulse reset in process
#define SW_CHANGED_P0 0x40 //Changes while pulse in progress #define SW_CHANGED_P0 0x40 //Changes while pulse in progress
#define SW_CHANGED_P1 0x80 //Changes while pulse in progress #define SW_CHANGED_P1 0x80 //Changes while pulse in progress
#define SW_PULSE0_R 0x100 //Pulse Reset requested #define SW_PULSE0_R 0x100 //Pulse Reset requested
#define SW_PULSE1_R 0x200 //Pulse Reset requested #define SW_PULSE1_R 0x200 //Pulse Reset requested
#define recheck_interval 5 #define recheck_interval 5
@@ -50,6 +50,8 @@ e-mail anklimov@gmail.com
#define t_max 20 //Maximum number of 1w devices #define t_max 20 //Maximum number of 1w devices
#define TEMPERATURE_PRECISION 9 #define TEMPERATURE_PRECISION 9
#ifndef OWIRE_DISABLE
#ifndef ARDUINO_ARCH_STM32F1 #ifndef ARDUINO_ARCH_STM32F1
#include <DS2482_OneWire.h> #include <DS2482_OneWire.h>
#endif #endif
@@ -84,7 +86,8 @@ extern owChangedType owChanged;
int owUpdate(); int owUpdate();
int owSetup(owChangedType owCh); int owSetup(owChangedType owCh);
void owLoop(); void owLoop();
void owIdle(void) ; void owIdle(void) ;
int owFind(DeviceAddress addr); int owFind(DeviceAddress addr);
void owAdd (DeviceAddress addr); void owAdd (DeviceAddress addr);
#endif

View File

@@ -99,12 +99,11 @@ lib_deps =
[env:megaatmega2560] [env:megaatmega2560]
platform = atmelavr platform = atmelavr
board = megaatmega2560 board = megaatmega2560
;upload_port = net:192.168.88.31:23
framework = arduino framework = arduino
;lib_ldf_mode = chain+ ;lib_ldf_mode = chain+
build_flags = !sh build_flags_mega2560.sh build_flags = !sh build_flags_mega2560.sh
lib_deps = lib_deps =
https://github.com/anklimov/Arduino-Temperature-Control-Library.git
https://github.com/anklimov/DS2482_OneWire
https://github.com/anklimov/DmxSimple https://github.com/anklimov/DmxSimple
https://github.com/anklimov/httpClient https://github.com/anklimov/httpClient
https://github.com/anklimov/aJson https://github.com/anklimov/aJson