Small fix

This commit is contained in:
2018-03-08 22:23:16 +03:00
parent a87207121b
commit 45cbd8b4a0
9 changed files with 196 additions and 70 deletions

4
.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
.pioenvs
.piolibdeps
.clang_complete
.gcc-flags.json

67
.travis.yml Normal file
View File

@@ -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

View File

@@ -28,6 +28,10 @@ e-mail anklimov@gmail.com
#endif #endif
#endif #endif
#if defined(__ESP__)
DMXESPSerial dmxout;
#endif
uint8_t * DMXin = NULL; uint8_t * DMXin = NULL;
int D_State=0; int D_State=0;
@@ -225,6 +229,7 @@ void DMXoutSetup(int channels,int pin)
#if defined(__ESP__) #if defined(__ESP__)
dmxout.init(channels);
#endif #endif
#if defined(__SAM3X8E__) #if defined(__SAM3X8E__)

View File

@@ -39,7 +39,9 @@ e-mail anklimov@gmail.com
#endif #endif
#if defined(__ESP__) #if defined(__ESP__)
#include <ESP-Dmx.h> #include <ESPDMX.h>
extern DMXESPSerial dmxout;
#define DmxWrite dmxout.write
#endif #endif
#if defined(__SAM3X8E__) #if defined(__SAM3X8E__)

View File

@@ -22,20 +22,6 @@ e-mail anklimov@gmail.com
#include "aJSON.h" #include "aJSON.h"
#ifdef _dmxout #ifdef _dmxout
/*
#if defined(__AVR__)
#include <DmxSimple.h>
#endif
#if defined(__ESP__)
#include <ESP-Dmx.h>
#endif
#if defined(__SAM3X8E__)
#include <DmxDue.h>
#endif
*/
#include "dmx.h" #include "dmx.h"
#include "FastLED.h" #include "FastLED.h"
#endif #endif
@@ -223,20 +209,7 @@ int Item::Ctrl(short cmd, short n, int * Par, boolean send)
{ {
int t; int t;
case CMD_TOGGLE: case CMD_TOGGLE:
switch (t=getCmd()) if (isActive()) cmd=CMD_OFF; else cmd=CMD_ON;
{
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);
break; break;
case CMD_RESTORE: case CMD_RESTORE:
@@ -269,14 +242,17 @@ int Item::Ctrl(short cmd, short n, int * Par, boolean send)
st.s=Par[1]; st.s=Par[1];
st.v=Par[2]; st.v=Par[2];
setVal(st.aslong); setVal(st.aslong);
//SendCmd(0,3,Par); // Send back triplet ?
break; break;
case CH_DIMMER: //Everywhere, in flat VAL case CH_PWM:
case CH_MODBUS:
case CH_THERMO:
case CH_VC: case CH_VC:
case CH_DIMMER:
case CH_MODBUS:
SendCmd(0,1,Par); // Send back parameter for channel above this line
case CH_THERMO:
case CH_VCTEMP: case CH_VCTEMP:
setVal(Par[0]); setVal(Par[0]); // Store value
}//itemtype }//itemtype
@@ -306,10 +282,13 @@ int Item::Ctrl(short cmd, short n, int * Par, boolean send)
SendCmd(0,params,Par); // Send restored triplet SendCmd(0,params,Par); // Send restored triplet
break; break;
case CH_DIMMER: //Everywhere, in flat VAL case CH_DIMMER: //Everywhere, in flat VAL
case CH_MODBUS: case CH_MODBUS:
case CH_VC: case CH_VC:
case CH_VCTEMP: case CH_VCTEMP:
case CH_PWM:
Par[0]=st.aslong; Par[0]=st.aslong;
params=1; params=1;
SendCmd(0,params,Par); // Send restored parameter SendCmd(0,params,Par); // Send restored parameter
@@ -544,7 +523,12 @@ int Item::isActive()
if (!isValid()) return -1; if (!isValid()) return -1;
//Serial.print(itemArr->name); //Serial.print(itemArr->name);
int cmd=getCmd(); int cmd=getCmd();
if (itemType!=CH_GROUP)
// Simple check last command first
switch (cmd) switch (cmd)
{ {
case CMD_ON: case CMD_ON:
@@ -552,19 +536,38 @@ switch (cmd)
return 1; return 1;
case CMD_OFF: case CMD_OFF:
case CMD_HALT: case CMD_HALT:
case -1: ///// No last command
//Serial.println(" inactive"); //Serial.println(" inactive");
return 0; return 0;
} }
// Last time was not a command but parameters set. Looking inside
st.aslong=getVal(); st.aslong=getVal();
switch (itemType) 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_RGBW:
case CH_RGB: case CH_RGB:
val=st.v;
val=st.v; //Light volume
break; break;
case CH_DIMMER: //Everywhere, in flat VAL case CH_DIMMER: //Everywhere, in flat VAL

View File

@@ -57,11 +57,14 @@ DMX-OUT deploy on USART1
Config webserver Config webserver
*/ */
#if defined(__ESP__)
#include <FS.h> //this needs to be first, or it all crashes and burns...
#endif
// Configuration of drivers enabled // Configuration of drivers enabled
#include "options.h" #include "options.h"
#include <Ethernet.h>
#include <PubSubClient.h> #include <PubSubClient.h>
#include <SPI.h> #include <SPI.h>
#include "utils.h" #include "utils.h"
@@ -95,7 +98,16 @@ Config webserver
#include <EEPROM.h> #include <EEPROM.h>
#endif #endif
#if defined(ESP_PLATFORM) #if defined(__ESP__)
#include "esp.h"
#define wdt_res()
#define wdt_en()
#define wdt_dis()
#else
#include <Ethernet2.h>
EthernetClient ethClient;
#endif #endif
#ifdef _owire #ifdef _owire
@@ -152,7 +164,7 @@ ModbusMaster node;
byte mac[6]; byte mac[6];
EthernetClient ethClient;
PubSubClient client(ethClient); PubSubClient client(ethClient);
@@ -283,6 +295,12 @@ switch (lanStatus)
{ {
//Initial state //Initial state
case 0: //Ethernet.begin(mac,ip); 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")); Serial.println(F("Starting lan"));
wdt_dis(); wdt_dis();
if (Ethernet.begin(mac,12000) == 0) { if (Ethernet.begin(mac,12000) == 0) {
@@ -296,6 +314,7 @@ if (Ethernet.begin(mac,12000) == 0) {
} }
wdt_en(); wdt_en();
wdt_res(); wdt_res();
#endif
break; break;
//Have IP address //Have IP address
case 1: case 1:
@@ -852,12 +871,23 @@ void postTransmission()
} }
void setup() { void setup() {
cmdInit(115200); cmdInit(115200);
Serial.println(F("\nLazyhome.ru LightHub controller v0.96")); 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
short macvalid=0; short macvalid=0;
byte defmac[6]={0xDE,0xAD,0xBE,0xEF,0xFE,0}; byte defmac[6]={0xDE,0xAD,0xBE,0xEF,0xFE,0};
@@ -905,14 +935,6 @@ void setup() {
// checkForRemoteSketchUpdate(); // checkForRemoteSketchUpdate();
#endif #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 (inputs) inputLoop();
#if defined (_espdmx)
dmxout.update();
#endif
} }
// Idle handlers // Idle handlers
@@ -972,6 +998,10 @@ if (lanLoop() == 1) client.loop();
DMXCheck(); DMXCheck();
#endif #endif
#if defined (_espdmx)
dmxout.update();
#endif
//modbusLoop(); //modbusLoop();
} }
@@ -993,6 +1023,11 @@ if (lanLoop() > 1)
#ifdef _dmxin #ifdef _dmxin
DMXCheck(); DMXCheck();
#endif #endif
#if defined (_espdmx)
dmxout.update();
#endif
//modbusloop(); //modbusloop();
} }

