add IRremote

This commit is contained in:
Mit4el
2024-09-21 12:09:11 +03:00
parent af0f782f07
commit d63f1bb5bf
8 changed files with 448 additions and 82 deletions

View File

@@ -0,0 +1,215 @@
#include "Global.h"
#include "classes/IoTItem.h"
#include <Arduino.h>
#include <IRremoteESP8266.h>
#include <IRac.h>
#include <IRutils.h>
IRac* ac;
const uint16_t kIrLed = 4; // The ESP GPIO pin to use that controls the IR LED.
class IRremote : public IoTItem {
private:
String _set_id; // заданная температура
//float pv_last = 0; // предыдущая температура
//float sp, pv, pv2;
//String interim;
int enable = 1;
float _tmp;
int _prot; // протокол
int _pinTx; // Выход модуля передатчика
public:
IRremote(String parameters): IoTItem(parameters) {
jsonRead(parameters, "pinTx", _pinTx); //передатчик
jsonRead(parameters, "prot", _prot); // используемый протокол
jsonRead(parameters, "set_id", _set_id); // id установленной температуры
if (_pinTx >= 0) {
IoTgpio.pinMode(_pinTx, OUTPUT);
IoTgpio.digitalWrite(_pinTx, false); }
// Set up what we want to send.
// See state_t, opmode_t, fanspeed_t, swingv_t, & swingh_t in IRsend.h for
// all the various options.
ac = new IRac(kIrLed);
ac->next.protocol = (decode_type_t)_prot;
ac->next.model = 1; // Некоторые кондиционеры имеют разные модели. Попробуйте только первое.
ac->next.mode = stdAc::opmode_t::kCool; // Сначала запустите в прохладном режиме.
ac->next.celsius = true; // Используйте градусы Цельсия в качестве единиц измерения температуры. Ложь = Фаренгейт
ac->next.degrees = 20; // 20 degrees.
ac->next.fanspeed = stdAc::fanspeed_t::kMedium; // Запустите вентилятор на средней скорости.
ac->next.swingv = stdAc::swingv_t::kOff; // Не поворачивайте вентилятор вверх или вниз.
ac->next.swingh = stdAc::swingh_t::kOff; // Не поворачивайте вентилятор влево или вправо.
ac->next.light = false; // Выключите все светодиоды/световые приборы/дисплеи, которые сможем.
ac->next.beep = false; // Если есть возможность, выключите все звуковые сигналы кондиционера.
ac->next.econo = false; // Turn off any economy modes if we can.
ac->next.filter = false; // Turn off any Ion/Mold/Health filters if we can.
ac->next.turbo = false; // Don't use any turbo/powerful/etc modes.
ac->next.quiet = false; // Don't use any quiet/silent/etc modes.
ac->next.sleep = -1; // Don't set any sleep time or modes.
ac->next.clean = false; // Turn off any Cleaning options if we can.
ac->next.clock = -1; // Don't set any current time if we can avoid it.
ac->next.power = false; // Initially start with the unit off.
Serial.println("Try to turn on & off every supported A/C type ...");
}
void doByInterval() {
// pv_last = pv;
}
IoTValue execute(String command, std::vector<IoTValue> &param) {
if (command == "on") {
ac->next.power = true; // Типа команда включить
ac->sendAc(); // Send the message.
SerialPrint("i", F("IRremote"), "Ballu AC on ");
}
if (command == "off") {
ac->next.power = false;
ac->sendAc(); // Send the message.
SerialPrint("i", F("IRremote"), "Ballu AC off ");
}
if (command == "cool") {
ac->next.mode = stdAc::opmode_t::kCool;
ac->sendAc(); // Send the message.
SerialPrint("i", F("IRremote"), "Ballu AC cool ");
}
if (command == "heat") {
ac->next.mode = stdAc::opmode_t::kHeat;
ac->sendAc(); // Send the message.
SerialPrint("i", F("IRremote"), "Ballu AC heat ");
}
if (command == "dry") {
ac->next.mode = stdAc::opmode_t::kDry;
ac->sendAc(); // Send the message.
SerialPrint("i", F("IRremote"), "Ballu AC dry ");
}
if (command == "auto") {
ac->next.fanspeed = stdAc::fanspeed_t::kAuto;
ac->sendAc(); // Send the message.
SerialPrint("i", F("IRremote"), "Ballu AC speed1 ");
}
if (command == "speedmin") {
ac->next.fanspeed = stdAc::fanspeed_t::kMin;
ac->sendAc(); // Send the message.
SerialPrint("i", F("IRremote"), "Ballu AC speed min ");
}
if (command == "speedlow") {
ac->next.fanspeed = stdAc::fanspeed_t::kLow;
ac->sendAc(); // Send the message.
SerialPrint("i", F("IRremote"), "Ballu AC speed low ");
}
if (command == "speedmed") {
ac->next.fanspeed = stdAc::fanspeed_t::kMedium; // Надо выбрать под конкретный кондиционер из 6-ти вариантов
ac->sendAc(); // Send the message.
SerialPrint("i", F("IRremote"), "Ballu AC speed medium ");
}
if (command == "speedhigh") {
ac->next.fanspeed = stdAc::fanspeed_t::kHigh; // Надо выбрать под конкретный кондиционер из 6-ти вариантов
ac->sendAc(); // Send the message.
SerialPrint("i", F("IRremote"), "Ballu AC speed high");
}
if (command == "speedmax") {
ac->next.fanspeed = stdAc::fanspeed_t::kMax; // Надо выбрать под конкретный кондиционер из 6-ти вариантов
ac->sendAc(); // Send the message.
SerialPrint("i", F("IRremote"), "Ballu AC speed max");
}
if (command == "speedmh") {
ac->next.fanspeed = stdAc::fanspeed_t::kMediumHigh; // Надо выбрать под конкретный кондиционер из 6-ти вариантов
ac->sendAc(); // Send the message.
SerialPrint("i", F("IRremote"), "Ballu AC speed mh");
}
//setTemp acc.setTemp(val)
if (command == "setTemp") {
// заданная температура
IoTItem *tmp = findIoTItem(_set_id);
if (tmp)
{
//interim = tmp->getValue();
_tmp = ::atof(tmp->getValue().c_str());
ac->next.degrees = _tmp; // set Temp 17 C - 30 C.
ac->sendAc(); // Send the message.
SerialPrint("i", F("IRremote"), "Ballu AC set temp -> " + String(_tmp) );
}
else
{
// если не заполнены настройки кондиционера
setValue("ошибка настройки кондиционера");
}
//ac->next.degrees = _tmp; // set Temp 17 C - 30 C.
//ac->sendAc(); // Send the message.
}
//ac->next.swingv = stdAc::swingv_t::kOff;
if (command == "swing") {
ac->next.swingv = stdAc::swingv_t::kMiddle;; // Надо выбрать под конкретный кондиционер из 6-ти вариантов
ac->sendAc(); // Send the message.
SerialPrint("i", F("IRremote"), "Ballu AC swing middle");
}
return {}; // команда поддерживает возвращаемое значения. Т.е. по итогу выполнения команды или общения с внешней системой, можно вернуть значение в сценарий для дальнейшей обработки
}
~IRremote() {};
};
void* getAPI_IRremote(String subtype, String param) {
if (subtype == F("IRremote")) {
return new IRremote(param);
} else {
return nullptr;
}
}

