diff --git a/lib/comms/comms.cpp b/lib/comms/comms.cpp index 19e66fb..53781b3 100644 --- a/lib/comms/comms.cpp +++ b/lib/comms/comms.cpp @@ -43,28 +43,38 @@ void _onReceive1() Comms1->_onReceive(); } +#if ARDUINO_USB_MODE +#define IF_CDC_EVENT(e, data) \ + arduino_hw_cdc_event_data_t *data = (arduino_hw_cdc_event_data_t *)event_data; \ + if (event_base == ARDUINO_HW_CDC_EVENTS && event_id == ARDUINO_HW_CDC_##e) +#else +#define IF_CDC_EVENT(e, data) \ + arduino_usb_cdc_event_data_t *data = (arduino_usb_cdc_event_data_t *)event_data; \ + if (event_base == ARDUINO_USB_CDC_EVENTS && event_id == ARDUINO_USB_CDC_##e) +#endif + void _onUsbEvent0(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data) { - if (event_base == ARDUINO_HW_CDC_EVENTS) - { - arduino_hw_cdc_event_data_t *data = (arduino_hw_cdc_event_data_t *)event_data; - if (event_id == ARDUINO_HW_CDC_RX_EVENT) - { - _onReceiveUsb(data->rx.len); - } - } + IF_CDC_EVENT(RX_EVENT, data) { _onReceiveUsb(data->rx.len); } } bool Comms::initComms(Config &c) { bool fine = false; -#ifndef HELTEC + +#ifdef ARDUINO_USB_CDC_ON_BOOT if (c.listen_on_usb.equalsIgnoreCase("readline")) { // comms using readline plaintext protocol HostComms = new ReadlineComms("Host", Serial); +#if ARDUINO_USB_MODE + // if Serial is HWCDC... Serial.onEvent(ARDUINO_HW_CDC_RX_EVENT, _onUsbEvent0); +#else + // if Serial is USBCDC... + Serial.onEvent(ARDUINO_USB_CDC_RX_EVENT, _onUsbEvent0); +#endif Serial.begin(); Serial.println("Initialized communications on Serial using readline protocol"); diff --git a/lib/comms/comms.h b/lib/comms/comms.h index 455a8d4..b852a06 100644 --- a/lib/comms/comms.h +++ b/lib/comms/comms.h @@ -7,7 +7,7 @@ #include #include -#ifdef HELTEC +#ifndef ARDUINO_USB_CDC_ON_BOOT #define SERIAL0 Serial #else #define SERIAL0 Serial0 diff --git a/lib/config/config.cpp b/lib/config/config.cpp index cb46edd..2b2ec69 100644 --- a/lib/config/config.cpp +++ b/lib/config/config.cpp @@ -384,21 +384,22 @@ LoRaConfig *configureLora(String cfg) } String k = param.substring(0, j); + param = param.substring(j + 1); if (k.equalsIgnoreCase("sync_word")) { - lora->sync_word = (uint8_t)fromHex(param.substring(j + 1)); + lora->sync_word = (uint8_t)fromHex(param); continue; } - int v = param.substring(j + 1).toInt(); - if (k.equalsIgnoreCase("freq")) { - lora->freq = (uint16_t)v; + lora->freq = param.toFloat(); continue; } + int v = param.toInt(); + if (k.equalsIgnoreCase("bw")) { lora->bw = (uint16_t)v; diff --git a/lib/config/config.h b/lib/config/config.h index b4f32f6..770f7ac 100644 --- a/lib/config/config.h +++ b/lib/config/config.h @@ -12,7 +12,7 @@ struct ScanRange struct LoRaConfig { - uint16_t freq; + float freq; uint16_t bw; uint8_t sf; uint8_t cr; diff --git a/platformio.ini b/platformio.ini index 5723634..6696f87 100644 --- a/platformio.ini +++ b/platformio.ini @@ -34,6 +34,8 @@ lib_deps = build_flags = -DHELTEC_POWER_BUTTON -DHELTEC + -DARDUINO_USB_CDC_ON_BOOT=1 + -DARDUINO_USB_MODE=1 [env:heltec_wifi_lora_32_V3-OSD] platform = espressif32