Compiled for all platforms + binaries

This commit is contained in:
2020-05-07 00:22:27 +03:00
parent 7b9c474c19
commit f650b830d7
27 changed files with 26363 additions and 24567 deletions

View File

@@ -38,5 +38,5 @@ int abstractCh::publishTopic(const char* topic, const char * value, const char*
return 1;
}
}
return 0;
};

View File

@@ -26,7 +26,6 @@ int abstractIn::publish(float value, const char* subtopic)
int abstractIn::publish(char * value, const char* subtopic)
{
char addrstr[MQTT_TOPIC_LENGTH];
if (in)
{
aJsonObject *emit = aJson.getObjectItem(in->inputObj, "emit");

23
lighthub/bright.cpp Normal file
View File

@@ -0,0 +1,23 @@
#include "bright.h"
uint8_t getBright(uint8_t percent)
{
int index = map(percent,0,100,0,255);
if (index>255) index=255;
return getBright255(index);
}
uint8_t getBright255(uint8_t percent)
{
#ifdef BRIGHT_LINEAR
return percent;
#else
int val = stepvar[index];
if (val>255) val=255;
Serial.print(F("Bright:"));
Serial.print(percent);
Serial.print(F("->"));
Serial.println(val);
return val;
#endif
}

105
lighthub/bright.h Normal file
View File

@@ -0,0 +1,105 @@
#pragma once
#include <Arduino.h>
#define BRIGHT_LINEAR
#ifdef BRIGHT_LOG
const uint8_t stepvar[] PROGMEM =
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
// 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x02, 0x02, 0x02, 0x02, 0x02,
0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
0x02, 0x03, 0x03, 0x03, 0x03, 0x03,
0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
0x03, 0x03, 0x03, 0x03, 0x04, 0x04,
0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
0x04, 0x04, 0x04, 0x04, 0x05, 0x05,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x05, 0x06, 0x06, 0x06, 0x06, 0x06,
0x06, 0x06, 0x06, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x08, 0x08, 0x08,
0x08, 0x08, 0x08, 0x09, 0x09, 0x09,
0x09, 0x09, 0x0A, 0x0A, 0x0A, 0x0A,
0x0A, 0x0B, 0x0B, 0x0B, 0x0B, 0x0C,
0x0C, 0x0C, 0x0C, 0x0D, 0x0D, 0x0D,
0x0E, 0x0E, 0x0E, 0x0E, 0x0F, 0x0F,
0x0F, 0x10, 0x10, 0x10, 0x11, 0x11,
0x12, 0x12, 0x12, 0x13, 0x13, 0x14,
0x14, 0x14, 0x15, 0x15, 0x16, 0x16,
0x17, 0x17, 0x18, 0x18, 0x19, 0x19,
0x1A, 0x1B, 0x1B, 0x1C, 0x1C, 0x1D,
0x1E, 0x1E, 0x1F, 0x20, 0x20, 0x21,
0x22, 0x23, 0x23, 0x24, 0x25, 0x26,
0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B,
0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31,
0x32, 0x33, 0x34, 0x35, 0x37, 0x38,
0x39, 0x3A, 0x3B, 0x3D, 0x3E, 0x3F,
0x41, 0x42, 0x44, 0x45, 0x47, 0x48,
0x4A, 0x4C, 0x4D, 0x4F, 0x51, 0x52,
0x54, 0x56, 0x58, 0x5A, 0x5C, 0x5E,
0x60, 0x62, 0x64, 0x66, 0x69, 0x6B,
0x6D, 0x70, 0x72, 0x75, 0x77, 0x7A,
0x7C, 0x7F, 0x82, 0x85, 0x88, 0x8B,
0x8E, 0x91, 0x94, 0x97, 0x9B, 0x9E,
0xA2, 0xA5, 0xA9, 0xAC, 0xB0, 0xB4,
0xB8, 0xBC, 0xC0, 0xC4, 0xC9, 0xCD,
0xD2, 0xD6, 0xDB, 0xE0, 0xE5, 0xEA,
0xEF, 0xF4, 0xF9, 0xFF};
#endif
#ifdef BRIGHT_STEP
const uint8_t stepvar[] PROGMEM =
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x02,
0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
0x02, 0x02, 0x03, 0x03, 0x03, 0x03,
0x03, 0x03, 0x04, 0x04, 0x04, 0x04,
0x04, 0x04, 0x05, 0x05, 0x05, 0x05,
0x06, 0x06, 0x06, 0x06, 0x07, 0x07,
0x07, 0x07, 0x08, 0x08, 0x08, 0x08,
0x09, 0x09, 0x09, 0x0A, 0x0A, 0x0A,
0x0B, 0x0B, 0x0C, 0x0C, 0x0C, 0x0D,
0x0D, 0x0E, 0x0E, 0x0E, 0x0F, 0x0F,
0x10, 0x10, 0x11, 0x11, 0x12, 0x12,
0x13, 0x13, 0x14, 0x14, 0x15, 0x16,
0x16, 0x17, 0x17, 0x18, 0x19, 0x19,
0x1A, 0x1B, 0x1B, 0x1C, 0x1D, 0x1D,
0x1E, 0x1F, 0x20, 0x20, 0x21, 0x22,
0x23, 0x23, 0x24, 0x25, 0x26, 0x27,
0x28, 0x29, 0x29, 0x2A, 0x2B, 0x2C,
0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32,
0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
0x39, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
0x40, 0x42, 0x43, 0x44, 0x45, 0x47,
0x48, 0x49, 0x4B, 0x4C, 0x4D, 0x4F,
0x50, 0x51, 0x53, 0x54, 0x56, 0x57,
0x59, 0x5A, 0x5C, 0x5D, 0x5F, 0x60,
0x62, 0x64, 0x65, 0x67, 0x68, 0x6A,
0x6C, 0x6E, 0x6F, 0x71, 0x73, 0x75,
0x76, 0x78, 0x7A, 0x7C, 0x7E, 0x80,
0x82, 0x84, 0x85, 0x87, 0x89, 0x8B,
0x8E, 0x90, 0x92, 0x94, 0x96, 0x98,
0x9A, 0x9C, 0x9E, 0xA1, 0xA3, 0xA5,
0xA7, 0xAA, 0xAC, 0xAE, 0xB1, 0xB3,
0xB6, 0xB8, 0xBA, 0xBD, 0xBF, 0xC2,
0xC4, 0xC7, 0xCA, 0xCC, 0xCF, 0xD1,
0xD4, 0xD7, 0xD9, 0xDC, 0xDF, 0xE2,
0xE5, 0xE7, 0xEA, 0xED, 0xF0, 0xF3,
0xF6, 0xF9, 0xFC, 0xFF};
#endif
uint8_t getBright(uint8_t percent);
uint8_t getBright255(uint8_t percent);

