This commit is contained in:
Dmitry Borisenko
2020-09-18 00:02:20 +03:00
parent 0598a20beb
commit b66b4ab947
10 changed files with 52 additions and 222 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,31 +1,25 @@
#pragma once
/*
* Main consts
*/
//=================Firmeare=================
#define FIRMWARE_NAME "esp8266-iotm"
#define FIRMWARE_VERSION 240
#define NUM_BUTTONS 6
#define LED_PIN 2
#define FLASH_4MB true
//=================System===================
#define NUM_BUTTONS 6
#define LED_PIN 2
//=================MQTT=====================
#define MQTT_RECONNECT_INTERVAL 20000
//===============Telemetry==================
#define TELEMETRY_UPDATE_INTERVAL_MIN 60
//=============Configuration================
#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
*/
//=============System parts=================
//#define OTA_UPDATES_ENABLED
//#define MDNS_ENABLED
//#define WEBSOCKET_ENABLED
@@ -33,34 +27,25 @@
//#define UDP_ENABLED
#define SSDP_EN
/*
* Sensor
*/
//=========Sensors enable/disable===========
#define TANK_LEVEL_SAMPLES 10
#define LEVEL_ENABLED
#define ANALOG_ENABLED
#define DALLAS_ENABLED
#define DHT_ENABLED
#define BMP_ENABLED
#define BME_ENABLED
/*
* Gears
*/
//=========Gears enable/disable===========
#define STEPPER_ENABLED
#define SERVO_ENABLED
/*
* Other
*/
//=========Other enable/disable===========
#define LOGGING_ENABLED
#define SERIAL_ENABLED
#define PUSH_ENABLED
struct Time_t {
uint8_t second;
uint8_t minute;
@@ -129,9 +114,4 @@ enum LedStatus_t {
enum ConfigType_t {
CT_CONFIG,
CT_SCENARIO
};
enum BusScanner_t {
BS_I2C,
BS_ONE_WIRE
};
};

View File

@@ -82,15 +82,6 @@ extern int enter_to_logging_counter;
extern int scenario_line_status[40];
extern int lastVersion;
//Запрос на скарнирование шины
extern boolean busScanFlag;
//Запрос на сканирование шины, указание какую
extern BusScanner_t busToScan;
extern boolean fsCheckFlag;
//Global functions
// Logging
extern void logging();

View File

@@ -1,26 +0,0 @@
#include "Bus/I2CScanner.h"
#include "Utils/PrintMessage.h"
#include <Wire.h>
I2CScanner::I2CScanner(String& out) : BusScanner(TAG_I2C, out, 2){};
void I2CScanner::init() {
Wire.begin();
}
boolean I2CScanner::syncScan() {
SerialPrint("I","module","scanning...");
size_t cnt = 0;
for (uint8_t i = 8; i < 120; i++) {
Wire.beginTransmission(i);
if (Wire.endTransmission() == 0) {
SerialPrint("I","module","found: " + i);
addResult(i, i < 119);
cnt++;
}
}
return cnt;
}

View File

@@ -48,7 +48,6 @@ int enter_to_logging_counter;
// Scenario
int scenario_line_status[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
int lastVersion;
BusScanner_t busToScan;
boolean busScanFlag = false;
boolean fsCheckFlag = false;

View File

@@ -85,29 +85,31 @@ void web_init() {
}
#endif
//==============================udp settings=============================================
if (request->hasArg("udponoff")) {
bool value = request->getParam("udponoff")->value().toInt();
jsonWriteBool(configSetupJson, "udponoff", value);
saveConfig();
loadScenario();
request->send(200);
}
//if (request->hasArg("udponoff")) {
// bool value = request->getParam("udponoff")->value().toInt();
// jsonWriteBool(configSetupJson, "udponoff", value);
// saveConfig();
// loadScenario();
// request->send(200);
//}
//
//if (request->hasArg("updatelist")) {
// removeFile("/dev.csv");
// addFileLn("dev.csv", "device id;device name;ip address");
// request->redirect("/?set.udp");
//}
//
//if (request->hasArg("updatepage")) {
// request->redirect("/?set.udp");
//}
//
//if (request->hasArg("devname")) {
// jsonWriteStr(configSetupJson, "name", request->getParam("devname")->value());
// saveConfig();
// request->send(200);
//}
if (request->hasArg("updatelist")) {
removeFile("/dev.csv");
addFileLn("dev.csv", "device id;device name;ip address");
request->redirect("/?set.udp");
}
if (request->hasArg("updatepage")) {
request->redirect("/?set.udp");
}
if (request->hasArg("devname")) {
jsonWriteStr(configSetupJson, "name", request->getParam("devname")->value());
saveConfig();
request->send(200);
}
//==============================wifi settings=============================================
if (request->hasArg("routerssid")) {
jsonWriteStr(configSetupJson, "routerssid", request->getParam("routerssid")->value());
@@ -167,7 +169,9 @@ void web_init() {
saveConfig();
request->send(200);
}
//==============================mqtt settings=============================================
if (request->hasArg("mqttServer")) {
jsonWriteStr(configSetupJson, "mqttServer", request->getParam("mqttServer")->value());
saveConfig();
@@ -215,31 +219,20 @@ void web_init() {
request->send(200, "text/html", payload);
}
//==============================push settings=============================================
#ifdef PUSH_ENABLED
if (request->hasArg("pushingboxid")) {
jsonWriteStr(configSetupJson, "pushingboxid", request->getParam("pushingboxid")->value());
saveConfig();
request->send(200);
}
#endif
// //==============================push settings=============================================
//#ifdef PUSH_ENABLED
// if (request->hasArg("pushingboxid")) {
// jsonWriteStr(configSetupJson, "pushingboxid", request->getParam("pushingboxid")->value());
// saveConfig();
// request->send(200);
// }
//#endif
//==============================utilities settings=============================================
if (request->hasArg(TAG_I2C)) {
busScanFlag = true;
busToScan = BS_I2C;
if (request->hasArg("i2c")) {
request->redirect("/?set.utilities");
} else if (request->hasArg(TAG_ONE_WIRE)) {
busScanFlag = true;
busToScan = BS_ONE_WIRE;
if (request->hasParam(TAG_ONE_WIRE_PIN)) {
setConfigParam(TAG_ONE_WIRE_PIN, request->getParam(TAG_ONE_WIRE_PIN)->value());
}
request->redirect("/?set.utilities");
} else if (request->hasArg(TAG_ONE_WIRE_PIN)) {
setConfigParam(TAG_ONE_WIRE_PIN, request->getParam(TAG_ONE_WIRE_PIN)->value());
request->send(200);
}
}
});
//==============================list of items=====================================================
@@ -272,7 +265,7 @@ void web_init() {
} else if (lastVersion == -2) {
msg = F("Устройство не подключено к роутеру!");
}
// else if (lastVersion == "") {
//msg = F("Нажмите на кнопку \"обновить прошивку\" повторно...");
//} else if (lastVersion == "less") {

View File

@@ -1,18 +0,0 @@
#include "Bus/BusScannerFactory.h"
#include "Class/NotAsinc.h"
#include "Global.h"
void busInit() {
myNotAsincActions->add(
do_BUSSCAN, [&](void*) {
doBusScan();
},
nullptr);
}
void doBusScan() {
String res = "";
BusScanner* scanner = BusScannerFactory::get(configSetupJson, busToScan, res);
scanner->scan();
jsonWriteStr(configLiveJson, String(scanner->tag()), res);
}

View File

@@ -99,9 +99,6 @@ void loop() {
#endif
#ifdef WS_enable
ws.cleanupClients();
#endif
#ifdef UDP_ENABLED
loopUdp();
#endif
timeNow->loop();
MqttClient::loop();