This commit is contained in:
Dmitry Borisenko
2020-09-02 22:33:03 +03:00
parent 26383c0a19
commit 70096c71c8
288 changed files with 0 additions and 29977 deletions

View File

@@ -1,56 +0,0 @@
#pragma once
#include <Arduino.h>
class BusScanner {
public:
BusScanner(const char* tag, String& out, size_t tries) : _found{0},
_tries{tries},
_out{&out} {
_tag = new char(strlen(tag) + 1);
strcpy(_tag, tag);
}
void scan() {
init();
bool res;
do {
res = syncScan();
} while (!res && --_tries);
if (!_found) {
addResult("не найдено");
}
}
const char* tag() {
return _tag;
}
protected:
virtual void init(){};
virtual boolean syncScan() = 0;
protected:
void addResult(const String& str) {
_out->concat(str);
}
void addResult(uint8_t addr, boolean last = true) {
_found++;
String str = "0x";
if (addr < 16) {
str += "0";
}
str += String(addr, HEX);
str += !last ? ", " : ", ";
addResult(str);
};
private:
char* _tag;
size_t _found;
size_t _tries;
String* _out;
};

View File

@@ -1,18 +0,0 @@
#pragma once
#include "Bus/BusScanner.h"
#include "Bus/I2CScanner.h"
#include "Consts.h"
#include "Utils/JsonUtils.h"
class BusScannerFactory {
public:
static BusScanner* get(String& config, BusScanner_t type, String& str) {
switch (type) {
case BS_I2C:
return new I2CScanner(str);
default:
return nullptr;
}
}
};

View File

@@ -1,12 +0,0 @@
#pragma once
#include "Bus/BusScanner.h"
class I2CScanner : public BusScanner {
public:
I2CScanner(String& out);
protected:
virtual void init() override;
virtual boolean syncScan() override;
};

View File

@@ -1,26 +0,0 @@
#pragma once
#include <Arduino.h>
#include <stdint.h>
#include <functional>
// Декларируем тип - сигнатуру метода , который мы готовы принять в данном случае это
// должен быть метод без результата и без параметров.
// Новый тип мы называем AsynсActionCb - хотя можешь назвать вообще как нравиться а что значит callBack
typedef std::function<void()> AsyncActionCb; //метод без результата и параметров
typedef std::function<bool(const String)> AsyncParamActionCb; //метод без результата и параметров
class CallBackTest {
private:
long count;
AsyncActionCb _cb;
AsyncParamActionCb _pcb;
public:
CallBackTest();
void loop();
void setCallback(AsyncActionCb cb);
void setCallback(AsyncParamActionCb pcb);
};
//extern CallBackTest* CB;

View File

@@ -1,33 +0,0 @@
#pragma once
#include <Arduino.h>
#include "Class/LineParsing.h"
#include "Global.h"
class Input : public LineParsing {
public:
Input() : LineParsing(){};
void inputSetDefaultFloat() {
inputSetFloat(_key, _state);
}
void inputSetDefaultStr() {
inputSetStr(_key, _state);
}
void inputSetFloat(String key, String state) {
eventGen(key, "");
jsonWriteFloat(configLiveJson, key, state.toFloat());
MqttClient::publishStatus(key, state);
}
void inputSetStr(String key, String state) {
eventGen(key, "");
jsonWriteStr(configLiveJson, key, state);
MqttClient::publishStatus(key, state);
}
};
extern Input* myInput;

View File

@@ -1,177 +0,0 @@
#pragma once
#include <Arduino.h>
#include "Global.h"
#include "Utils/JsonUtils.h"
class LineParsing {
protected:
String _key;
String _file;
String _page;
String _descr;
String _order;
String _addr;
String _pin;
String _map;
String _c;
String _inv;
String _state;
String _db;
public:
LineParsing() :
_key{""},
_file{""},
_page{""},
_descr{""},
_order{""},
_addr{""},
_pin{""},
_map{""},
_c{""},
_inv{""},
_state{""},
_db{""}
{};
void update() {
//String order = sCmd.order();
//pm.info("create '" + order + "'");
for (int i = 1; i < 12; i++) {
if (i == 1) _key = sCmd.next();
if (i == 2) _file = sCmd.next();
if (i == 3) _page = sCmd.next();
if (i == 4) _descr = sCmd.next();
if (i == 5) _order = sCmd.next();
}
for (int i = 1; i < 10; i++) {
String arg = sCmd.next();
if (arg != "") {
if (arg.indexOf("pin[") != -1) {
_pin = extractInner(arg);
}
if (arg.indexOf("inv[") != -1) {
_inv = extractInner(arg);
}
if (arg.indexOf("st[") != -1) {
_state = extractInner(arg);
}
if (arg.indexOf("db[") != -1) {
_db = extractInner(arg);
}
if (arg.indexOf("map[") != -1) {
_map = extractInner(arg);
}
if (arg.indexOf("c[") != -1) {
_c = extractInner(arg);
}
}
}
_page.replace("#", " ");
_descr.replace("#", " ");
createWidgetClass(_descr, _page, _order, _file, _key);
}
//jsonWriteStr(configOptionJson, _key + "_pin", _pin);
String gkey() {
return _key;
}
String gfile() {
return _file;
}
String gpage() {
return _page;
}
String gdescr() {
return _descr;
}
String gorder() {
return _order;
}
String gpin() {
return _pin; //
}
String ginv() {
return _inv; //
}
String gstate() {
return _state;
}
String gmap() {
return _map;
}
String gc() {
return _c;
}
void clear() {
_key = "";
_file = "";
_page = "";
_descr = "";
_order = "";
_addr = "";
_pin = "";
_map = "";
_c = "";
_inv = "";
_state = "";
_db = "";
}
String extractInnerDigit(String str) {
int p1 = str.indexOf("[");
int p2 = str.indexOf("]");
return str.substring(p1 + 1, p2);
}
void createWidgetClass(String descr, String page, String order, String filename, String topic) {
String buf = "{}";
if (!loadWidgetClass(filename, buf)) {
return;
}
jsonWriteStr(buf, "page", page);
jsonWriteStr(buf, "order", order);
jsonWriteStr(buf, "descr", descr);
jsonWriteStr(buf, "topic", prex + "/" + topic);
#ifdef LAYOUT_IN_RAM
all_widgets += widget + "\r\n";
#else
addFileLn("layout.txt", buf);
#endif
}
bool loadWidgetClass(const String& filename, String& buf) {
buf = readFile(getWidgetFileClass(filename), 2048);
bool res = !(buf == "Failed" || buf == "Large");
if (!res) {
//pm.error("on load" + filename);
}
return res;
}
const String getWidgetFileClass(const String& name) {
return "/widgets/" + name + ".json";
}
//String jsonWriteStr1(String& json, String name, String value) {
// DynamicJsonBuffer jsonBuffer;
// JsonObject& root = jsonBuffer.parseObject(json);
// root[name] = value;
// json = "";
// root.printTo(json);
// return json;
//}
};

View File

@@ -1,31 +0,0 @@
#pragma once
#include <Arduino.h>
#include <stdint.h>
#include <functional>
typedef std::function<void(void*)> NotAsincCb;
struct NotAsincItem {
bool test;
NotAsincCb cb;
void * cb_arg;
volatile bool is_used = false;
};
class NotAsinc {
private:
uint8_t size;
uint8_t task = 0;
NotAsincItem* items = NULL;
void handle(NotAsincCb f, void* arg);
public:
NotAsinc(uint8_t size);
~NotAsinc();
void add(uint8_t i, NotAsincCb, void* arg);
void make(uint8_t task);
void loop();
};
extern NotAsinc* myNotAsincActions;

View File

@@ -1,24 +0,0 @@
#pragma once
#include <Arduino.h>
#include "Class/LineParsing.h"
#include "Global.h"
class OutputModule : public LineParsing {
public:
OutputModule() : LineParsing(){};
void OutputModuleStateSetDefault() {
if (_state != "") {
OutputModuleChange(_key, _state);
}
}
void OutputModuleChange(String key, String state) {
state.replace("#", " ");
eventGen(key, "");
jsonWriteStr(configLiveJson, key, state);
MqttClient::publishStatus(key, state);
}
};
extern OutputModule* myText;