View File

@@ -0,0 +1,94 @@
{
"menuSection": "executive_devices",
"configItem": [{
"global": 0,
"name": "Управление кондиционером",
"type": "Reading",
"subtype": "IRremote",
"id": "ir",
"pinTx": 4,
"set_id": "",
"int": 1,
"prot": 15
}],
"about": {
"authorName": "Serghei Crasnicov",
"authorContact": "https://t.me/Serghei63",
"authorGit": "https://github.com/Serghei63",
"specialThanks": "Mikhail Bubnov https://t.me/Mit4bmw , Олег Астахов https://t.me/Threedreality , Valentin Khandriga @Valiuhaaa",
"moduleName": "IRremote",
"moduleVersion": "2.0",
"usedRam": {
"esp32_4mb": 15,
"esp8266_4mb": 15
},
"title": "Эмулятор IR пульта",
"moduleDesc": "Позволяет управлять кондиционером и другой техникой по IR каналу",
"propInfo": {
"pinTx": "GPIO номер, к которому подключен инфракрасный приемник.",
"prot": " Цифровой код протокола . UNKNOWN = -1, UNUSED = 0, COOLIX - 15, SAMSUNG_AC - 46 ....",
"set_id": "id установленной температуры"
},
"funcInfo": [
{
"name": "on",
"descr": "Включить конциционер",
"params": []
},
{
"name": "off",
"descr": "Выключить конциционер",
"params": []
},
{
"name": "cool",
"descr": "Режим охлаждения",
"params": []
},
{
"name": "heat",
"descr": "Режим нагрева",
"params": []
},
{
"name": "dry",
"descr": "Режим осушения",
"params": []
},
{
"name": "speed1",
"descr": "Медленная скорость вентилятора",
"params": []
},
{
"name": "speed2",
"descr": "Средняя скорость вентилятора",
"params": []
},
{
"name": "speed3",
"descr": "Максимальная скорость вентилятора",
"params": []
},
{
"name": "setTemp",
"descr": "Установленная температура",
"params": []
}
]
},
"defActive": false,
"usedLibs": {
"esp32*": [
"https://github.com/crankyoldgit/IRremoteESP8266"
],
"esp82*": [
"https://github.com/crankyoldgit/IRremoteESP8266"
]
}
}