View File

@@ -5,6 +5,9 @@
#define _modbus #define _modbus
#define _artnet #define _artnet
#if defined(ESP8266)
#define __ESP__
#endif
#if defined(__AVR__) #if defined(__AVR__)
//All options available //All options available
@@ -19,10 +22,11 @@
#define dmxin DmxDue1 #define dmxin DmxDue1
#endif #endif
#if defined(ESP_PLATFORM) #if defined(__ESP__)
#undef _dmxin #undef _dmxin
#undef _dmxout #undef _modbus
#define modbusSerial Serial #define _espdmx
#define modbusSerial Serial1
#endif #endif
#ifndef _dmxout #ifndef _dmxout

View File

@@ -23,6 +23,12 @@ e-mail anklimov@gmail.com
#include <malloc.h> #include <malloc.h>
#endif #endif
#if defined(ESP8266)
extern "C" {
#include "user_interface.h"
}
#endif
void PrintBytes(uint8_t* addr, uint8_t count, bool newline) { void PrintBytes(uint8_t* addr, uint8_t count, bool newline) {
for (uint8_t i = 0; i < count; i++) { for (uint8_t i = 0; i < count; i++) {
Serial.print(addr[i]>>4, HEX); Serial.print(addr[i]>>4, HEX);
@@ -74,13 +80,13 @@ int getInt(char ** chan)
} }
#if defined(ESP_PLATFORM) #if defined(ESP8266)
int freeRam () unsigned long freeRam ()
{return system_get_free_heap_size();} {return system_get_free_heap_size();}
#endif #endif
#if defined(__AVR__) #if defined(__AVR__)
int freeRam () unsigned long freeRam ()
{ {
extern int __heap_start, *__brkval; extern int __heap_start, *__brkval;
int v; int v;
@@ -92,7 +98,7 @@ int freeRam ()
extern char _end; extern char _end;
extern "C" char *sbrk(int i); extern "C" char *sbrk(int i);
int freeRam() unsigned long freeRam()
{ {
char *ramstart = (char *) 0x20070000; char *ramstart = (char *) 0x20070000;
char *ramend = (char *) 0x20088000; char *ramend = (char *) 0x20088000;

View File

@@ -24,4 +24,4 @@ void SetBytes(uint8_t* addr, uint8_t count, char * out);
void SetAddr(char * out, uint8_t* addr); void SetAddr(char * out, uint8_t* addr);
uint8_t HEX2DEC(char i); uint8_t HEX2DEC(char i);
int getInt(char ** chan); int getInt(char ** chan);
int freeRam (); unsigned long freeRam ();