View File

@@ -1,33 +0,0 @@
#pragma once
#include <Arduino.h>
#include "Class/LineParsing.h"
#include "Global.h"
class Pwm : public LineParsing {
public:
Pwm() : LineParsing(){};
void pwmModeSet() {
if (_pin != "") {
pinMode(_pin.toInt(), INPUT);
}
}
void pwmStateSetDefault() {
if (_state != "") {
pwmChange(_key, _pin, _state);
}
}
void pwmChange(String key, String pin, String state) {
int pinInt = pin.toInt();
analogWrite(pinInt, state.toInt());
eventGen(key, "");
jsonWriteInt(configLiveJson, key, state.toInt());
MqttClient::publishStatus(key, state);
}
};
extern Pwm* myPwm;

View File

@@ -1,113 +0,0 @@
#pragma once
#include <Arduino.h>
#include "Cmd.h"
#include "Global.h"
class Scenario {
protected:
String _scenarioTmp;
String _condition;
String _conditionParam;
String _conditionSign;
String _conditionValue;
String _scenBlok;
String _event;
String _eventParam;
String _eventValue;
public:
Scenario() : _scenarioTmp{""},
_condition{""},
_conditionParam{""},
_conditionSign{""},
_conditionValue{""},
_scenBlok{""},
_event{""},
_eventParam{""},
_eventValue{""} {};
void load() {
_scenarioTmp = scenario;
}
void calculate1() {
_scenBlok = selectToMarker(_scenarioTmp, "end\n");
_condition = selectToMarker(_scenBlok, "\n");
_eventParam = selectToMarker(eventBuf, ",");
}
bool isIncommingEventInScenario() {
bool ret = false;
if (_condition.indexOf(_eventParam) != -1) {
ret = true;
}
return ret;
}
void calculate2() {
_scenarioTmp += "\n";
_scenarioTmp.replace("\r\n", "\n");
_scenarioTmp.replace("\r", "\n");
_conditionParam = selectFromMarkerToMarker(_condition, " ", 0);
_conditionSign = selectFromMarkerToMarker(_condition, " ", 1);
_conditionValue = selectFromMarkerToMarker(_condition, " ", 2);
if (!isDigitStr(_conditionValue)) _conditionValue = jsonReadStr(configLiveJson, _conditionValue);
_eventValue = jsonReadStr(configLiveJson, _conditionParam);
}
void delOneScenBlock() {
_scenarioTmp = deleteBeforeDelimiter(_scenarioTmp, "end\n");
}
void delOneEvent() {
eventBuf = deleteBeforeDelimiter(eventBuf, ",");
}
bool isConditionSatisfied() {
boolean flag = false;
if (_conditionSign == "=") {
flag = _eventValue == _conditionValue;
} else if (_conditionSign == "!=") {
flag = _eventValue != _conditionValue;
} else if (_conditionSign == "<") {
flag = _eventValue.toInt() < _conditionValue.toInt();
} else if (_conditionSign == ">") {
flag = _eventValue.toInt() > _conditionValue.toInt();
} else if (_conditionSign == ">=") {
flag = _eventValue.toInt() >= _conditionValue.toInt();
} else if (_conditionSign == "<=") {
flag = _eventValue.toInt() <= _conditionValue.toInt();
}
if (flag) Serial.println("[I] Scenario event: " + _condition);
return flag;
}
void loop() {
if (!this->isScenarioEnabled()) {
return;
}
this->load(); //после этого мы получили все сценарии
while (_scenarioTmp.length() > 1) {
this->calculate1(); //расчет необходимый для ответа на следующий вопрос
if (this->isIncommingEventInScenario()) { //если вошедшее событие есть в сценарии
this->calculate2();
if (this->isConditionSatisfied()) { //если вошедшее событие выполняет условие сценария
_scenBlok = deleteBeforeDelimiter(_scenBlok, "\n");
//Serial.println(" [>] Making: " + _scenBlok);
spaceExecute(_scenBlok);
}
}
this->delOneScenBlock(); //удалим использованный блок
}
this->delOneEvent();
}
bool isScenarioEnabled() {
return jsonReadBool(configSetupJson, "scen") && eventBuf != "";
}
};
extern Scenario* myScenario;

View File

@@ -1,35 +0,0 @@
#pragma once
#include <Arduino.h>
#include "Class/LineParsing.h"
#include "Class/SensorConverting.h"
#include "Global.h"
class SensorAnalog : public SensorConverting {
public:
SensorAnalog() : SensorConverting(){};
void SensorAnalogInit(String key) {
}
int SensorAnalogRead(String key, String pin) {
int pinInt = pin.toInt();
int value;
#ifdef ESP32
value = analogRead(pinInt);
#endif
#ifdef ESP8266
pinInt = pinInt;
value = analogRead(A0);
#endif
value = this->mapping(key, value);
float valueFl = this->correction(key, value);
eventGen(key, "");
jsonWriteStr(configLiveJson, key, String(valueFl));
MqttClient::publishStatus(key, String(valueFl));
Serial.println("[I] sensor '" + key + "' data: " + String(valueFl));
return value;
}
};
extern SensorAnalog* mySensorAnalog;

View File

@@ -1,32 +0,0 @@
#pragma once
#include <Arduino.h>
#include "Class/LineParsing.h"
#include "Global.h"
class SensorConverting : public LineParsing {
public:
SensorConverting() : LineParsing(){};
int mapping(String key, int input) {
String map_ = jsonReadStr(configOptionJson, key + "_map");
if (map_ != "") {
input = map(input,
selectFromMarkerToMarker(map_, ",", 0).toInt(),
selectFromMarkerToMarker(map_, ",", 1).toInt(),
selectFromMarkerToMarker(map_, ",", 2).toInt(),
selectFromMarkerToMarker(map_, ",", 3).toInt());
}
return input;
}
float correction(String key, float input) {
String corr = jsonReadStr(configOptionJson, key + "_с");
if (corr != "") {
float coef = corr.toFloat();
input = input * coef;
}
return input;
}
};

View File

@@ -1,56 +0,0 @@
#pragma once
#include <Arduino.h>
#include "Class/LineParsing.h"
#include "Global.h"
class Switch : public LineParsing {
protected:
int numberEntering = 0;
int state = _state.toInt();
public:
Switch() : LineParsing(){};
void init() {
if (_pin != "") {
int number = numberEntering++;
buttons[number].attach(_pin.toInt());
buttons[number].interval(_db.toInt());
but[number] = true;
jsonWriteStr(configOptionJson, "switch_num_" + String(number), _key);
}
}
void loop() {
static uint8_t switch_number = 1;
if (but[switch_number]) {
buttons[switch_number].update();
if (buttons[switch_number].fell()) {
}
if (buttons[switch_number].rose()) {
String key = jsonReadStr(configOptionJson, "switch_num_" + String(switch_number));
state = !state;
switchChangeVirtual(key, String(state));
}
}
switch_number++;
if (switch_number == NUM_BUTTONS) {
switch_number = 0;
}
}
void switchStateSetDefault() {
if (_state != "") {
switchChangeVirtual(_key, _state);
}
}
void switchChangeVirtual(String key, String state) {
eventGen(key, "");
jsonWriteInt(configLiveJson, key, state.toInt());
MqttClient::publishStatus(key, state);
}
};
extern Switch* mySwitch;

View File

