From b2b51b757ed53571ee5290a848af66a240c660ef Mon Sep 17 00:00:00 2001 From: proddy Date: Tue, 4 Aug 2020 15:44:17 +0200 Subject: [PATCH] rename gpio to pin command - #445 --- README.md | 6 +++--- src/locale_EN.h | 4 ++-- src/mqtt.cpp | 2 +- src/system.cpp | 22 +++++++--------------- src/system.h | 2 +- src/test/test.cpp | 14 +++++++------- 6 files changed, 21 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 7348439f..c160e051 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,7 @@ system set wifi password set wifi ssid wifi reconnect - gpio [data] + pin [data] boiler read @@ -150,9 +150,9 @@ commands must be written as `{"cmd": ,"data":, "id": }`. The `id` holiday date -*cmd* +*system_cmd* send <"0B XX XX .."> - gpio <0 | 1> <0-3> (for D0-D3) + pin ``` diff --git a/src/locale_EN.h b/src/locale_EN.h index 13b29c83..5738a5e8 100644 --- a/src/locale_EN.h +++ b/src/locale_EN.h @@ -62,7 +62,7 @@ MAKE_PSTR_WORD(heartbeat) MAKE_PSTR_WORD(users) MAKE_PSTR_WORD(master) MAKE_PSTR_WORD(test) -MAKE_PSTR_WORD(gpio) +MAKE_PSTR_WORD(pin) // for commands MAKE_PSTR_WORD(call) @@ -104,7 +104,7 @@ MAKE_PSTR(degrees, "°C") MAKE_PSTR(asterisks, "********") MAKE_PSTR(n_mandatory, "") MAKE_PSTR(n_optional, "[n]") -MAKE_PSTR(pin_mandatory, "") +MAKE_PSTR(gpio_mandatory, "") MAKE_PSTR(data_optional, "[data]") MAKE_PSTR(typeid_mandatory, "") MAKE_PSTR(deviceid_mandatory, "") diff --git a/src/mqtt.cpp b/src/mqtt.cpp index 3b7e6ce1..bd5cf023 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -432,7 +432,7 @@ void Mqtt::on_connect() { // add the system MQTT subscriptions, only if its a fresh start with no previous subscriptions // these commands respond to the topic "system_cmd" and take a payload like {cmd:"", data:"", id:""} if (mqtt_subfunctions_.empty()) { - add_command(EMSdevice::DeviceType::SERVICEKEY, F("gpio"), System::mqtt_command_gpio); + add_command(EMSdevice::DeviceType::SERVICEKEY, F("pin"), System::mqtt_command_pin); add_command(EMSdevice::DeviceType::SERVICEKEY, F("send"), System::mqtt_command_send); } diff --git a/src/system.cpp b/src/system.cpp index efeb4a47..371bf4e7 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -36,20 +36,12 @@ bool System::upload_status_ = false; // send on/off to a gpio pin // value: true = HIGH, false = LOW -void System::mqtt_command_gpio(const char * value, const int8_t id) { -#if defined(ESP8266) - const uint8_t pins[] = {16, 5, 4, 0}; -#elif defined(ESP32) - const uint8_t pins[] = {26, 22, 21, 17}; -#else - const uint8_t pins[] = {11, 12, 13, 14}; -#endif +void System::mqtt_command_pin(const char * value, const int8_t id) { bool v = false; if (Helpers::value2bool(value, v)) { - uint8_t gpio = pins[id]; // D0 - D3 - pinMode(gpio, OUTPUT); - digitalWrite(gpio, v); - LOG_INFO(F("Port D%d set to %s"), id, v ? "HIGH" : "LOW"); + pinMode(id, OUTPUT); + digitalWrite(id, v); + LOG_INFO(F("GPIO %d set to %s"), id, v ? "HIGH" : "LOW"); } } @@ -559,8 +551,8 @@ void System::console_commands(Shell & shell, unsigned int context) { EMSESPShell::commands->add_command(ShellContext::SYSTEM, CommandFlags::ADMIN, - flash_string_vector{F_(gpio)}, - flash_string_vector{F_(pin_mandatory), F_(data_optional)}, + flash_string_vector{F_(pin)}, + flash_string_vector{F_(gpio_mandatory), F_(data_optional)}, [](Shell & shell, const std::vector & arguments) { if (arguments.size() == 1) { shell.printfln(F("use on/off, 1/0 or true/false")); @@ -568,7 +560,7 @@ void System::console_commands(Shell & shell, unsigned int context) { } int pin = 0; if (Helpers::value2number(arguments[0].c_str(), pin)) { - System::mqtt_command_gpio(arguments[1].c_str(), pin); + System::mqtt_command_pin(arguments[1].c_str(), pin); } }); diff --git a/src/system.h b/src/system.h index 541e5df7..b594308e 100644 --- a/src/system.h +++ b/src/system.h @@ -50,7 +50,7 @@ class System { static void console_commands(Shell & shell, unsigned int context); - static void mqtt_command_gpio(const char * value, const int8_t id); + static void mqtt_command_pin(const char * value, const int8_t id); static void mqtt_command_send(const char * value, const int8_t id); static uint8_t free_mem(); diff --git a/src/test/test.cpp b/src/test/test.cpp index d64e443c..85e36d14 100644 --- a/src/test/test.cpp +++ b/src/test/test.cpp @@ -480,15 +480,15 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & command) { EMSESP::txservice_.flush_tx_queue(); } - if (command == "gpio") { - shell.printfln(F("Testing gpio...")); + if (command == "pin") { + shell.printfln(F("Testing pin...")); EMSESP::add_context_menus(); // need to add this as it happens later in the code shell.invoke_command("su"); shell.invoke_command("system"); shell.invoke_command("help"); - shell.invoke_command("gpio"); - shell.invoke_command("gpio 1 true"); + shell.invoke_command("pin"); + shell.invoke_command("pin 1 true"); shell.loop_all(); } @@ -550,12 +550,12 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & command) { strcpy(payload, "{\"cmd\":\"flowtemp\",\"data\":55}"); EMSESP::mqtt_.incoming(topic, payload); - strcpy(topic, "ems-esp/system"); + strcpy(topic, "ems-esp/system_cmd"); strcpy(payload, "{\"cmd\":\"send\",\"data\":\"01 02 03 04 05\"}"); EMSESP::mqtt_.incoming(topic, payload); - strcpy(topic, "ems-esp/system"); - strcpy(payload, "{\"cmd\":\"gpio\",\"id\":1,\"data\":\"1\"}"); + strcpy(topic, "ems-esp/system_cmd"); + strcpy(payload, "{\"cmd\":\"pin\",\"id\":12,\"data\":\"1\"}"); EMSESP::mqtt_.incoming(topic, payload); strcpy(topic, "ems-esp/thermostat_cmd");