diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5dac9f5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.pioenvs +.piolibdeps +.clang_complete +.gcc-flags.json diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..9443843 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,67 @@ +# Continuous Integration (CI) is the practice, in software +# engineering, of merging all developer working copies with a shared mainline +# several times a day < http://docs.platformio.org/page/ci/index.html > +# +# Documentation: +# +# * Travis CI Embedded Builds with PlatformIO +# < https://docs.travis-ci.com/user/integration/platformio/ > +# +# * PlatformIO integration with Travis CI +# < http://docs.platformio.org/page/ci/travis.html > +# +# * User Guide for `platformio ci` command +# < http://docs.platformio.org/page/userguide/cmd_ci.html > +# +# +# Please choice one of the following templates (proposed below) and uncomment +# it (remove "# " before each line) or use own configuration according to the +# Travis CI documentation (see above). +# + + +# +# Template #1: General project. Test it using existing `platformio.ini`. +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# install: +# - pip install -U platformio +# - platformio update +# +# script: +# - platformio run + + +# +# Template #2: The project is intended to by used as a library with examples +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# env: +# - PLATFORMIO_CI_SRC=path/to/test/file.c +# - PLATFORMIO_CI_SRC=examples/file.ino +# - PLATFORMIO_CI_SRC=path/to/test/directory +# +# install: +# - pip install -U platformio +# - platformio update +# +# script: +# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/lighthub/dmx.cpp b/lighthub/dmx.cpp index c16483f..e8826f6 100644 --- a/lighthub/dmx.cpp +++ b/lighthub/dmx.cpp @@ -28,6 +28,10 @@ e-mail anklimov@gmail.com #endif #endif +#if defined(__ESP__) +DMXESPSerial dmxout; +#endif + uint8_t * DMXin = NULL; int D_State=0; @@ -225,6 +229,7 @@ void DMXoutSetup(int channels,int pin) #if defined(__ESP__) +dmxout.init(channels); #endif #if defined(__SAM3X8E__) diff --git a/lighthub/dmx.h b/lighthub/dmx.h index 4b21b56..9109d11 100644 --- a/lighthub/dmx.h +++ b/lighthub/dmx.h @@ -39,7 +39,9 @@ e-mail anklimov@gmail.com #endif #if defined(__ESP__) -#include +#include +extern DMXESPSerial dmxout; +#define DmxWrite dmxout.write #endif #if defined(__SAM3X8E__) diff --git a/lighthub/item.cpp b/lighthub/item.cpp index 0189b80..71cec63 100644 --- a/lighthub/item.cpp +++ b/lighthub/item.cpp @@ -22,20 +22,6 @@ e-mail anklimov@gmail.com #include "aJSON.h" #ifdef _dmxout - -/* -#if defined(__AVR__) -#include -#endif - -#if defined(__ESP__) -#include -#endif - -#if defined(__SAM3X8E__) -#include -#endif -*/ #include "dmx.h" #include "FastLED.h" #endif @@ -223,20 +209,7 @@ int Item::Ctrl(short cmd, short n, int * Par, boolean send) { int t; case CMD_TOGGLE: - switch (t=getCmd()) - { - case CMD_ON: - case CMD_SET: - cmd=CMD_OFF; - break; - case CMD_OFF: - case CMD_HALT: - case 0: - case -1: //No stored command yet - cmd=CMD_ON; - break; - }//switch old cmd - //Serial.print("Tog/oldcmd:");Serial.print(t);Serial.print(F(" new "));Serial.println(cmd); + if (isActive()) cmd=CMD_OFF; else cmd=CMD_ON; break; case CMD_RESTORE: @@ -253,7 +226,7 @@ int Item::Ctrl(short cmd, short n, int * Par, boolean send) } //switch cmd switch (cmd) - { + { case 0: //no command setCmd(CMD_SET); @@ -268,15 +241,18 @@ int Item::Ctrl(short cmd, short n, int * Par, boolean send) st.h=Par[0]; st.s=Par[1]; st.v=Par[2]; - setVal(st.aslong); + setVal(st.aslong); + //SendCmd(0,3,Par); // Send back triplet ? break; - case CH_DIMMER: //Everywhere, in flat VAL + case CH_PWM: + case CH_VC: + case CH_DIMMER: case CH_MODBUS: - case CH_THERMO: - case CH_VC: + SendCmd(0,1,Par); // Send back parameter for channel above this line + case CH_THERMO: case CH_VCTEMP: - setVal(Par[0]); + setVal(Par[0]); // Store value }//itemtype @@ -305,11 +281,14 @@ int Item::Ctrl(short cmd, short n, int * Par, boolean send) params=3; SendCmd(0,params,Par); // Send restored triplet break; - + + case CH_DIMMER: //Everywhere, in flat VAL - case CH_MODBUS: - case CH_VC: - case CH_VCTEMP: + case CH_MODBUS: + case CH_VC: + case CH_VCTEMP: + case CH_PWM: + Par[0]=st.aslong; params=1; SendCmd(0,params,Par); // Send restored parameter @@ -544,7 +523,12 @@ int Item::isActive() if (!isValid()) return -1; //Serial.print(itemArr->name); + int cmd=getCmd(); + + +if (itemType!=CH_GROUP) +// Simple check last command first switch (cmd) { case CMD_ON: @@ -552,19 +536,38 @@ switch (cmd) return 1; case CMD_OFF: case CMD_HALT: + case -1: ///// No last command //Serial.println(" inactive"); return 0; } +// Last time was not a command but parameters set. Looking inside st.aslong=getVal(); switch (itemType) { - //case CH_GROUP: + case CH_GROUP: //make recursive calculation - is it some active in group + if (itemArg->type==aJson_Array) + { + Serial.println(F("Grp check: ")); + aJsonObject *i =itemArg->child; + while (i) + { + Item it (i->valuestring); + + if (it.isValid() && it.isActive()) {Serial.println(F("Active")); return 1;} + i=i->next; + } //while + return 0; + } //if + break; + + case CH_RGBW: case CH_RGB: - - val=st.v; + + + val=st.v; //Light volume break; case CH_DIMMER: //Everywhere, in flat VAL @@ -572,7 +575,7 @@ switch (itemType) case CH_THERMO: case CH_VC: case CH_VCTEMP: - val=st.aslong; + val=st.aslong; } //switch Serial.print(F(":="));Serial.println(val); if (val) return 1; else return 0; diff --git a/lighthub/lighthub.ino b/lighthub/lighthub.ino index 543808f..dc0fffe 100644 --- a/lighthub/lighthub.ino +++ b/lighthub/lighthub.ino @@ -57,11 +57,14 @@ DMX-OUT deploy on USART1 Config webserver */ +#if defined(__ESP__) +#include //this needs to be first, or it all crashes and burns... +#endif // Configuration of drivers enabled #include "options.h" -#include + #include #include #include "utils.h" @@ -95,7 +98,16 @@ Config webserver #include #endif -#if defined(ESP_PLATFORM) +#if defined(__ESP__) +#include "esp.h" +#define wdt_res() +#define wdt_en() +#define wdt_dis() + + +#else +#include +EthernetClient ethClient; #endif #ifdef _owire @@ -152,7 +164,7 @@ ModbusMaster node; byte mac[6]; -EthernetClient ethClient; + PubSubClient client(ethClient); @@ -283,9 +295,15 @@ switch (lanStatus) { //Initial state case 0: //Ethernet.begin(mac,ip); + +#ifdef __ESP__ +//WiFi.mode(WIFI_STA); +//wifiMulti.addAP("Smartbox", ""); +if((wifiMulti.run() == WL_CONNECTED)) lanStatus=1; +#else Serial.println(F("Starting lan")); wdt_dis(); -if (Ethernet.begin(mac,12000) == 0) { +if (Ethernet.begin(mac,12000) == 0) { Serial.println(F("Failed to configure Ethernet using DHCP")); lanStatus = -10; lanCheck=millis()+60000; @@ -296,6 +314,7 @@ if (Ethernet.begin(mac,12000) == 0) { } wdt_en(); wdt_res(); +#endif break; //Have IP address case 1: @@ -851,13 +870,24 @@ void postTransmission() digitalWrite(TXEnablePin, 0); } -void setup() { - - - cmdInit(115200); +void setup() { + cmdInit(115200); + + Serial.println(F("\nLazyhome.ru LightHub controller v0.96")); + + cmdAdd("help", _handleHelp); + cmdAdd("save", _saveConfig); + cmdAdd("load", _loadConfig); + cmdAdd("get", _getConfig); + cmdAdd("set", _setConfig); + cmdAdd("kill", _kill); + cmdAdd("req", _mqttConfigReq); + + + #ifdef __ESP__ + espSetup(); + #endif - Serial.println(F("\nLazyhome.ru LightHub controller v0.96")); - short macvalid=0; byte defmac[6]={0xDE,0xAD,0xBE,0xEF,0xFE,0}; @@ -905,14 +935,6 @@ void setup() { // checkForRemoteSketchUpdate(); #endif - cmdAdd("help", _handleHelp); - cmdAdd("save", _saveConfig); - cmdAdd("load", _loadConfig); - cmdAdd("get", _getConfig); - cmdAdd("set", _setConfig); - cmdAdd("kill", _kill); - cmdAdd("req", _mqttConfigReq); - } @@ -952,6 +974,10 @@ if (owReady && owArr) owLoop(); if (inputs) inputLoop(); +#if defined (_espdmx) + dmxout.update(); +#endif + } // Idle handlers @@ -971,7 +997,11 @@ if (lanLoop() == 1) client.loop(); #ifdef _dmxin DMXCheck(); #endif - + +#if defined (_espdmx) + dmxout.update(); +#endif + //modbusLoop(); } @@ -993,6 +1023,11 @@ if (lanLoop() > 1) #ifdef _dmxin DMXCheck(); #endif + +#if defined (_espdmx) + dmxout.update(); +#endif + //modbusloop(); } diff --git a/lighthub/options.h b/lighthub/options.h index fa55863..9517d24 100644 --- a/lighthub/options.h +++ b/lighthub/options.h @@ -5,6 +5,9 @@ #define _modbus #define _artnet +#if defined(ESP8266) +#define __ESP__ +#endif #if defined(__AVR__) //All options available @@ -19,10 +22,11 @@ #define dmxin DmxDue1 #endif -#if defined(ESP_PLATFORM) +#if defined(__ESP__) #undef _dmxin -#undef _dmxout -#define modbusSerial Serial +#undef _modbus +#define _espdmx +#define modbusSerial Serial1 #endif #ifndef _dmxout diff --git a/lighthub/utils.cpp b/lighthub/utils.cpp index 9d6133c..4459e31 100644 --- a/lighthub/utils.cpp +++ b/lighthub/utils.cpp @@ -23,6 +23,12 @@ e-mail anklimov@gmail.com #include #endif +#if defined(ESP8266) +extern "C" { +#include "user_interface.h" +} +#endif + void PrintBytes(uint8_t* addr, uint8_t count, bool newline) { for (uint8_t i = 0; i < count; i++) { Serial.print(addr[i]>>4, HEX); @@ -74,13 +80,13 @@ int getInt(char ** chan) } -#if defined(ESP_PLATFORM) -int freeRam () +#if defined(ESP8266) +unsigned long freeRam () {return system_get_free_heap_size();} #endif #if defined(__AVR__) -int freeRam () +unsigned long freeRam () { extern int __heap_start, *__brkval; int v; @@ -92,7 +98,7 @@ int freeRam () extern char _end; extern "C" char *sbrk(int i); -int freeRam() +unsigned long freeRam() { char *ramstart = (char *) 0x20070000; char *ramend = (char *) 0x20088000; diff --git a/lighthub/utils.h b/lighthub/utils.h index ccacb34..41eaa7e 100644 --- a/lighthub/utils.h +++ b/lighthub/utils.h @@ -24,4 +24,4 @@ void SetBytes(uint8_t* addr, uint8_t count, char * out); void SetAddr(char * out, uint8_t* addr); uint8_t HEX2DEC(char i); int getInt(char ** chan); -int freeRam (); +unsigned long freeRam ();