@@ -1,43 +0,0 @@
#pragma once
#include <Arduino.h>
#include "Class/LineParsing.h"
#include "Global.h"
class Button1 : public LineParsing {
public:
Button1() : LineParsing(){};
void pinModeSet() {
if (_pin != "") {
pinMode(_pin.toInt(), OUTPUT);
}
}
void pinStateSetDefault() {
if (_inv == "" && _state != "") {
pinChange(_key, _pin, _state, true);
}
}
void pinStateSetInvDefault() {
if (_inv != "" && _state != "") {
pinChange(_key, _pin, _state, false);
}
}
void pinChange(String key, String pin, String state, bool rev) {
int pinInt = pin.toInt();
int stateInt;
if (rev) {
digitalWrite(pinInt, state.toInt());
} else {
digitalWrite(pinInt, !state.toInt());
}
eventGen(key, "");
jsonWriteInt(configLiveJson, key, state.toInt());
MqttClient::publishStatus(key, state);
}
};
extern Button1* myButton;

View File

@@ -1,167 +0,0 @@
#pragma once
#include "Utils/TimeUtils.h"
#include "Utils/PrintMessage.h"
#include "Global.h"
#include "Clock.h"
#ifdef ESP8266
#include "sntp.h"
#endif
class Clock {
const char* MODULE = "Clock";
private:
Time_t _time_local;
Time_t _time_utc;
unsigned long _uptime;
unsigned long _unixtime;
int _timezone;
String _ntp;
bool _hasSynced;
bool _configured;
public:
Clock() : _uptime{0}, _timezone{0}, _ntp{""}, _hasSynced{false}, _configured{false} {};
void loop() {
unsigned long passed = millis_since(_uptime);
if (passed < ONE_SECOND_ms) {
return;
}
_uptime += passed;
// world time
time_t now = getSystemTime();
time_t estimated = _unixtime + (passed / ONE_SECOND_ms);
double drift = difftime(now, estimated);
if (drift > 1) {
// Обработать ситуации c дрифтом времени на значительные величины
}
// TODO сохранять время на флеше
_unixtime = now;
breakEpochToTime(_unixtime, _time_utc);
breakEpochToTime(_unixtime + getOffsetInSeconds(_timezone), _time_local);
}
bool hasSync() {
if (!_hasSynced) {
startSync();
}
return _hasSynced;
}
void setNtpPool(String ntp) {
if (!_ntp.equals(ntp)) {
_ntp = ntp;
_configured = false;
}
}
void setTimezone(int timezone) {
if (_timezone != timezone) {
_timezone = timezone;
_configured = false;
}
}
void startSync() {
if (!_configured) {
//pm.info("sync to: " + _ntp + " timezone: " + String(_timezone));
setupSntp();
_configured = true;
// лучше не ждать, проверим в следующий раз
return;
}
_hasSynced = hasTimeSynced();
if (_hasSynced) {
//pm.info("synced " + getDateDotFormated() + " " + getTime());
} else {
//pm.error("failed to obtain");
}
}
void setupSntp() {
#ifdef ESP2866
sntp_setservername(0, _ntp.c_str());
sntp_setservername(1, "ru.pool.ntp.org");
sntp_setservername(2, "pool.ntp.org");
sntp_stop();
sntp_set_timezone(0); // UTC time
sntp_init();
#else
configTime(0, 0, _ntp.c_str(), "ru.pool.ntp.org", "pool.ntp.org");
#endif
}
bool hasTimeSynced() const {
return _unixtime > MIN_DATETIME;
}
time_t getSystemTime() const {
timeval tv{0, 0};
timezone tz = timezone{0, 0};
time_t epoch = 0;
if (gettimeofday(&tv, &tz) != -1) {
epoch = tv.tv_sec;
}
return epoch;
}
const String getTimeUnix() {
return String(_unixtime);
}
/*
* Локальное время "дд.ММ.гг"
*/
const String getDateDotFormated() {
char buf[32];
sprintf(buf, "%02d.%02d.%02d", _time_local.day_of_month, _time_local.month, _time_local.year);
return String(buf);
}
/*
* Локальное дата время "дд.ММ.гг чч.мм.cc"
*/
const String getDateTimeDotFormated() {
char buf[32];
sprintf(buf, "%02d.%02d.%02d %02d:%02d:%02d", _time_local.day_of_month, _time_local.month, _time_local.year, _time_local.hour, _time_local.minute, _time_local.second);
return String(buf);
}
/*
* Локальное время "чч:мм:cc"
*/
const String getTime() {
char buf[32];
sprintf(buf, "%02d:%02d:%02d", _time_local.hour, _time_local.minute, _time_local.second);
return String(buf);
}
const String getTimeJson() {
char buf[32];
sprintf(buf, "%02d-%02d-%02d", _time_local.hour, _time_local.minute, _time_local.second);
return String(buf);
}
/*
* Локальное время "чч:мм"
*/
const String getTimeWOsec() {
char buf[32];
sprintf(buf, "%02d:%02d", _time_local.hour, _time_local.minute);
return String(buf);
}
/*
* Время с момента запуска "чч:мм:cc" далее "дд чч:мм"
*/
const String getUptime() {
return prettyMillis(_uptime);
}
};

View File

@@ -1,98 +0,0 @@
#pragma once
#include <Arduino.h>
extern void cmd_init();
extern void buttonOut();
extern void buttonOutSet();
extern void pwmOut();
extern void pwmOutSet();
extern void buttonIn();
extern void buttonInSet();
extern void inputDigit();
extern void inputDigitSet();
extern void inputTime();
extern void inputTimeSet();
extern void textOut();
extern void textOutSet();
extern void analogAdc();
extern void analogReading();
extern void ultrasonicCm();
extern void ultrasonicReading();
extern void sensorsInit();
extern void levelPr();
extern void ultrasonicCm();
extern void ultrasonic_reading();
extern void analog_reading1();
extern void analog_reading2();
extern void dallas_reading();
extern void dhtT_reading();
extern void dallas();
extern void bmp280T();
extern void bmp280P();
extern void bmp280T_reading();
extern void bmp280P_reading();
extern void bme280T();
extern void bme280P();
extern void bme280H();
extern void bme280A();
extern void bme280T_reading();
extern void bme280P_reading();
extern void bme280H_reading();
extern void bme280A_reading();
extern void dhtT();
extern void dhtH();
extern void dhtP();
extern void dhtC();
extern void dhtD();
extern void dhtH_reading();
extern void dhtP_reading();
extern void dhtC_reading();
extern void dhtD_reading();
extern void handle_time_init();
extern void stepper();
extern void stepperSet();
extern void servo_();
extern void servoSet();
extern void serialBegin();
extern void serialWrite();
extern void logging();
extern void button();
extern void timeSet();
extern void mqttOrderSend();
extern void httpOrderSend();
extern void firmwareVersion();
extern void firmwareUpdate();
extern void loadScenario();
extern void fileExecute(const String& filename);
extern void csvExecute(String& cmdStr);
extern void spaceExecute(String& cmdStr);

View File

