diff --git a/firmware/esp32/gdoor/main.cpp b/firmware/esp32/gdoor/main.cpp index eb2a465..985d2eb 100644 --- a/firmware/esp32/gdoor/main.cpp +++ b/firmware/esp32/gdoor/main.cpp @@ -20,10 +20,6 @@ #include "src/wifi_helper.h" #include "src/printer_helper.h" -#define PIN_RX 12 -#define PIN_TX 25 -#define PIN_TX_EN 27 - boolean debug = false; // Global variable to indicate if we are in debug mode (true) const char* mqtt_topic_bus_rx = NULL; @@ -65,14 +61,22 @@ void setup() { Serial.begin(115200); Serial.setTimeout(1); JSONDEBUG("GDOOR Setup start"); - GDOOR::setup(PIN_TX, PIN_TX_EN, PIN_RX); + WIFI_HELPER::setup(); + + GDOOR::setRxThreshold(PIN_RX_THRESH, WIFI_HELPER::rx_sensitivity()); + GDOOR::setup(PIN_TX, PIN_TX_EN, WIFI_HELPER::rx_pin()); + MQTT_HELPER::setup(WIFI_HELPER::mqtt_server(), WIFI_HELPER::mqtt_port(), WIFI_HELPER::mqtt_user(), WIFI_HELPER::mqtt_password(), WIFI_HELPER::mqtt_topic_bus_tx()); mqtt_topic_bus_rx = WIFI_HELPER::mqtt_topic_bus_rx(); debug = WIFI_HELPER::debug(); JSONDEBUG("GDOOR Setup done"); + JSONDEBUG("RX Pin: "); + JSONDEBUG(WIFI_HELPER::rx_pin()); + JSONDEBUG("RX Sensitivity: "); + JSONDEBUG(WIFI_HELPER::rx_sensitivity()); } void loop() { diff --git a/firmware/esp32/gdoor/src/defines.h b/firmware/esp32/gdoor/src/defines.h index fa305d3..03789bf 100644 --- a/firmware/esp32/gdoor/src/defines.h +++ b/firmware/esp32/gdoor/src/defines.h @@ -49,4 +49,37 @@ #define DEFAULT_MQTT_TOPIC_BUS_RX "gdoor/bus_rx" #define DEFAULT_MQTT_TOPIC_BUS_TX "gdoor/bus_tx" +// Settings + +#define PIN_TX 25 +#define PIN_TX_EN 27 +#define PIN_RX_THRESH 26 + +// RX Pin Settings +#define RX_PIN_22_NAME "v3.1 adjustable (IO22)" +#define RX_PIN_22_NUM 22 + +#define RX_PIN_21_NAME "v3.1 (IO21)" +#define RX_PIN_21_NUM 21 + +#define RX_PIN_12_NAME "v3.0 bugfix (IO12)" +#define RX_PIN_12_NUM 12 + +#define RX_PIN_32_NAME "v3.0 (IO32)" +#define RX_PIN_32_NUM 32 + +#define RX_PIN_CHOICES {RX_PIN_22_NAME, RX_PIN_21_NAME, RX_PIN_12_NAME, RX_PIN_32_NAME} +#define RX_PIN_CHOICES_LEN 4 + +// RX Pin Sensitivity (only working for RX PIN22) +#define RX_SENS_LOW_NAME "Low (1.3V)" +#define RX_SENS_LOW_NUM 1.3 +#define RX_SENS_MED_NAME "Med (1.45V)" +#define RX_SENS_MED_NUM 1.45 +#define RX_SENS_HIGH_NAME "High (1.65V)" +#define RX_SENS_HIGH_NUM 1.65 + +#define RX_SENS_CHOICES {RX_SENS_HIGH_NAME, RX_SENS_MED_NAME, RX_SENS_LOW_NAME} +#define RX_SENS_CHOICES_LEN 3 + #endif \ No newline at end of file diff --git a/firmware/esp32/gdoor/src/gdoor.cpp b/firmware/esp32/gdoor/src/gdoor.cpp index 1836745..9d93790 100644 --- a/firmware/esp32/gdoor/src/gdoor.cpp +++ b/firmware/esp32/gdoor/src/gdoor.cpp @@ -68,4 +68,12 @@ namespace GDOOR { bool active() { return (GDOOR_TX::tx_state != 0 || GDOOR_RX::rx_state != 0); } + + /** Set RX Threshold (Sensitivity) to a certain level, + * only working for IO22 rx input on v3.1 hardware + */ + void setRxThreshold(uint8_t pin, float sensitivity) { + uint8_t value = (uint8_t)((sensitivity/3.3)*255); + dacWrite(pin, value); + } } \ No newline at end of file diff --git a/firmware/esp32/gdoor/src/gdoor.h b/firmware/esp32/gdoor/src/gdoor.h index 45ed8a4..037b1a8 100644 --- a/firmware/esp32/gdoor/src/gdoor.h +++ b/firmware/esp32/gdoor/src/gdoor.h @@ -30,6 +30,7 @@ namespace GDOOR { //Namespace as we can only use it once void send(uint8_t *data, uint16_t len); void send(String str); bool active(); + void setRxThreshold(uint8_t pin, float sensitivity); }; #endif \ No newline at end of file diff --git a/firmware/esp32/gdoor/src/wifi_helper.cpp b/firmware/esp32/gdoor/src/wifi_helper.cpp index 2f8d380..b89f210 100644 --- a/firmware/esp32/gdoor/src/wifi_helper.cpp +++ b/firmware/esp32/gdoor/src/wifi_helper.cpp @@ -154,7 +154,8 @@ class NullableParameter : public WiFiManagerParameter { namespace WIFI_HELPER { //Namespace as we can only use it once bool shouldSaveConfig = false; - + const char* rx_pin_select_values[] = RX_PIN_CHOICES; + const char* rx_sensitivity_select_values[] = RX_SENS_CHOICES; MyCustomWifiManager wifiManager; WiFiManagerParameter custom_mqtt_server("mqtt_server", "MQTT Server", DEFAULT_MQTT_SERVER, 40); @@ -164,6 +165,8 @@ namespace WIFI_HELPER { //Namespace as we can only use it once WiFiManagerParameter custom_mqtt_topic_bus_rx("mqtt_topic_bus_rx", "MQTT Topic - from bus", DEFAULT_MQTT_TOPIC_BUS_RX, 40); WiFiManagerParameter custom_mqtt_topic_bus_tx("mqtt_topic_bus_tx", "MQTT Topic - to bus", DEFAULT_MQTT_TOPIC_BUS_TX, 40); EnableDisableParameter custom_debug("param_6", "Debug Mode"); //param_4 is a very ugly workaround for stupid WifiManager custom fields implementation. Works only with param_ + CheckSelectParameter custom_rx_pin("param_7", "RX Input", rx_pin_select_values, RX_PIN_CHOICES_LEN, 40); + CheckSelectParameter custom_rx_sens("param_8", "IO22 Sensitivity", rx_sensitivity_select_values, RX_SENS_CHOICES_LEN, 40); /** * Internal function which creates and writes a file to LittleFS. @@ -236,6 +239,35 @@ namespace WIFI_HELPER { //Namespace as we can only use it once return strcmp(custom_debug.getValue(), "enabled") == 0; } + /** Returns io number of select RX method*/ + uint8_t rx_pin() { + const char* value = custom_rx_pin.getValue(); + + if(!strcmp(value, RX_PIN_22_NAME)) { + return RX_PIN_22_NUM; + } else if(!strcmp(value, RX_PIN_21_NAME)) { + return RX_PIN_21_NUM; + } else if(!strcmp(value, RX_PIN_12_NAME)) { + return RX_PIN_12_NUM; + } else if(!strcmp(value, RX_PIN_32_NAME)) { + return RX_PIN_32_NUM; + } + return RX_PIN_22_NUM; + } + + /** Returns DAC value for RX comparator*/ + float rx_sensitivity() { + const char* value = custom_rx_sens.getValue(); + if(!strcmp(value, RX_SENS_LOW_NAME)) { + return RX_SENS_LOW_NUM; + } else if(!strcmp(value, RX_SENS_MED_NAME)) { + return RX_SENS_MED_NUM; + } else if(!strcmp(value, RX_SENS_HIGH_NAME)) { + return RX_SENS_HIGH_NUM; + } + return RX_SENS_MED_NUM; + } + void setup() { String filevalue; @@ -269,6 +301,14 @@ namespace WIFI_HELPER { //Namespace as we can only use it once custom_debug.setValue(filevalue.c_str(), 10); } + if (read_config_file("/custom_rx_pin", &filevalue) && filevalue.length() > 0 ) { + custom_rx_pin.setValue(filevalue.c_str(), 40); + } + + if (read_config_file("/custom_rx_sens", &filevalue) && filevalue.length() > 0 ) { + custom_rx_sens.setValue(filevalue.c_str(), 40); + } + LittleFS.end(); } else { JSONPRINT("Could not mount filesystem on load"); @@ -283,9 +323,12 @@ namespace WIFI_HELPER { //Namespace as we can only use it once wifiManager.addParameter(&custom_mqtt_password); wifiManager.addParameter(&custom_mqtt_topic_bus_rx); wifiManager.addParameter(&custom_mqtt_topic_bus_tx); - + wifiManager.addParameter(&custom_debug); + wifiManager.addParameter(&custom_rx_pin); + wifiManager.addParameter(&custom_rx_sens); + wifiManager.setSaveConfigCallback(on_save); wifiManager.setSaveParamsCallback(on_save); @@ -316,6 +359,8 @@ namespace WIFI_HELPER { //Namespace as we can only use it once save_config_file("/custom_mqtt_topic_bus_rx", custom_mqtt_topic_bus_rx.getValue()); save_config_file("/custom_mqtt_topic_bus_tx", custom_mqtt_topic_bus_tx.getValue()); save_config_file("/custom_debug", custom_debug.getValue()); + save_config_file("/custom_rx_pin", custom_rx_pin.getValue()); + save_config_file("/custom_rx_sens", custom_rx_sens.getValue()); LittleFS.end(); ESP.restart(); } else { diff --git a/firmware/esp32/gdoor/src/wifi_helper.h b/firmware/esp32/gdoor/src/wifi_helper.h index 86b5bff..2e4179f 100644 --- a/firmware/esp32/gdoor/src/wifi_helper.h +++ b/firmware/esp32/gdoor/src/wifi_helper.h @@ -16,8 +16,8 @@ */ #ifndef WIFI_H - #define WIFI_H +#include #define GDOOR_LOGO ("") @@ -31,6 +31,8 @@ namespace WIFI_HELPER { //Namespace as we can only use it once const char* mqtt_topic_bus_rx(); const char* mqtt_topic_bus_tx(); bool debug(); + uint8_t rx_pin(); + float rx_sensitivity(); }; #endif \ No newline at end of file diff --git a/hardware/esp32/esp32.kicad_pro b/hardware/esp32/esp32.kicad_pro index 8fcc4a5..5f35ae7 100644 --- a/hardware/esp32/esp32.kicad_pro +++ b/hardware/esp32/esp32.kicad_pro @@ -451,7 +451,7 @@ "idf": "", "netlist": "", "specctra_dsn": "", - "step": "", + "step": "esp32.step", "vrml": "" }, "page_layout_descr_file": ""