From 3c38e151e14882d3c0cbc8fb214e965f4afefa17 Mon Sep 17 00:00:00 2001 From: Andrey Klimov Date: Sat, 4 Jul 2020 22:04:57 +0300 Subject: [PATCH] SlatusLed & reverting to Ethernet2 wiznet lib --- build-flags/build_flags_lighthub21 | 1 + lighthub/item.cpp | 253 +++++++++++++++++++++++++++++ lighthub/item.h | 2 + lighthub/main.cpp | 17 +- lighthub/utils.cpp | 57 +++++++ lighthub/utils.h | 29 ++++ platformio.ini | 9 +- 7 files changed, 357 insertions(+), 11 deletions(-) diff --git a/build-flags/build_flags_lighthub21 b/build-flags/build_flags_lighthub21 index d28e605..9104f31 100644 --- a/build-flags/build_flags_lighthub21 +++ b/build-flags/build_flags_lighthub21 @@ -5,3 +5,4 @@ -DMODBUS_SERIAL_BAUD=9600 -DOTA -DSYSLOG_ENABLE +-DWiz5500 diff --git a/lighthub/item.cpp b/lighthub/item.cpp index e2ed62c..9a543b5 100644 --- a/lighthub/item.cpp +++ b/lighthub/item.cpp @@ -643,6 +643,259 @@ short Item::cmd2changeActivity(int lastActivity, short defaultCmd) } */ +int Ctrl(itemCmd cmd, int suffixCode, char* subItem) +{ + /* + char stringBuffer[16]; + bool operation = isNotRetainingStatus() ; + + if ((!subItem || !strlen(subItem)) && strlen(defaultSubItem)) + subItem = defaultSubItem; /// possible problem here with truncated default + + if (!suffixCode && subItem && strlen(subItem)) + suffixCode = retrieveCode(&subItem); + + if (!suffixCode && defaultSuffixCode) + suffixCode = defaultSuffixCode; + + + debugSerial<setVal(st=Parameters[0]); //Store + if (!suffixCode) + { + if (chActive>0 && !st) item->setCmd(CMD_OFF); + if (chActive==0 && st) item->setCmd(CMD_ON); + item->SendStatus(SEND_COMMAND | SEND_PARAMETERS | SEND_DEFFERED); + if (item->getExt()) item->setExt(millis()+maxOnTime); //Extend motor time + } + else item->SendStatus(SEND_PARAMETERS | SEND_DEFFERED); + + return 1; + //break; + + case S_CMD: + item->setCmd(cmd); + switch (cmd) + { + case CMD_ON: + //retrive stored values + st = item->getVal(); + + + if (st && (stsetVal(st); + + if (st) //Stored smthng + { + item->SendStatus(SEND_COMMAND | SEND_PARAMETERS); + debugSerial<setVal(st); + item->SendStatus(SEND_COMMAND | SEND_PARAMETERS ); + } + if (item->getExt()) item->setExt(millis()+maxOnTime); //Extend motor time + return 1; + + case CMD_OFF: + item->SendStatus(SEND_COMMAND); + if (item->getExt()) item->setExt(millis()+maxOnTime); //Extend motor time + return 1; + + } //switch cmd + + break; + } //switch suffix + debugSerial< nextLanCheckTime) onInitialStateInitLAN(); break; case HAVE_IP_ADDRESS: - + LED.set(ledRED|ledGREEN|((configLoaded)?ledBLINK:0)); if (configLocked) return HAVE_IP_ADDRESS; if (!configOk) lanStatus = loadConfigFromHttp(0, NULL); @@ -365,9 +368,7 @@ lan_status lanLoop() { case IP_READY_CONFIG_LOADED_CONNECTING_TO_BROKER: wdt_res(); - - - + LED.set(ledRED|ledGREEN|((configLoaded)?ledBLINK:0)); ip_ready_config_loaded_connecting_to_broker(); break; @@ -387,10 +388,12 @@ lan_status lanLoop() { } case OPERATION: + LED.set(ledGREEN|((configLoaded)?ledBLINK:0)); if (!mqttClient.connected()) lanStatus = IP_READY_CONFIG_LOADED_CONNECTING_TO_BROKER;//2; break; case AWAITING_ADDRESS: + LED.set(ledRED|((configLoaded)?ledBLINK:0)); if (millis() > nextLanCheckTime) lanStatus = INITIAL_STATE;//0; break; @@ -1061,7 +1064,7 @@ configLocked++; udpSyslogArr = aJson.getObjectItem(root, "syslog"); #endif printConfigSummary(); - +configLoaded=true; configLocked--; } @@ -1786,7 +1789,7 @@ void setupCmdArduino() { } void loop_main() { - + LED.poll(); #if defined(M5STACK) // Initialize the M5Stack object diff --git a/lighthub/utils.cpp b/lighthub/utils.cpp index ba8918e..bf477cc 100644 --- a/lighthub/utils.cpp +++ b/lighthub/utils.cpp @@ -630,7 +630,64 @@ itemCmd mapInt(int32_t arg, aJsonObject* map) return _itemCmd.Int(arg); } +statusLED::statusLED(uint8_t pattern) +{ + pinMode(pinRED, OUTPUT); + pinMode(pinGREEN, OUTPUT); + pinMode(pinBLUE, OUTPUT); + set(pattern); + timestamp=0; +} +void statusLED::show (uint8_t pattern) +{ + digitalWrite(pinRED,(pattern & ledRED)?HIGH:LOW ); + digitalWrite(pinGREEN,(pattern & ledGREEN)?HIGH:LOW); + digitalWrite(pinBLUE,(pattern & ledBLUE)?HIGH:LOW); +} + +void statusLED::set (uint8_t pattern) +{ + short newStat = pattern & ledParams; + + if (newStat!=(curStat & ledParams)) + { + //if (!(curStat & ledHidden)) + show(pattern); + curStat=newStat | (curStat & ~ledParams); + } +} + +void statusLED::flash(uint8_t pattern) +{ + show(pattern); + curStat|=ledFlash; +} + +void statusLED::poll() + +{ + if (curStat & ledFlash) + { + curStat&=~ledFlash; + show(curStat); + } +if (millis()>timestamp) + { + + if (curStat & ledFASTBLINK) timestamp=millis()+ledFastDelayms; + else timestamp=millis()+ledDelayms; + + if (( curStat & ledBLINK) || (curStat & ledFASTBLINK)) + { + curStat^=ledHidden; + if (curStat & ledHidden) + show(0); + else show(curStat); + } + } + +} #pragma message(VAR_NAME_VALUE(debugSerial)) diff --git a/lighthub/utils.h b/lighthub/utils.h index 3fdc4cf..bc45745 100644 --- a/lighthub/utils.h +++ b/lighthub/utils.h @@ -65,3 +65,32 @@ bool isTimeOver(uint32_t timestamp, uint32_t currTime, uint32_t time, uint32_t m bool executeCommand(aJsonObject* cmd, int8_t toggle = -1); bool executeCommand(aJsonObject* cmd, int8_t toggle, itemCmd _itemCmd); itemCmd mapInt(int32_t arg, aJsonObject* map); + +#define ledRED 1 +#define ledGREEN 2 +#define ledBLUE 4 +#define ledBLINK 8 +#define ledFASTBLINK 16 +#define ledParams (ledRED | ledGREEN | ledBLUE | ledBLINK | ledFASTBLINK) + +#define ledFlash 32 +#define ledHidden 64 + +#define pinRED 50 +#define pinGREEN 51 +#define pinBLUE 52 + +#define ledDelayms 1000UL +#define ledFastDelayms 300UL + +class statusLED { +public: + statusLED(uint8_t pattern = 0); + void set (uint8_t pattern); + void show (uint8_t pattern); + void poll(); + void flash(uint8_t pattern); +private: + uint8_t curStat; + uint32_t timestamp; +}; diff --git a/platformio.ini b/platformio.ini index 0d9e6ca..8344245 100644 --- a/platformio.ini +++ b/platformio.ini @@ -23,13 +23,13 @@ default_envs = ; mega2560-5500 ; LightHub controller HW revision 2.1 and above (Wiznet 5500 CS on pin 53) -; lighthub21 + lighthub21 ; Arduino DUE + Ethernet shield Wiznet 5100 ; due-5100 ; Generic DUE - due +; due ; Arduino DUE + Ethernet shield Wiznet 5500 ; due-5500 @@ -551,6 +551,7 @@ platform = atmelsam framework = arduino board = due build_flags = !python get_build_flags.py lighthub21 +;upload_command = arduinoOTA -address 192.168.88.59 -port 65280 -username arduino -password password -b -upload /sketch -sketch $SOURCE ;upload_command = arduinoOTA -address 192.168.88.34 -port 65280 -username arduino -password password -b -upload /sketch -sketch $SOURCE ;upload_protocol = custom lib_ignore = @@ -562,7 +563,7 @@ lib_ignore = WifiManager DmxSimple httpClient - Ethernet2 + Ethernet Ethernet3 NRFFlashStorage WebServer @@ -580,7 +581,7 @@ lib_deps = https://github.com/anklimov/aJson https://github.com/anklimov/CmdArduino https://github.com/anklimov/ModbusMaster - https://github.com/anklimov/Ethernet + https://github.com/anklimov/Ethernet2 https://github.com/knolleary/pubsubclient.git https://github.com/anklimov/Artnet.git FastLED@3.3.2