@@ -1,138 +0,0 @@
#pragma once
/*
* Main consts
*/
#define FIRMWARE_VERSION "2.4.0"
#define NUM_BUTTONS 6
#define LED_PIN 2
#define FLASH_4MB true
#define MQTT_RECONNECT_INTERVAL 20000
#define TELEMETRY_UPDATE_INTERVAL 7200000
#define DEVICE_CONFIG_FILE "s.conf.csv"
#define DEVICE_SCENARIO_FILE "s.scen.txt"
#define DEFAULT_PRESET 100
#define DEFAULT_SCENARIO 100
#define TAG_ONE_WIRE "oneWire"
#define TAG_I2C "i2c"
#define TAG_ONE_WIRE_PIN "oneWirePin"
/*
* Optional
*/
//#define OTA_UPDATES_ENABLED
//#define MDNS_ENABLED
//#define WEBSOCKET_ENABLED
//#define LAYOUT_IN_RAM
//#define UDP_ENABLED
/*
* Sensor
*/
#define TANK_LEVEL_SAMPLES 10
#define LEVEL_ENABLED
#define ANALOG_ENABLED
#define DALLAS_ENABLED
#define DHT_ENABLED
#define BMP_ENABLED
#define BME_ENABLED
#define FSEditor
//#define SSDP
/*
* Gears
*/
#define STEPPER_ENABLED
//#define SERVO_ENABLED
/*
* Other
*/
#define LOGGING_ENABLED
#define SERIAL_ENABLED
#define PUSH_ENABLED
struct Time_t {
uint8_t second;
uint8_t minute;
uint8_t hour;
uint8_t day_of_week;
uint8_t day_of_month;
uint8_t month;
uint16_t day_of_year;
uint16_t year;
unsigned long days;
unsigned long valid;
};
enum TimerTask_t { WIFI_SCAN,
WIFI_MQTT_CONNECTION_CHECK,
SENSORS,
STEPPER1,
STEPPER2,
LOG1,
LOG2,
LOG3,
LOG4,
LOG5,
TIMER_COUNTDOWN,
TIME,
TIME_SYNC,
STATISTICS,
UPTIME,
UDP,
UDP_DB,
TEST };
enum notAsincActions {
do_ZERO,
do_UPGRADE,
do_GETLASTVERSION,
do_UDPDATAPARSE,
do_MQTTUDP,
do_BUSSCAN,
do_MQTTPARAMSCHANGED,
do_LAST,
};
enum ErrorType_t {
ET_NONE,
ET_FUNCTION,
ET_MODULE,
ET_SYSTEM
};
enum ErrorLevel_t {
EL_NONE,
EL_INFO,
EL_WARNING,
EL_ERROR
};
enum LedStatus_t {
LED_OFF,
LED_ON,
LED_SLOW,
LED_FAST
};
enum ConfigType_t {
CT_CONFIG,
CT_SCENARIO
};
enum BusScanner_t {
BS_I2C,
BS_ONE_WIRE
};

View File

@@ -1,26 +0,0 @@
#pragma once
#ifdef ESP32
// don't change order
#include "WiFi.h"
//
#include "ESPAsyncWebServer.h"
#include "SPIFFSEditor.h"
// don't change order
#include <AsyncUDP.h>
#include <ESP32Servo.h>
#include <HTTPClient.h>
#include <HTTPUpdate.h>
//
#include <WiFi.h>
#include <analogWrite.h>
#ifdef MDNS_ENABLED
#include <ESPmDNS.h>
#endif
extern AsyncUDP udp;
#endif

View File

@@ -1,19 +0,0 @@
#pragma once
#ifdef ESP8266
#include <ESP8266WebServer.h>
#include <ESP8266httpUpdate.h>
#include "ESPAsyncTCP.h"
#include "ESPAsyncWebServer.h"
#include <LittleFS.h>
#include <SPIFFSEditor.h>
#include <Servo.h>
#include <WiFiUdp.h>
#include <SoftwareSerial.h>
#ifdef MDNS_ENABLED
#include <ESP8266mDNS.h>
#endif
extern WiFiUDP udp;
#endif

View File

@@ -1,52 +0,0 @@
#pragma once
#include <Arduino.h>
String getErrorLevelStr(ErrorLevel_t level);
class Error : public Printable {
public:
static Error OK() {
return Error();
}
static Error InfoMessage(const char *message) {
return Error(EL_INFO, message);
}
static Error ErrorMessage(const char *message) {
return Error(EL_ERROR, message);
}
public:
Error() : _type{ET_NONE}, _level{EL_NONE} {};
Error(const ErrorLevel_t level, const char *message) : Error(ET_FUNCTION, level, message){};
Error(const ErrorType_t type, const ErrorLevel_t level, const char *message) : _type{type}, _level{level} {
strncpy(_message, message, sizeof(_message));
};
const ErrorLevel_t level() const { return _level; }
const ErrorType_t type() const { return _type; }
const char *message() const { return _message; }
operator bool() const { return _level != EL_NONE; }
const String toString() const {
char buf[128];
sprintf(buf, "[%s] %s", getErrorLevelStr(_level).c_str(), _message);
return String(buf);
}
virtual size_t printTo(Print &p) const {
return p.println(toString().c_str());
}
private:
char _message[128];
ErrorType_t _type;
ErrorLevel_t _level;
};

View File

@@ -1,28 +0,0 @@
#pragma once
#include <ESPAsyncWebServer.h>
#include <FS.h>
#ifdef ESP8266
#include <LittleFS.h>
#endif
class FSEditor : public AsyncWebHandler {
private:
fs::FS _fs;
String _username;
String _password;
bool _authenticated;
uint32_t _startTime;
public:
#ifdef ESP32
FSEditor(const fs::FS& fs, const String& username = String(), const String& password = String());
#else
FSEditor(const String& username = String(), const String& password = String(), const fs::FS& fs = LittleFS);
#endif
virtual bool canHandle(AsyncWebServerRequest* request) override final;
virtual void handleRequest(AsyncWebServerRequest* request) override final;
virtual void handleUpload(AsyncWebServerRequest* request, const String& filename, size_t index, uint8_t* data, size_t len, bool final) override final;
virtual bool isRequestHandlerTrivial() override final { return false; }
};

View File

@@ -1,221 +0,0 @@
#pragma once
/*
* Libraries
*/
#include <Arduino.h>
#include <ArduinoJson.h>
#include "ESP32.h"
#include "ESP8266.h"
//
#include "Consts.h"
#include "Errors.h"
#include "GyverFilters.h"
#include "Upgrade.h"
#include "Clock.h"
#include "MqttClient.h"
#include "Utils\FileUtils.h"
#include "Utils\JsonUtils.h"
#include "Utils\StringUtils.h"
#include "Utils\SysUtils.h"
#include "Utils\PrintMessage.h"
#include "Utils\WiFiUtils.h"
//=========ПОДКЛЮЧЕНИЕ ОБЩИХ БИБЛИОТЕК===============
#include <Adafruit_BME280.h>
#include <Adafruit_BMP280.h>
#include <Bounce2.h>
#include <DHTesp.h>
#include <DallasTemperature.h>
#include <OneWire.h>
#include <PubSubClient.h>
#include <StringCommand.h>
#include <TickerScheduler.h>
#include <Wire.h>
#include <time.h>
#include <ArduinoOTA.h>
#ifdef WEBSOCKET_ENABLED
extern AsyncWebSocket ws;
//extern AsyncEventSource events;
#endif
extern Clock* timeNow;
extern TickerScheduler ts;
extern WiFiClient espClient;
extern PubSubClient mqtt;
extern StringCommand sCmd;
extern AsyncWebServer server;
extern DallasTemperature sensors;
extern OneWire *oneWire;
extern boolean but[NUM_BUTTONS];
extern Bounce* buttons;
/*
* Global vars
*/
extern boolean just_load;
// Json
extern String configSetupJson; //все настройки
extern String configLiveJson; //все данные с датчиков (связан с mqtt)
extern String configOptionJson; //для трансфера
// Mqtt
extern String chipId;
extern String prex;
extern String all_widgets;
extern String scenario;
//orders and events
extern String orderBuf;
extern String eventBuf;
extern String itemsFile;
extern String itemsLine;
// Sensors
extern String sensorReadingMap;
extern String analog_value_names_list;
extern int enter_to_analog_counter;
extern String dallas_value_name;
extern int enter_to_dallas_counter;
extern String levelPr_value_name;
extern String ultrasonicCm_value_name;
extern String dhtT_value_name;
extern String dhtH_value_name;
extern String bmp280T_value_name;
extern String bmp280P_value_name;
extern String bme280T_value_name;
extern String bme280P_value_name;
extern String bme280H_value_name;
extern String bme280A_value_name;
extern String logging_value_names_list;
extern int enter_to_logging_counter;
extern int scenario_line_status[40];
extern String lastVersion;
extern boolean checkUpdatesFlag;
extern boolean updateFlag;
extern boolean mqttParamsChanged;
extern boolean udp_data_parse;
extern boolean mqtt_send_settings_to_udp;
extern boolean delElementFlag;
extern boolean getJsonListFromCsvFlag;
extern String csvFile;
extern int colum;
/*
* Запрос на скарнирование шины
*/
extern boolean busScanFlag;
/*
* Запрос на сканирование шины, указание какую
*/
extern BusScanner_t busToScan;
extern boolean fsCheckFlag;
extern int sensors_reading_map[15];
/*
* Global functions
*/
// Logging
extern void logging();
extern void deleteOldDate(String filename, size_t max_lines, String date_to_add);
extern void clean_log_date();
extern void choose_log_date_and_send();
// Main
extern void setChipId();
extern void saveConfig();
extern void setConfigParam(const char* param, const String& value);
extern String getURL(const String& urls);
extern void do_fscheck();
extern void doBusScan();
extern void servo_();
extern void clock_init();
extern void setLedStatus(LedStatus_t);
//Scenario
extern void eventGen(String event_name, String number);
extern String add_set(String param_name);
//Timers
extern void Timer_countdown_init();
extern void timerStart_();
extern void addTimer(String number, String time);
extern void timerStop_();
extern void delTimer(String number);
extern int readTimer(int number);
extern void upgradeInit();
// widget
extern void createWidgetByType(String widget_name, String page_name, String page_number, String file, String topic);
extern void createWidgetParam(String widget_name, String page_name, String page_number, String file, String topic, String name1, String param1, String name2, String param2, String name3, String param3);
extern void createWidget(String widget_name, String page_name, String page_number, String type, String topik);
extern void createChart(String widget_name, String page_name, String page_number, String file, String topic, String maxCount);
// PushingBox
extern void pushControl();
// UDP
extern void udpInit();
extern void do_udp_data_parse();
extern void do_mqtt_send_settings_to_udp();
extern void addCommandLoop(const String& cmdStr);
extern void loopSerial();
extern void loopCmd();
extern void loopScenario();
extern void loopUdp();
extern void do_update();
// Init
extern void uptime_init();
// Web
extern void web_init();
extern void telemetry_init();

