mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-27 06:32:19 +03:00
Добавляем сервопривод
This commit is contained in:
@@ -6,6 +6,7 @@ void* getAPI_SysExt(String subtype, String params);
|
||||
void* getAPI_Variable(String subtype, String params);
|
||||
void* getAPI_ButtonIn(String subtype, String params);
|
||||
void* getAPI_ButtonOut(String subtype, String params);
|
||||
void* getAPI_IoTServo(String subtype, String params);
|
||||
void* getAPI_Mp3(String subtype, String params);
|
||||
void* getAPI_Telegram(String subtype, String params);
|
||||
void* getAPI_Timer(String subtype, String params);
|
||||
@@ -34,6 +35,7 @@ if ((tmpAPI = getAPI_SysExt(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Variable(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_ButtonIn(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_ButtonOut(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_IoTServo(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Mp3(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Telegram(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Timer(subtype, params)) != nullptr) return tmpAPI;
|
||||
|
||||
69
src/modules/exec/IoTServo/IoTServo.cpp
Normal file
69
src/modules/exec/IoTServo/IoTServo.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
#include "Global.h"
|
||||
#include "classes/IoTItem.h"
|
||||
|
||||
#include <Servo.h>
|
||||
|
||||
class IoTServo : public IoTItem {
|
||||
private:
|
||||
Servo servObj;
|
||||
int _apin, _oldValue;
|
||||
int _locmap1, _locmap2, _locmap3, _locmap4;
|
||||
|
||||
public:
|
||||
IoTServo(String parameters): IoTItem(parameters) {
|
||||
int pin;
|
||||
jsonRead(parameters, "pin", pin);
|
||||
servObj.attach(pin);
|
||||
|
||||
jsonRead(parameters, "apin", _apin);
|
||||
|
||||
String map;
|
||||
jsonRead(parameters, F("amap"), map, false);
|
||||
if (map != "") {
|
||||
_locmap1 = selectFromMarkerToMarker(map, ",", 0).toInt();
|
||||
_locmap2 = selectFromMarkerToMarker(map, ",", 1).toInt();
|
||||
_locmap3 = selectFromMarkerToMarker(map, ",", 2).toInt();
|
||||
_locmap4 = selectFromMarkerToMarker(map, ",", 3).toInt();
|
||||
}
|
||||
}
|
||||
|
||||
void doByInterval() {
|
||||
if (_apin >= 0) {
|
||||
value.valD = map(analogRead(_apin), _locmap1, _locmap2, _locmap3, _locmap4);
|
||||
if (abs(_oldValue - value.valD) > 1) {
|
||||
_oldValue = value.valD;
|
||||
servObj.write(_oldValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IoTValue execute(String command, std::vector<IoTValue> ¶m) {
|
||||
if (command == "rotate") {
|
||||
if (param.size()) {
|
||||
value.valD = param[0].valD;
|
||||
servObj.write(value.valD);
|
||||
regEvent(value.valD, "IoTServo");
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
void setValue(IoTValue Value) {
|
||||
value = Value;
|
||||
if (value.isDecimal & (_oldValue != value.valD)) {
|
||||
_oldValue = value.valD;
|
||||
servObj.write(_oldValue);
|
||||
regEvent(value.valD, "IoTServo");
|
||||
}
|
||||
}
|
||||
|
||||
~IoTServo() {};
|
||||
};
|
||||
|
||||
void* getAPI_IoTServo(String subtype, String param) {
|
||||
if (subtype == F("IoTServo")) {
|
||||
return new IoTServo(param);
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
17
src/modules/exec/IoTServo/items.json
Normal file
17
src/modules/exec/IoTServo/items.json
Normal file
@@ -0,0 +1,17 @@
|
||||
[
|
||||
{
|
||||
"name": "Сервопривод",
|
||||
"num": 30,
|
||||
"type": "Writing",
|
||||
"subtype": "IoTServo",
|
||||
"id": "servo",
|
||||
"widget": "range",
|
||||
"page": "servo",
|
||||
"descr": "угол",
|
||||
|
||||
"int": 0,
|
||||
"pin": 12,
|
||||
"apin": -1,
|
||||
"amap": "0, 4096, 0, 180"
|
||||
}
|
||||
]
|
||||
7
src/modules/exec/IoTServo/platformio.ini
Normal file
7
src/modules/exec/IoTServo/platformio.ini
Normal file
@@ -0,0 +1,7 @@
|
||||
[env:esp8266_4mb]
|
||||
lib_deps =
|
||||
|
||||
|
||||
[env:esp32_4mb]
|
||||
lib_deps =
|
||||
https://github.com/RoboticsBrno/ServoESP32
|
||||
Reference in New Issue
Block a user