| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- #include <Arduino.h> // needed for PlatformIO
- #include <Mesh.h>
- #include "MyMesh.h"
- // Believe it or not, this std C function is busted on some platforms!
- static uint32_t _atoi(const char* sp) {
- uint32_t n = 0;
- while (*sp && *sp >= '0' && *sp <= '9') {
- n *= 10;
- n += (*sp++ - '0');
- }
- return n;
- }
- #if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
- #include <InternalFileSystem.h>
- #elif defined(RP2040_PLATFORM)
- #include <LittleFS.h>
- #elif defined(ESP32)
- #include <SPIFFS.h>
- #endif
- #ifdef ESP32
- #ifdef WIFI_SSID
- #include <helpers/esp32/SerialWifiInterface.h>
- SerialWifiInterface serial_interface;
- #ifndef TCP_PORT
- #define TCP_PORT 5000
- #endif
- #elif defined(BLE_PIN_CODE)
- #include <helpers/esp32/SerialBLEInterface.h>
- SerialBLEInterface serial_interface;
- #elif defined(SERIAL_RX)
- #include <helpers/ArduinoSerialInterface.h>
- ArduinoSerialInterface serial_interface;
- HardwareSerial companion_serial(1);
- #else
- #include <helpers/ArduinoSerialInterface.h>
- ArduinoSerialInterface serial_interface;
- #endif
- #elif defined(RP2040_PLATFORM)
- //#ifdef WIFI_SSID
- // #include <helpers/rp2040/SerialWifiInterface.h>
- // SerialWifiInterface serial_interface;
- // #ifndef TCP_PORT
- // #define TCP_PORT 5000
- // #endif
- // #elif defined(BLE_PIN_CODE)
- // #include <helpers/rp2040/SerialBLEInterface.h>
- // SerialBLEInterface serial_interface;
- #if defined(SERIAL_RX)
- #include <helpers/ArduinoSerialInterface.h>
- ArduinoSerialInterface serial_interface;
- HardwareSerial companion_serial(1);
- #else
- #include <helpers/ArduinoSerialInterface.h>
- ArduinoSerialInterface serial_interface;
- #endif
- #elif defined(NRF52_PLATFORM)
- #ifdef BLE_PIN_CODE
- #include <helpers/nrf52/SerialBLEInterface.h>
- SerialBLEInterface serial_interface;
- #else
- #include <helpers/ArduinoSerialInterface.h>
- ArduinoSerialInterface serial_interface;
- #endif
- #elif defined(STM32_PLATFORM)
- #include <helpers/ArduinoSerialInterface.h>
- ArduinoSerialInterface serial_interface;
- #else
- #error "need to define a serial interface"
- #endif
- /* GLOBAL OBJECTS */
- StdRNG fast_rng;
- SimpleMeshTables tables;
- MyMesh the_mesh(radio_driver, fast_rng, rtc_clock, tables);
- #ifdef DISPLAY_CLASS
- #include "UITask.h"
- UITask ui_task(&board);
- #endif
- /* END GLOBAL OBJECTS */
- void halt() {
- while (1) ;
- }
- void setup() {
- Serial.begin(115200);
- board.begin();
- #ifdef DISPLAY_CLASS
- DisplayDriver* disp = NULL;
- if (display.begin()) {
- disp = &display;
- disp->startFrame();
- disp->print("Please wait...");
- disp->endFrame();
- }
- #endif
- if (!radio_init()) { halt(); }
- fast_rng.begin(radio_get_rng_seed());
- #if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
- InternalFS.begin();
- the_mesh.begin(InternalFS,
- #ifdef DISPLAY_CLASS
- disp != NULL
- #else
- false
- #endif
- );
- #ifdef BLE_PIN_CODE
- char dev_name[32+16];
- sprintf(dev_name, "%s%s", BLE_NAME_PREFIX, the_mesh.getNodeName());
- serial_interface.begin(dev_name, the_mesh.getBLEPin());
- #else
- serial_interface.begin(Serial);
- #endif
- the_mesh.startInterface(serial_interface);
- #elif defined(RP2040_PLATFORM)
- LittleFS.begin();
- the_mesh.begin(LittleFS,
- #ifdef DISPLAY_CLASS
- disp != NULL
- #else
- false
- #endif
- );
- //#ifdef WIFI_SSID
- // WiFi.begin(WIFI_SSID, WIFI_PWD);
- // serial_interface.begin(TCP_PORT);
- // #elif defined(BLE_PIN_CODE)
- // char dev_name[32+16];
- // sprintf(dev_name, "%s%s", BLE_NAME_PREFIX, the_mesh.getNodeName());
- // serial_interface.begin(dev_name, the_mesh.getBLEPin());
- #if defined(SERIAL_RX)
- companion_serial.setPins(SERIAL_RX, SERIAL_TX);
- companion_serial.begin(115200);
- serial_interface.begin(companion_serial);
- #else
- serial_interface.begin(Serial);
- #endif
- the_mesh.startInterface(serial_interface);
- #elif defined(ESP32)
- SPIFFS.begin(true);
- the_mesh.begin(SPIFFS,
- #ifdef DISPLAY_CLASS
- disp != NULL
- #else
- false
- #endif
- );
- #ifdef WIFI_SSID
- WiFi.begin(WIFI_SSID, WIFI_PWD);
- serial_interface.begin(TCP_PORT);
- #elif defined(BLE_PIN_CODE)
- char dev_name[32+16];
- sprintf(dev_name, "%s%s", BLE_NAME_PREFIX, the_mesh.getNodeName());
- serial_interface.begin(dev_name, the_mesh.getBLEPin());
- #elif defined(SERIAL_RX)
- companion_serial.setPins(SERIAL_RX, SERIAL_TX);
- companion_serial.begin(115200);
- serial_interface.begin(companion_serial);
- #else
- serial_interface.begin(Serial);
- #endif
- the_mesh.startInterface(serial_interface);
- #else
- #error "need to define filesystem"
- #endif
- sensors.begin();
- #ifdef DISPLAY_CLASS
- ui_task.begin(disp, the_mesh.getNodePrefs(), FIRMWARE_BUILD_DATE, FIRMWARE_VERSION, the_mesh.getBLEPin());
- #endif
- }
- void loop() {
- the_mesh.loop();
- sensors.loop();
- }
|