Удаление сканера one wire

This commit is contained in:
Dmitry Borisenko
2020-07-27 21:10:11 +02:00
parent bdd9f1d3bd
commit 110fc167a1
10 changed files with 10 additions and 123 deletions

View File

@@ -34,32 +34,6 @@
"title": "Сканировать", "title": "Сканировать",
"action": "/set?i2c", "action": "/set?i2c",
"class": "btn btn-block btn-default" "class": "btn btn-block btn-default"
},
{
"type": "h3",
"title": "Сканирование шины OneWire"
},
{
"type": "input",
"title": "Номер пина шины OneWire",
"name": "oneWirePin-arg",
"state": "{{oneWirePin}}"
},
{
"type": "button",
"title": "Сохранить",
"action": "/set?oneWirePin=[[oneWirePin-arg]]",
"class": "btn btn-block btn-default"
},
{
"type": "h4",
"title": "{{oneWire}}"
},
{
"type": "link",
"title": "Сканировать",
"action": "/set?oneWire=[[oneWirePin-arg]]",
"class": "btn btn-block btn-default"
} }
] ]
} }

View File

@@ -2,7 +2,6 @@
#include "Bus/BusScanner.h" #include "Bus/BusScanner.h"
#include "Bus/I2CScanner.h" #include "Bus/I2CScanner.h"
#include "Bus/OneWireScanner.h"
#include "Consts.h" #include "Consts.h"
#include "Utils/JsonUtils.h" #include "Utils/JsonUtils.h"
@@ -12,10 +11,6 @@ class BusScannerFactory {
switch (type) { switch (type) {
case BS_I2C: case BS_I2C:
return new I2CScanner(str); return new I2CScanner(str);
case BS_ONE_WIRE: {
uint8_t pin = jsonReadInt(config, TAG_ONE_WIRE_PIN);
return new OneWireScanner(str, pin);
}
default: default:
return nullptr; return nullptr;
} }

View File

@@ -1,21 +0,0 @@
#pragma once
#include <Arduino.h>
#include <OneWire.h>
struct OneWireBus_t {
OneWire *bus;
uint8_t pin;
};
class OneWireBus {
public:
OneWireBus();
OneWire *get(uint8_t pin);
size_t count();
private:
std::vector<OneWireBus_t> _items;
};
extern OneWireBus oneWireBus;

View File

@@ -1,15 +0,0 @@
#pragma once
#include "BusScanner.h"
#include "OneWireBus.h"
class OneWireScanner : public BusScanner {
public:
OneWireScanner(String& out, uint8_t pin);
protected:
virtual boolean syncScan() override;
private:
OneWire* _bus;
};

View File

@@ -57,6 +57,8 @@ extern AsyncWebServer server;
extern DallasTemperature sensors; extern DallasTemperature sensors;
extern OneWire *oneWire;
extern boolean but[NUM_BUTTONS]; extern boolean but[NUM_BUTTONS];
extern Bounce* buttons; extern Bounce* buttons;

View File

@@ -1,25 +0,0 @@
#include "Bus/OneWireBus.h"
OneWireBus oneWireBus;
OneWireBus::OneWireBus(){};
OneWire *OneWireBus::get(uint8_t pin) {
// Ищем среди ранее созданных
for (size_t i = 0; i < _items.size(); i++) {
auto item = _items.at(i);
if (item.pin == pin) {
return item.bus;
}
}
// Добавляем новый
OneWireBus_t newItem;
newItem.bus = new OneWire(pin);
newItem.pin = pin;
_items.push_back(newItem);
return newItem.bus;
}
size_t OneWireBus::count() {
return _items.size();
}

View File

@@ -1,26 +0,0 @@
#include "Bus/OneWireScanner.h"
#include "Utils/PrintMessage.h"
const char* MODULE = "OneWire";
OneWireScanner::OneWireScanner(String& out, uint8_t pin) : BusScanner(TAG_ONE_WIRE, out, 1) {
_bus = oneWireBus.get(pin);
}
bool OneWireScanner::syncScan() {
uint8_t addr[8];
pm.info("scanning...");
while (_bus->search(addr)) {
for (uint8_t i = 0; i < 8; i++) {
pm.info("found: " + String(i, DEC));
addResult(addr[i], i < 7);
}
}
if (OneWire::crc8(addr, 7) != addr[7]) {
pm.error(String("CRC!"));
return false;
}
_bus->reset_search();
return true;
}

View File

@@ -108,6 +108,7 @@ void cmd_init() {
//========================================================================================================== //==========================================================================================================
//==========================================Модуль кнопок=================================================== //==========================================Модуль кнопок===================================================
void button() { void button() {
pm.info("create 'button'"); pm.info("create 'button'");
String number = sCmd.next(); String number = sCmd.next();

View File

@@ -17,6 +17,8 @@ StringCommand sCmd;
AsyncWebServer server(80); AsyncWebServer server(80);
OneWire *oneWire;
DallasTemperature sensors; DallasTemperature sensors;
/* /*

View File

@@ -1,4 +1,3 @@
#include "Bus/OneWireBus.h"
#include "Global.h" #include "Global.h"
GMedian<10, int> medianFilter; GMedian<10, int> medianFilter;
@@ -232,18 +231,19 @@ void analog_reading2() {
//========================================================================================================================================= //=========================================================================================================================================
//=========================================Модуль температурного сенсора ds18b20=========================================================== //=========================================Модуль температурного сенсора ds18b20===========================================================
#ifdef DALLAS_ENABLED #ifdef DALLAS_ENABLED
//dallas temp1 2 0x14 Температура Датчики anydata 1 //dallas temp1 2 1 Температура Датчики anydata 1
//dallas temp2 2 0x14 Температура Датчики anydata 2 //dallas temp2 2 2 Температура Датчики anydata 2
void dallas() { void dallas() {
String value_name = sCmd.next(); String value_name = sCmd.next();
uint8_t pin = (uint8_t)String(sCmd.next()).toInt(); String pin = sCmd.next();
String address = sCmd.next(); String address = sCmd.next();
jsonWriteStr(configOptionJson, value_name + "_ds", address); jsonWriteStr(configOptionJson, value_name + "_ds", address);
String widget_name = sCmd.next(); String widget_name = sCmd.next();
String page_name = sCmd.next(); String page_name = sCmd.next();
String type = sCmd.next(); String type = sCmd.next();
String page_number = sCmd.next(); String page_number = sCmd.next();
sensors.setOneWire(oneWireBus.get(pin)); oneWire = new OneWire((uint8_t) pin.toInt());
sensors.setOneWire(oneWire);
sensors.begin(); sensors.begin();
sensors.setResolution(12); sensors.setResolution(12);
dallas_value_name += value_name + ";"; dallas_value_name += value_name + ";";