View File

@@ -1,9 +0,0 @@
#pragma once
#include "Global.h"
namespace HttpServer {
void init();
} // namespace HttpServer

View File

@@ -1,11 +0,0 @@
#pragma once
extern void loadConfig();
extern void all_init();
extern void statistics_init();
extern void loadScenario();
extern void Device_init();
extern void prsets_init();
extern void handle_uptime();
extern void handle_statistics();
extern void telemetry_init();

View File

@@ -1,10 +0,0 @@
#pragma once
#include <Arduino.h>
#include "Global.h"
extern void addItem(String name);
extern void delAllItems();
extern uint8_t getNewElementNumber(String file);
extern uint8_t getFreePinAll();
extern uint8_t getFreePinAnalog();

View File

@@ -1,72 +0,0 @@
#pragma once
#include <Arduino.h>
class CharBuffer : Print {
public:
CharBuffer(size_t size) : _capacity(size < 2 ? 2 : size), _write(0), _read(0) {
_pool = new char[_capacity + 1];
memset(_pool, 0, _capacity + 1);
}
CharBuffer(const CharBuffer &src) {
_capacity = src._capacity;
_write = src._write;
memcpy(_pool, src._pool, src._write);
}
CharBuffer(const char *str) : CharBuffer(strlen(str) + 1) {
write((const uint8_t *)str, strlen(str));
}
~CharBuffer() {
delete _pool;
}
void clear() {
memset(_pool, 0, _capacity);
_write = 0;
_read = 0;
}
size_t size() const { return _capacity; }
size_t free() const { return _capacity - _write - 2; }
size_t available() const { return _write; }
const char *c_str() {
if (_pool[_write] != '\x00')
_pool[_write] = '\x00';
return _pool;
}
size_t write(char ch) {
return write((uint8_t)ch);
};
size_t write(const uint8_t ch) {
size_t n = 0;
if (_write < (_capacity - 2)) {
_pool[_write++] = ch;
n = 1;
}
return n;
}
size_t write(const uint8_t *ptr, const size_t size) {
size_t n = 0;
while (n < size) {
uint8_t ch = ptr[n++];
if (!write(ch))
break;
}
return n;
}
protected:
char *_pool;
size_t _capacity;
size_t _write;
size_t _read;
};

View File

@@ -1,86 +0,0 @@
#pragma once
#include <Arduino.h>
template <typename T, size_t BUFFER_SIZE>
class CircularBuffer {
public:
CircularBuffer() : _head{0}, _tail{0}, _full{false} {}
~CircularBuffer() {}
void reset() {
_head = _tail = _full = 0;
}
bool empty() const {
return _head == _tail && !_full;
}
bool full() const {
return _full;
}
size_t size() const {
size_t res = 0;
if (!_full) {
if (_head < _tail)
res = BUFFER_SIZE + _head - _tail;
else
res = _head - _tail;
} else {
res = BUFFER_SIZE;
}
return res;
}
void push(const T &item) {
if (_full) {
_tail++;
if (_tail == BUFFER_SIZE)
_tail = 0;
}
_pool[_head++] = item;
if (_head == BUFFER_SIZE)
_head = 0;
if (_head == _tail)
_full = true;
}
bool pop(T &item) {
bool res = false;
if (!empty()) {
item = _pool[_tail++];
if (_tail == BUFFER_SIZE) _tail = 0;
_full = false;
res = true;
}
return res;
}
bool pop_back(T &item) {
bool res = false;
if (!empty()) {
item = _pool[--_head];
_full = false;
res = true;
}
return res;
}
bool peek(T &item) const {
bool res = false;
if (!empty()) {
item = _pool[_tail];
res = true;
}
return res;
}
private:
T _pool[BUFFER_SIZE];
size_t _head;
size_t _tail;
bool _full;
};

View File

@@ -1,45 +0,0 @@
#pragma once
#include <Arduino.h>
#include "Module/Terminal.h"
#include "Module/CircularBuffer.h"
#include "Module/Runner.h"
class CommandShell {
public:
CommandShell(Runner *runner);
void setTerm(Terminal *term);
Terminal *term();
void showGreetings(bool = true);
void showFarewell(bool = true);
void clearHistory();
void addHistory(const char *);
bool getHistoryInput(String &);
void setEditLine(const String &);
bool active();
void loop();
private:
size_t printGreetings(Print *);
size_t printFarewell(Print *);
size_t printPrompt(Print *);
void onOpen(Print *out);
void onClose(Print *out);
void onData(const char *);
void onHistory(Print *out);
bool getLastInput(String &);
private:
CircularBuffer<String, 4> _history;
Terminal *_term;
Runner *_runner;
String _path;
bool _active;
bool _greetings;
bool _farewell;
};

View File

@@ -1,68 +0,0 @@
#pragma once
#include "Module/CharBuffer.h"
class EditLine : public CharBuffer {
public:
EditLine(size_t size) : CharBuffer(size){};
char &operator[](size_t i) { return _pool[i]; }
char operator[](size_t i) const { return _pool[i]; }
EditLine &operator=(const EditLine &src) {
delete[] _pool;
_pool = new char[src._capacity];
memcpy(_pool, src._pool, src._capacity);
_read = src._read;
_write = src._write;
return *this;
}
void del() {
size_t i;
for (i = _write; i < _capacity; ++i)
_pool[i] = _pool[i + 1];
_pool[i] = '\x00';
}
bool backspace() {
bool res = false;
if (prev()) {
del();
res = true;
}
return res;
}
bool next() {
bool res = false;
if (_write < _capacity - 1) {
_write++;
res = true;
}
return res;
}
bool prev() {
bool res = false;
if (_write > 0) {
_write--;
res = true;
}
return res;
}
size_t home() {
size_t res = _write;
_write = 0;
return res;
}
size_t end() {
size_t n;
for (n = 0; n < _capacity - 1; ++n)
if (_pool[n] == '\x00') break;
return n;
}
};

View File