View File

@@ -122,7 +122,6 @@ void DMXSemiImmediateUpdate(short tch,short trh, int val)
void DMXput(void)
{
int t;
for (short tch=0; tch<=3 ; tch++)
{
short base = tch*4;
@@ -202,7 +201,7 @@ for (int i=1; i<17; i++) {Serial.print(dmxin.read(i));Serial.print(";");}
void onDmxFrame(uint16_t universe, uint16_t length, uint8_t sequence, uint8_t* data, IPAddress remoteIP)
{
#ifdef _dmxout
for (int i = 0 ; i < length && i<MAX_CHANNELS ; i++)
for (unsigned int i = 0 ; i < length && i<MAX_CHANNELS ; i++)
{
DmxWrite(i+1,data[i]);
}

View File

@@ -176,7 +176,7 @@ switch (inType)
}
int Input::poll(short cause) {
int Input::Poll(short cause) {
if (!isValid()) return -1;
#ifndef CSSHDC_DISABLE
@@ -533,6 +533,7 @@ return true;
default:
return false;
} //switch type
return false;
}
// TODO Polling via timed interrupt with CHECK_INTERRUPT cause
@@ -669,8 +670,10 @@ switch (store->state) //Timer based transitions
{
case IS_PRESSED:
if (isTimeOver(store->timestamp16,millis() & 0xFFFF,T_LONG,0xFFFF))
{
if (!aJson.getObjectItem(inputObj, "lcmd") && !aJson.getObjectItem(inputObj, "rpcmd")) changeState(IS_WAITRELEASE, cause);
else changeState(IS_LONG, cause);
}
break;
case IS_LONG:
@@ -691,8 +694,10 @@ switch (store->state) //Timer based transitions
case IS_PRESSED2:
if (isTimeOver(store->timestamp16,millis() & 0xFFFF,T_LONG,0xFFFF))
{
if (!aJson.getObjectItem(inputObj, "lcmd2") && !aJson.getObjectItem(inputObj, "rpcmd2")) changeState(IS_WAITRELEASE, cause);
else changeState(IS_LONG2, cause);
}
break;
case IS_LONG2:

View File

@@ -145,7 +145,7 @@ public:
void onContactChanged(int newValue);
void onAnalogChanged(float newValue);
int poll(short cause);
int Poll(short cause);
void setup();
static void inline onCounterChanged(int i);

View File

@@ -24,6 +24,7 @@ e-mail anklimov@gmail.com
#include "utils.h"
#include "textconst.h"
#include "main.h"
#include "bright.h"
#ifdef _dmxout
#include "dmx.h"
@@ -50,9 +51,6 @@ extern int8_t ethernetIdleCount;
extern int8_t configLocked;
extern lan_status lanStatus;
static unsigned long lastctrl = 0;
static aJsonObject *lastobj = NULL;
int retrieveCode(char **psubItem);
int txt2cmd(char *payload) {
@@ -94,6 +92,7 @@ int subitem2cmd(char *payload) {
// Check for command
if (payload)
{
if (strcmp_P(payload, ON_P) == 0) cmd = CMD_ON;
else if (strcmp_P(payload, OFF_P) == 0) cmd = CMD_OFF;
//else if (strcmp_P(payload, REST_P) == 0) cmd = CMD_RESTORE;
@@ -109,7 +108,7 @@ int subitem2cmd(char *payload) {
//else if (strcmp_P(payload, HIGH_P) == 0) cmd = CMD_HIGH;
//else if (strcmp_P(payload, MED_P) == 0) cmd = CMD_MED;
//else if (strcmp_P(payload, LOW_P) == 0) cmd = CMD_LOW;
}
return cmd;
}
@@ -256,6 +255,7 @@ short Item::getFlag (short flag)
{
return itemCmd->valueint & flag & FLAG_MASK;
}
return 0;
}
void Item::setFlag (short flag)
@@ -493,7 +493,7 @@ debugSerial<<F("Txt2Cmd:")<<cmd<<endl;
return Ctrl(cmd, 0, NULL, send, suffixCode, subItem);
} //ctrl
//}
return 0;
}
/*
@@ -612,7 +612,7 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send, int suffixCode
case CMD_DN:
case CMD_UP:
{
if (itemType == CH_GROUP) break;
if (itemType == CH_GROUP) break; ////bug here
if (!n || !Par[0]) Par[0] = DEFAULT_INC_STEP;
if (cmd == CMD_DN) Par[0]=-Par[0];
st.aslong = getVal();
@@ -1001,13 +1001,19 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send, int suffixCode
int rgbSaturation =map(Par[1], 0, 100, 0, 255);
int rgbValue = map(Par[2], 0, 100, 0, 255);
// int rgbValue = map(Par[2], 0, 100, 0, 255);
//Vebler-Heffler law
// float x = Par[2]/25.-3.;
// int rgbValue = round(exp(x)/(exp(1)/255));
int rgbValue = getBright(Par[1]);
switch (itemType) {
#ifdef _dmxout
case CH_DIMMER: //Dimmed light
if (iaddr>0)
DmxWrite(iaddr, map(Par[0], 0, 100, 0, 255));
// DmxWrite(iaddr, map(Par[0], 0, 100, 0, 255));
DmxWrite(iaddr, getBright(Par[0]));
break;
case CH_RGBW: //Colour RGBW
// Saturation 0 - Only white
@@ -1016,9 +1022,9 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send, int suffixCode
{
// int k;
if (Par[1]<50 && iaddr>0) { // Using white
DmxWrite(iaddr + 3, map((50 - Par[1]) * Par[2], 0, 5000, 0, 255));
DmxWrite(iaddr + 3, getBright255(map((50 - Par[1]) * Par[2], 0, 5000, 0, 255)));
int rgbvLevel = map (Par[1],0,50,0,255*2);
rgbValue = map(Par[2], 0, 100, 0, rgbvLevel);
rgbValue = map(getBright(Par[2]), 0, 255, 0, rgbvLevel);
rgbSaturation = map(Par[1], 0, 50, 255, 100);
if (rgbValue>255) rgbValue = 255;
}
@@ -1054,7 +1060,8 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send, int suffixCode
DmxWrite(iaddr, 0);
DmxWrite(iaddr + 1, 0);
DmxWrite(iaddr + 2, 0);
DmxWrite(iaddr + 3, map(Par[2], 0, 100, 0, 255));
// DmxWrite(iaddr + 3, map(Par[2], 0, 100, 0, 255));
DmxWrite(iaddr + 3,rgbValue);
break;
}
#endif
@@ -1154,6 +1161,7 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send, int suffixCode
}
#endif
}
return 1;
}
int Item::isActive() {
@@ -1706,13 +1714,16 @@ int Item::checkModbusDimmer(int data) {
} //if data changed
}
int Item::Poll(short cause) {
#endif
int Item::Poll(int cause) {
switch (cause)
{
case POLLING_SLOW:
// Legacy polling
switch (itemType) {
#ifndef MODBUS_DISABLE
case CH_MODBUS:
checkModbusDimmer();
sendDelayedStatus();
@@ -1728,6 +1739,7 @@ switch (cause)
sendDelayedStatus();
return INTERVAL_CHECK_MODBUS;
break;
#endif
/* case CH_RGB: //All channels with slider generate too many updates
case CH_RGBW:
case CH_DIMMER:
@@ -1758,7 +1770,7 @@ void Item::sendDelayedStatus()
}
}
#endif
int Item::SendStatus(int sendFlags) {
int chancmd=getCmd();
if ((sendFlags & SEND_DEFFERED) || (lanStatus==RETAINING_COLLECTING)) {

View File

@@ -1,4 +1,4 @@
/* Copyright © 2017-2018 Andrey Klimov. All rights reserved.
/* Copyright © 2017-2020 Andrey Klimov. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -36,15 +36,7 @@ e-mail anklimov@gmail.com
#define S_HUE 7
#define S_SAT 8
#define S_ADDITIONAL 64
/*
#define S_RPM 11
#define S_TEMP 3
#define S_SETPOINT 5
#define S_POWER 6
#define S_VOL 7
#define S_HEAT 8
*/
#define CH_DIMMER 0 //DMX 1 ch
#define CH_RGBW 1 //DMX 4 ch
#define CH_RGB 2 //DMX 3 ch
@@ -99,6 +91,7 @@ e-mail anklimov@gmail.com
#define SEND_RETRY 0x400
#define SEND_DEFFERED 0x800
#define ACTION_NEEDED 0x1000
#define ACTION_IN_PROCESS 0x2000
//#define CMD_REPORT 32
@@ -183,16 +176,15 @@ class Item
short getFlag (short flag=FLAG_MASK);
void setFlag (short flag);
void clearFlag (short flag);
//void setVal(uint8_t n, int par);
void setVal(long int par);
//void copyPar (aJsonObject *itemV);
inline int On (){return Ctrl(CMD_ON);};
inline int Off(){return Ctrl(CMD_OFF);};
inline int Toggle(){return Ctrl(CMD_TOGGLE);};
int Poll(short cause);
int Poll(int cause);
int SendStatus(int sendFlags);
int isActive();
int getChanType();
inline int On (){return Ctrl(CMD_ON);};
inline int Off(){return Ctrl(CMD_OFF);};
inline int Toggle(){return Ctrl(CMD_TOGGLE);};
protected:
//short cmd2changeActivity(int lastActivity, short defaultCmd = CMD_SET);
int VacomSetFan (int8_t val, int8_t cmd=0);

View File

@@ -1817,7 +1817,7 @@ configLocked++;
while (input) {
if ((input->type == aJson_Object)) {
Input in(input);
in.poll(CHECK_INPUT);
in.Poll(CHECK_INPUT);
}
input = input->next;
}
@@ -1829,7 +1829,7 @@ configLocked++;
while (input) {
if ((input->type == aJson_Object)) {
Input in(input);
in.poll(CHECK_SENSOR);
in.Poll(CHECK_SENSOR);
}
input = input->next;
}
@@ -1862,7 +1862,7 @@ if (items) {
if (item->type == aJson_Array && aJson.getArraySize(item)>1) {
Item it(item);
if (it.isValid()) {
it.Poll(POLLING_FAST);
it.Poll(POLLING_FAST);
} //isValid
item = item->next;
} //if

View File

@@ -21,6 +21,7 @@
#if defined(ARDUINO_ARCH_ESP8266)
#include <FS.h> //this needs to be first, or it all crashes and burns...
//#include "SPIFFS.h"
#include <ESP_EEPROM.h>
#include <ESP8266HTTPClient.h>
//#include <ArduinoHttpClient.h>
@@ -35,6 +36,7 @@
#if defined ARDUINO_ARCH_ESP32
#include <FS.h> //this needs to be first, or it all crashes and burns...
//#include "SPIFFS.h"
//#include <EEPROM.h>
#include <NRFFlashStorage.h>
//#include "HttpClient.h"