View File

@@ -19,21 +19,21 @@ class Telegram : public IoTItem {
msg = deleteBeforeDelimiter(msg, "_");
generateOrder(selectToMarker(msg, "_"), selectToMarkerLast(msg, "_"));
_myBot.sendMessage(_chatID, "order done");
SerialPrint("<-", F("Telegram"), "chat ID: " + uint64ToString(_chatID) + ", msg: " + String(msg));
SerialPrint("<-", F("Telegram"), "chat ID: " + uint64ToStringIoTM(_chatID) + ", msg: " + String(msg));
} else if (msg.indexOf("get") != -1) {
msg = deleteBeforeDelimiter(msg, "_");
IoTItem* item = findIoTItem(msg);
if (item) {
_myBot.sendMessage(_chatID, item->getValue());
SerialPrint("<-", F("Telegram"), "chat ID: " + uint64ToString(_chatID) + ", msg: " + String(msg));
SerialPrint("<-", F("Telegram"), "chat ID: " + uint64ToStringIoTM(_chatID) + ", msg: " + String(msg));
}
} else if (msg.indexOf("all") != -1) {
String list = returnListOfParams();
_myBot.sendMessage(_chatID, list);
SerialPrint("<-", F("Telegram"), "chat ID: " + uint64ToString(_chatID) + "\n" + list);
SerialPrint("<-", F("Telegram"), "chat ID: " + uint64ToStringIoTM(_chatID) + "\n" + list);
} else if (msg.indexOf("help") != -1) {
_myBot.sendMessage(_chatID, "ID: " + chipId);
_myBot.sendMessage(_chatID, "chatID: " + uint64ToString(_chatID));
_myBot.sendMessage(_chatID, "chatID: " + uint64ToStringIoTM(_chatID));
_myBot.sendMessage(_chatID, F("Wrong order, use /all to get all values, /get_id to get value, or /set_id_value to set value"));
} else {
setValue(msg);
@@ -70,7 +70,7 @@ class Telegram : public IoTItem {
if (_receiveMsg) {
TBMessage msg;
if (_myBot.getNewMessage(msg)) {
SerialPrint("->", F("Telegram"), "chat ID: " + uint64ToString(msg.sender.id) + ", msg: " + msg.text);
SerialPrint("->", F("Telegram"), "chat ID: " + uint64ToStringIoTM(msg.sender.id) + ", msg: " + msg.text);
if (_autos) {
_chatID = msg.sender.id;
}
@@ -100,12 +100,12 @@ class Telegram : public IoTItem {
void sendTelegramMsg(bool often, String msg) {
if (often) {
_myBot.sendMessage(_chatID, msg);
SerialPrint("<-", F("Telegram"), "chat ID: " + uint64ToString(_chatID) + ", msg: " + msg);
SerialPrint("<-", F("Telegram"), "chat ID: " + uint64ToStringIoTM(_chatID) + ", msg: " + msg);
} else {
if (_prevMsg != msg) {
_prevMsg = msg;
_myBot.sendMessage(_chatID, msg);
SerialPrint("<-", F("Telegram"), "chat ID: " + uint64ToString(_chatID) + ", msg: " + msg);
SerialPrint("<-", F("Telegram"), "chat ID: " + uint64ToStringIoTM(_chatID) + ", msg: " + msg);
}
}
}

View File

@@ -14,14 +14,14 @@ void scanI2C() {
if (error == 0){
message += "I2C device found at address 0x";
message += uint64ToString(address, 16);
message += uint64ToStringIoTM(address, 16);
message += " !";
nDevices++;
}
else if (error==4) {
message += "Unknow error at address 0x";
message += uint64ToString(address, 16);
message += uint64ToStringIoTM(address, 16);
}
}
if (nDevices == 0)

View File

@@ -183,7 +183,7 @@ String prettyBytes(size_t size) {
return String(size / 1024.0 / 1024.0 / 1024.0) + "GB";
}
String uint64ToString(uint64_t input, uint8_t base) {
String uint64ToStringIoTM(uint64_t input, uint8_t base) {
String result = "";
do {