@@ -1,84 +0,0 @@
#pragma once
#include <Arduino.h>
enum ModuleState_t {
MOD_INIT,
MOD_INIT_FAILED,
MOD_INIT_COMPLETE,
MOD_START_FAILED,
MOD_ACTIVE
};
class Module {
protected:
virtual bool onInit() { return true; };
virtual void onEnd(){};
virtual bool onStart() { return true; }
virtual void onStop(){};
virtual void onLoop() = 0;
protected:
Print *_out;
public:
Module() : _state{MOD_INIT} {}
bool init(bool force = false) {
if (_state > MOD_INIT_COMPLETE) {
return true;
}
if (_state == MOD_INIT_FAILED && !force) {
return false;
}
_state = onInit() ? MOD_INIT_COMPLETE : MOD_INIT_FAILED;
return _state == MOD_INIT_COMPLETE;
}
bool start(bool force = false) {
if (_state == MOD_ACTIVE) {
return true;
}
if (_state == MOD_START_FAILED && !force) {
return false;
}
if (_state < MOD_INIT_COMPLETE) {
if (!init(force)) {
return false;
}
}
_state = onStart() ? MOD_ACTIVE : MOD_START_FAILED;
return _state == MOD_ACTIVE;
}
void stop() {
if (_state < MOD_ACTIVE) {
return;
}
onStop();
_state = MOD_INIT_COMPLETE;
};
void end() {
if (_state < MOD_INIT_FAILED) {
return;
}
onEnd();
_state = MOD_INIT;
};
void loop() {
if (_state == MOD_ACTIVE || start()) onLoop();
};
void setOutput(Print *p) { _out = p; }
ModuleState_t getState() {
return _state;
}
private:
ModuleState_t _state;
};

View File

@@ -1,17 +0,0 @@
#pragma once
#include <Print.h>
#include "Cmd.h"
class Runner {
public:
virtual void run(const char*, Print*);
};
class CmdRunner : public Runner {
public:
void run(const char* cmd, Print* out) override {
String cmdStr{cmd};
csvExecute(cmdStr);
}
};

View File

@@ -1,51 +0,0 @@
#pragma once
#include "Global.h"
#include "Module/Module.h"
#include "Module/Terminal.h"
#include "Module/CommandShell.h"
#include <functional>
enum TelnetEvent_t {
TE_CONNECTED,
TE_DISCONNECTED
};
typedef std::function<void(TelnetEvent_t, WiFiClient*)> TelnetEventHandler;
class Telnet : public Module {
public:
Telnet(uint16_t port) : _port{port}, _lastConnected{false} {};
public:
void setEventHandler(TelnetEventHandler);
void sendData(const String&);
bool hasClient();
bool isShellActive();
void setCommandShell(CommandShell*);
protected:
bool onInit() override;
void onEnd() override;
bool onStart() override;
void onStop() override;
void onLoop() override;
private:
void onConnect();
void onDisconnect();
void onData();
void onOpen();
void onClose();
private:
TelnetEventHandler _eventHandler;
uint16_t _port;
bool _lastConnected;
WiFiClient _client;
WiFiServer* _server;
Terminal* _term;
CommandShell* _shell;
};

View File

@@ -1,186 +0,0 @@
#pragma once
#include <Arduino.h>
#include "Module/EditLine.h"
#include <functional>
#define A_NORMAL 0x0000 // normal
#define A_UNDERLINE 0x0001 // underline
#define A_REVERSE 0x0002 // reverse
#define A_BLINK 0x0004 // blink
#define A_BOLD 0x0008 // bold
#define A_DIM 0x0010 // dim
#define A_STANDOUT A_BOLD // standout (same as bold)
#define F_BLACK 0x0100 // foreground black
#define F_RED 0x0200 // foreground red
#define F_GREEN 0x0300 // foreground green
#define F_BROWN 0x0400 // foreground brown
#define F_BLUE 0x0500 // foreground blue
#define F_MAGENTA 0x0600 // foreground magenta
#define F_CYAN 0x0700 // foreground cyan
#define F_WHITE 0x0800 // foreground white
#define F_YELLOW F_BROWN // some terminals show brown as yellow (with A_BOLD)
#define F_COLOR 0x0F00 // foreground mask
#define B_BLACK 0x1000 // background black
#define B_RED 0x2000 // background red
#define B_GREEN 0x3000 // background green
#define B_BROWN 0x4000 // background brown
#define B_BLUE 0x5000 // background blue
#define B_MAGENTA 0x6000 // background magenta
#define B_CYAN 0x7000 // background cyan
#define B_WHITE 0x8000 // background white
#define B_YELLOW B_BROWN // some terminals show brown as yellow (with A_BOLD)
#define B_COLOR 0xF000 // background mask
#define CHAR_NULL 0x00
#define CHAR_BEL 0x07
#define CHAR_BS 0x08
#define CHAR_SPACE 0x20
#define CHAR_TAB 0x09
#define CHAR_LF 0x0a
#define CHAR_CR 0x0d
#define CHR_ZERO 0x30
#define KEY_DEL 0x7f
#define KEY_DOWN 0x80
#define KEY_UP 0x81
#define KEY_LEFT 0x82
#define KEY_RIGHT 0x83
#define KEY_HOME 0x84
#define KEY_INS 0x86
#define KEY_PAGE_DOWN 0x87
#define KEY_PAGE_UP 0x88
#define KEY_END 0x89
#define CHAR_LT 0x8b
#define CHAR_CSI 0x9b
#define CHAR_ESC 0x1b
#define CHAR_BIN 0xFF
#define ESC_CURSOR_HOME "\x1b[H"
#define ESC_SAVE_CURSOR "\x1b[s"
#define ESC_UNSAVE_CURSOR "\x1b[u"
#define ESC_SAVE_CURSOR_AND_ATTRS "\x1b[7"
#define ESC_RESTORE_CURSOR_AND_ATTRS "\x1b[8"
#define ESC_CLEAR "\x1b[2J"
#define ESC_CLEAR_BOTTOM "\x1b[J"
#define ESC_CLEAR_EOL "\x1b[0K"
#define ESC_CURSOR_UP "\x1b[1A"
#define ESC_CURSOR_DOWN "\x1b[1B"
#define ESC_CURSOR_FORWARD "\x1b[1C"
#define ESC_CURSOR_BACKWARD "\x1b[1D"
#define SEQ_CSI PSTR("\033[") // code introducer
#define SEQ_LOAD_G1 PSTR("\033)0") // load G1 character set
#define SEQ_CLEAR PSTR("\033[2J") // clear screen
#define SEQ_ATTRSET PSTR("\033[0") // set attributes, e.g. "\033[0;7;1m"
#define SEQ_ATTRSET_BOLD PSTR(";1") // bold
#define SEQ_ATTRSET_DIM PSTR(";2") // dim
#define SEQ_ATTRSET_FCOLOR PSTR(";3") // forground color
#define SEQ_ATTRSET_UNDERLINE PSTR(";4") // underline
#define SEQ_ATTRSET_BCOLOR PSTR(";4") // background color
#define SEQ_ATTRSET_BLINK PSTR(";5") // blink
#define SEQ_ATTRSET_REVERSE PSTR(";7") // reverse
enum TerminalEventEnum {
EVENT_OPEN,
EVENT_CLOSE,
EVENT_TAB
};
enum SpecialKeyEnum { SPEC_KEY_UP,
SPEC_KEY_TAB,
SPEC_KEY_ENTER,
SPEC_KEY_ESC };
typedef std::function<bool(SpecialKeyEnum key)> SpecialKeyPressedEvent;
typedef std::function<void(TerminalEventEnum, Stream *)> TerminalEventHandler;
typedef std::function<void(const char *)> TerminalInputEventHandler;
enum EOLType_t { CRLF,
LFCR,
LF,
CR };
enum State { ST_INACTIVE,
ST_NORMAL,
ST_ESC_SEQ,
ST_CTRL_SEQ };
class Terminal : public Print {
public:
Terminal(Stream *stream = nullptr);
void setStream(Stream *stream);
void setEOL(EOLType_t code);
void enableControlCodes(bool enabled = true);
void enableEcho(bool enabled = true);
void enableColors(bool enabled = true);
void setOnEvent(TerminalEventHandler);
void setOnSpecKeyPress(SpecialKeyPressedEvent);
void setOnReadLine(TerminalInputEventHandler);
bool setLine(const uint8_t *bytes, size_t size);
CharBuffer &getLine();
void backsp();
void clear();
void clear_line();
size_t println(const char *str);
size_t println(void);
size_t write_P(PGM_P str);
size_t write(uint8_t c);
size_t write(const uint8_t *buf, size_t size);
void writeByDigit(uint8_t i);
bool available();
void loop();
void start();
void quit();
void initscr();
void attrset(uint16_t attr);
private:
void move(uint8_t y, uint8_t x);
TerminalEventHandler eventHandler_;
TerminalInputEventHandler inputHandler_;
uint8_t attr = 0xff;
uint8_t curY = 0xff;
uint8_t curX = 0xff;
unsigned long _lastReceived = 0;
State state;
Stream *_stream;
EditLine _line;
char _cc_buf[32] = {0};
size_t _cc_pos = 0;
bool _color = false;
bool _controlCodes = false;
bool _echo = false;
EOLType_t _eol = CRLF;
struct ControlCode {
const char *cc;
const char ch;
};
ControlCode keyMap[10] = {
{"G", KEY_HOME}, // 71 Home key
{"H", KEY_UP}, // 72 Up arrow
{"I", KEY_PAGE_UP}, // 73 PageUp
{"K", KEY_LEFT}, // 75 Left arrow
{"M", KEY_RIGHT}, // 77 Right arrow
{"O", KEY_END}, // 79 End key
{"P", KEY_DOWN}, // 80 Down arrow
{"Q", KEY_PAGE_DOWN}, // 81 PageDown
{"R", KEY_INS}, // 82 Insert
{"S", KEY_DEL}, // 83 Delete
};
};

View File

@@ -1,27 +0,0 @@
#pragma once
#include <Arduino.h>
namespace MqttClient {
void init();
boolean connect();
void reconnect();
void loop();
void subscribe();
boolean publish(const String& topic, const String& data);
boolean publishData(const String& topic, const String& data);
boolean publishChart(const String& topic, const String& data);
boolean publishControl(String id, String topic, String state);
boolean publishChart_test(const String& topic, const String& data);
boolean publishStatus(const String& topic, const String& data);
void publishWidgets();
void publishState();
void handleSubscribedUpdates(char* topic, uint8_t* payload, size_t length);
const String getStateStr();
} // namespace MqttClient

View File

@@ -1,8 +0,0 @@
#pragma once
#include "Utils/SysUtils.h"
namespace Discovery {
}

View File

@@ -1,8 +0,0 @@
#pragma once
#ifdef SSDP
#include <Arduino.h>
extern void SsdpInit();
extern String xmlNode(String tags, String data);
extern String decToHex(uint32_t decValue, byte desiredStringLength);
#endif

View File

@@ -1,3 +0,0 @@
#pragma once

View File

@@ -1,29 +0,0 @@
#pragma once
#ifdef SERVO_ENABLED
#include <Arduino.h>
#include <ESP32Servo.h>
#include <Servo.h>
struct Servo_t {
uint8_t num;
uint8_t pin;
Servo* obj;
Servo_t(uint8_t num, uint8_t pin) : num{num}, pin{pin}, obj{nullptr} {};
};
class Servos {
public:
Servos();
Servo* get(uint8_t num);
Servo* create(uint8_t num, uint8_t pin);
size_t count();
private:
std::vector<Servo_t> _items;
};
extern Servos myServo;
#endif

View File

@@ -1,139 +0,0 @@
#pragma once
//Strings
// #include <stdafx.h>
#include <stdio.h>
#include <cstring>
#include <iostream>
class char_array {
private:
char *p_stringarray; //initial input array
char *p_inputstring; //holds actual length data
//char **pp_database_string; //allocate data database.cpp
int stringsize; //holds array size to allocate memory
int charinput; //holds array input size
public:
inline char_array(); //inline so other functions can call on it
inline ~char_array();
inline void getinput(char *&); //retrieves user input
inline void grabline(char *&); //retrieve line with whitespace included NOT COMPLETE, may not need
inline int sortline(char **&, char *&); //sorts line into an array of strings and returns number of separate strings
inline int arraysize(); //returns size of string array
inline void printinput(); //print input string
inline void changedefaultsize(); //change default input size NOT COMPLETE
};
inline char_array::char_array() //constructor
{
stringsize = 0;
charinput = 64;
p_stringarray = new char[charinput];
}
inline char_array::~char_array() //destructor
{
delete[] p_inputstring;
delete[] p_stringarray;
}
inline void char_array::getinput(char *&p_stringin) {
stringsize = 0;
scanf("%63s", p_stringarray); //get input string
while (p_stringarray[stringsize] != 0) //finding out the size of string array
{
stringsize++;
}
stringsize++;
p_inputstring = new char[stringsize]; //reallocate memory block and set array inside
for (int i = 0; i < stringsize; i++) {
p_inputstring[i] = p_stringarray[i];
}
p_inputstring[stringsize - 1] = '\x00';
p_stringin = new char[stringsize]; //set pp_stringin
p_stringin = p_inputstring;
}
inline void char_array::grabline(char *&p_stringin) {
stringsize = 0;
std::cin.getline(p_stringarray, charinput);
while (p_stringarray[stringsize] != 0) {
stringsize++;
}
stringsize++;
p_inputstring = new char[stringsize];
for (int i = 0; i < stringsize; i++) {
p_inputstring[i] = p_stringarray[i];
}
p_stringin = new char[stringsize];
p_stringin = p_inputstring;
}
inline int char_array::sortline(char **&pp_stringin, char *&p_string) {
int position = 0; //position in string
int charcount = 1; //how many characters there are
int wordnum; //which word is being processed
int wordcount = 1; //number of words in string
int bookmark = 0; //holds last known position
while (p_string[position] == ' ') {
position++;
}
wordnum = position; //borrow wordnum to hold position value
while (p_string[position] != '\x00') //find total inputted string word length
{
if ((p_string[position] == ' ') && ((p_string[position + 1] != ' ') || (p_string[position + 1] != '\x00'))) {
wordcount++;
}
position++;
}
position = wordnum; //set position to original value
for (wordnum = 0; wordnum < wordcount; wordnum++) {
charcount = 1;
while (p_string[position] == ' ') {
position++;
}
while ((p_string[position] != ' ') && (p_string[position] != '\x00')) {
position++;
charcount++;
}
pp_stringin[wordnum] = new char[charcount];
for (int i = 0; i < charcount; i++) {
pp_stringin[wordnum][i] = p_string[i + bookmark];
}
pp_stringin[wordnum][charcount - 1] = '\x00';
bookmark = position + 1;
}
return wordcount;
}
inline int char_array::arraysize() {
if (stringsize != 0) {
return stringsize;
} else {
printf("Array size is set at 0\n");
return 0;
}
}
inline void char_array::printinput() {
printf("%s", p_inputstring);
}
inline void char_array::changedefaultsize() {
printf("Input new default input string size: ");
scanf("%i", charinput);
}

View File

@@ -1,8 +0,0 @@
#pragma once
#include <Arduino.h>
const String getAvailableUrl(const char* mcu);
void getLastVersion();
void upgradeInit();
void upgrade_firmware();

View File

@@ -1,55 +0,0 @@
#pragma once
#include <Arduino.h>
#include "FS.h"
#ifdef ESP32
#include "LITTLEFS.h"
#define LittleFS LITTLEFS
#endif
#ifdef ESP8266
#include <LittleFS.h>
#endif
class FileHelper {
public:
FileHelper(const String filename);
/*
* Проверить существование
*/
void exists();
/*
* Удалить файл
*/
void remove();
/*
* Открыть файл установить позицию @position
*/
File seek(size_t position = 0);
/*
* Чтение строки с содержащей @substr
*/
String readFileString(const String substr);
/*
* Добовление строки @str в файл
*/
String appendStr(const String str);
/*
* Запись строки
*/
String writeStr(const String);
/*
* Чтение в строку
*/
String readStr(size_t);
/*
* Размер в байтах
*/
size_t getSize();
};

View File

@@ -1,67 +0,0 @@
#pragma once
#include <Arduino.h>
#include "Consts.h"
#include "FS.h"
#ifdef ESP32
#include "LITTLEFS.h"
#define LittleFS LITTLEFS
#endif
#ifdef ESP8266
#include <LittleFS.h>
#endif
/*
* Инициализация ФС
*/
bool fileSystemInit();
/*
* Удалить файл
*/
void removeFile(const String& filename);
/*
* Открыть файл на позиции
*/
File seekFile(const String& filename, size_t position = 0);
/*
* Чтение строки из файла
* возвращает стоку из файла в которой есть искомое слово found
*/
const String readFileString(const String& filename, const String& to_find);
/*
* Добовление строки в файл
*/
const String addFileLn(const String& filename, const String& str);
/*
* Добовление строки в файл
*/
const String addFile(const String& filename, const String& str);
/*
* Запись строки в файл
*/
const String writeFile(const String& filename, const String& str);
/*
* Чтение файла в строку
*/
const String readFile(const String& filename, size_t max_size);
/*
* Размер файла
*/
const String getFileSize(const String& filename);
bool copyFile(const String& src, const String& dst, bool overwrite = true);
const String getFSSizeInfo();
const String getConfigFile(uint8_t preset, ConfigType_t type);

View File

@@ -1,19 +0,0 @@
#pragma once
#include <Arduino.h>
String jsonReadStr(String& json, String name);
int jsonReadInt(String& json, String name);
boolean jsonReadBool(String& json, String name);
String jsonWriteStr(String& json, String name, String value);
String jsonWriteInt(String& json, String name, int value);
String jsonWriteFloat(String& json, String name, float value);
String jsonWriteBool(String& json, String name, boolean value);
void saveConfig();

View File

@@ -1,33 +0,0 @@
#pragma once
#include "Arduino.h"
#include "Utils\StringUtils.h"
#include "Utils\TimeUtils.h"
#include "Errors.h"
#include "Global.h"
#define pm PrintMessage(MODULE)
class PrintMessage {
public:
PrintMessage(const char* module) {
_module = module;
}
void error(const String& str) {
print(EL_ERROR, str);
}
void info(const String& str) {
print(EL_INFO, str);
}
private:
void print(const ErrorLevel_t level, const String& str) {
Serial.printf("%s [%s] [%s] %s\n", prettyMillis(millis()).c_str(), getErrorLevelStr(level).c_str(), _module, str.c_str());
}
private:
const char* _module;
};

View File

@@ -1,29 +0,0 @@
#pragma once
#include <Arduino.h>
uint8_t hexStringToUint8(String hex);
uint16_t hexStringToUint16(String hex);
String selectToMarkerLast(String str, String found);
String selectToMarker(String str, String found);
String extractInner(String str);
String deleteAfterDelimiter(String str, String found);
String deleteBeforeDelimiter(String str, String found);
String deleteBeforeDelimiterTo(String str, String found);
String deleteToMarkerLast(String str, String found);
String selectFromMarkerToMarker(String str, String found, int number);
size_t itemsCount(String str, const String& separator);
boolean isDigitStr(const String&);
String prettyBytes(size_t size);

View File

@@ -1,17 +0,0 @@
#pragma once
#include <Arduino.h>
#include "Global.h"
const String getChipId();
void setLedStatus(LedStatus_t status);
const String getUniqueId(const String& name);
const String printMemoryStatus();
const String getHeapStats();
const String getMacAddress();
void setChipId();

View File

@@ -1,51 +0,0 @@
#pragma once
#include <Arduino.h>
#include "Consts.h"
#define ONE_MINUTE_s 60
#define ONE_HOUR_m 60
#define ONE_HOUR_s 60 * ONE_MINUTE_s
#define LEAP_YEAR(Y) (((1970 + Y) > 0) && !((1970 + Y) % 4) && (((1970 + Y) % 100) || !((1970 + Y) % 400)))
#define MIN_DATETIME 1575158400
#define ONE_SECOND_ms 1000
/*
* Время (мс) прошедщее с @since
*/
unsigned long millis_since(unsigned long sinse);
/*
* Интерввал времени (мс) между @start и @finish
*/
unsigned long millis_passed(unsigned long start, unsigned long finish);
/*
* Форматиронное время интервала (мс)
* "чч:мм:cc",
* "дд чч:мм", если > 24 часов
*/
const String prettyMillis(unsigned long time_ms = millis());
/*
* Форматиронное время интервала (c)
* "чч:мм:cc",
* "дд чч:мм", если > 24 часов
*/
const String prettySeconds(unsigned long time_s);
/*
* Тайм зона в секундах
*/
int getOffsetInSeconds(int timezone);
/*
* Тайм зона в минутах
*/
int getOffsetInMinutes(int timezone);
/*
* Разбивает время на составляющие
*/
void breakEpochToTime(unsigned long epoch, Time_t& tm);

View File

@@ -1,71 +0,0 @@
#include <Arduino.h>
enum Timings_t { MT_ONE,
MT_TWO,
NUM_TIMINGS };
struct Timing {
unsigned long _total_mu;
unsigned long _min_mu;
unsigned long _max_mu;
Timing() : _total_mu{0}, _min_mu{999999}, _max_mu{0} {};
void reset() {
_total_mu = 0;
_min_mu = 999999;
_max_mu = 0;
}
void add(unsigned long time_mu) {
if (time_mu == 0) return;
_total_mu += time_mu;
if (_min_mu > time_mu) {
_min_mu = time_mu;
}
if (_max_mu < time_mu) {
_max_mu = time_mu;
}
}
};
static const char* module_name[NUM_TIMINGS] = {"strings", "boolean"};
struct Timings {
Timing mu[NUM_TIMINGS];
unsigned long _counter;
unsigned long _start;
unsigned long long _total;
Timings() : _counter{0}, _start{0} {};
void add(size_t module, unsigned long now = micros()) {
unsigned long time = now - _start;
_total += time;
mu[module].add(time);
_start = now;
}
void count() {
_counter++;
_start = micros();
}
void print() {
if (!_counter) {
return;
};
Serial.printf("lp/ms: %llu ", _counter / _total);
for (size_t i = 0; i < NUM_TIMINGS; i++) {
Serial.printf("%s: %.2f%% ", module_name[i], ((float)mu[i]._total_mu / _total) * 100);
mu[i].reset();
}
Serial.println();
_counter = 0;
_total = 0;
};
};

View File

@@ -1,7 +0,0 @@
#pragma once
#include "HttpServer.h"
#include <Arduino.h>
extern String getURL(const String& urls);
extern const String getMethodName(AsyncWebServerRequest* request);
extern const String getRequestInfo(AsyncWebServerRequest* request);

View File

@@ -1,12 +0,0 @@
#pragma once
#include "Global.h"
boolean isNetworkActive();
void startSTAMode();
bool startAPMode();
boolean scanWiFi(String ssid);

View File

@@ -1,6 +0,0 @@
#pragma once
#include "Arduino.h"
void web_init();
void setConfigParam(const char* param, const String& value);

View File

@@ -1,3 +0,0 @@
#pragma once
//void myCallback;

View File

@@ -1,5 +0,0 @@
#pragma once
void setupTest();
void loopTest();
//char stringToCharArray(String in);

View File

@@ -1,9 +0,0 @@
#pragma once
extern void udpInit();
extern bool isUdpEnabled();
extern void loopUdp();
extern void handleUdp_esp32();
extern void do_udp_data_parse();
extern void add_dev_in_list(String filename, String id, String dev_name, String ip);
extern void send_mqtt_to_udp();