From c74575e0e9e35a058b061bb8975b98544815d6b2 Mon Sep 17 00:00:00 2001 From: Andrey Klimov Date: Sun, 3 Mar 2019 15:42:54 +0300 Subject: [PATCH] Improve multiplatform building stuff --- check_custom_build_flags_controllino.sh | 1 + check_custom_build_flags_due-5500.sh | 1 + check_custom_build_flags_due.sh | 1 + check_custom_build_flags_esp32.sh | 5 ++ check_custom_build_flags_esp8266.sh | 1 + check_custom_build_flags_mega2560-net.sh | 1 + check_custom_build_flags_mega2560.sh | 3 +- check_custom_build_flags_nrf52840.sh | 8 ++ check_custom_build_flags_stm32.sh | 4 + lighthub/main.cpp | 57 ++++++------ lighthub/main.h | 105 ++++++++++++----------- lighthub/options.h | 4 + lighthub/utils.cpp | 64 +++++++++++++- lighthub/utils.h | 1 + platformio.ini | 83 +++++++----------- 15 files changed, 211 insertions(+), 128 deletions(-) diff --git a/check_custom_build_flags_controllino.sh b/check_custom_build_flags_controllino.sh index c0411cc..801e919 100755 --- a/check_custom_build_flags_controllino.sh +++ b/check_custom_build_flags_controllino.sh @@ -1,6 +1,7 @@ #! /bin/bash export FLAGS="$FLAGS -DCONTROLLINO" export FLAGS="$FLAGS -DCUSTOM_FIRMWARE_MAC=de:ad:be:ef:fe:07" +export FLAGS="$FLAGS -DPIO_SRC_REV="$(git log --pretty=format:%h_%ad -1 --date=short) CUSTOM_BUILD_FLAGS_FILE=custom-build-flags/build_flags_controllino.sh if [ -f $CUSTOM_BUILD_FLAGS_FILE ]; then source $CUSTOM_BUILD_FLAGS_FILE diff --git a/check_custom_build_flags_due-5500.sh b/check_custom_build_flags_due-5500.sh index c03a0ac..74ef7ea 100755 --- a/check_custom_build_flags_due-5500.sh +++ b/check_custom_build_flags_due-5500.sh @@ -1,6 +1,7 @@ #! /bin/bash export FLAGS="$FLAGS -DWiz5500" export FLAGS="$FLAGS -DARTNET_ENABLE" +export FLAGS="$FLAGS -DPIO_SRC_REV="$(git log --pretty=format:%h_%ad -1 --date=short) CUSTOM_BUILD_FLAGS_FILE=custom-build-flags/build_flags_due-5500.sh if [ -f $CUSTOM_BUILD_FLAGS_FILE ]; then source $CUSTOM_BUILD_FLAGS_FILE diff --git a/check_custom_build_flags_due.sh b/check_custom_build_flags_due.sh index 75bf199..99d4ada 100755 --- a/check_custom_build_flags_due.sh +++ b/check_custom_build_flags_due.sh @@ -1,4 +1,5 @@ #! /bin/bash +export FLAGS="$FLAGS -DPIO_SRC_REV="$(git log --pretty=format:%h_%ad -1 --date=short) CUSTOM_BUILD_FLAGS_FILE=custom-build-flags/build_flags_due.sh if [ -f $CUSTOM_BUILD_FLAGS_FILE ]; then source $CUSTOM_BUILD_FLAGS_FILE diff --git a/check_custom_build_flags_esp32.sh b/check_custom_build_flags_esp32.sh index 093eabc..14db68b 100755 --- a/check_custom_build_flags_esp32.sh +++ b/check_custom_build_flags_esp32.sh @@ -1,4 +1,9 @@ #! /bin/bash +export FLAGS="$FLAGS -DPIO_SRC_REV="$(git log --pretty=format:%h_%ad -1 --date=short) +export FLAGS="$FLAGS -DDMX_DISABLE" +export FLAGS="$FLAGS -DMODBUS_DISABLE" +export FLAGS="$FLAGS -DOWIRE_DISABLE" +#export FLAGS="$FLAGS -std=gnu++11" CUSTOM_BUILD_FLAGS_FILE=custom-build-flags/build_flags_esp32.sh if [ -f $CUSTOM_BUILD_FLAGS_FILE ]; then source $CUSTOM_BUILD_FLAGS_FILE diff --git a/check_custom_build_flags_esp8266.sh b/check_custom_build_flags_esp8266.sh index 0e15b05..ef6d14a 100755 --- a/check_custom_build_flags_esp8266.sh +++ b/check_custom_build_flags_esp8266.sh @@ -1,5 +1,6 @@ #! /bin/bash export FLAGS="$FLAGS -DMODBUS_DISABLE" +export FLAGS="$FLAGS -DPIO_SRC_REV="$(git log --pretty=format:%h_%ad -1 --date=short) CUSTOM_BUILD_FLAGS_FILE=custom-build-flags/build_flags_esp8266.sh if [ -f $CUSTOM_BUILD_FLAGS_FILE ]; then source $CUSTOM_BUILD_FLAGS_FILE diff --git a/check_custom_build_flags_mega2560-net.sh b/check_custom_build_flags_mega2560-net.sh index af70285..035a64b 100755 --- a/check_custom_build_flags_mega2560-net.sh +++ b/check_custom_build_flags_mega2560-net.sh @@ -1,5 +1,6 @@ #! /bin/bash CUSTOM_BUILD_FLAGS_FILE=custom-build-flags/build_flags_mega2560-net.sh +export FLAGS="$FLAGS -DPIO_SRC_REV="$(git log --pretty=format:%h_%ad -1 --date=short) if [ -f $CUSTOM_BUILD_FLAGS_FILE ]; then source $CUSTOM_BUILD_FLAGS_FILE fi diff --git a/check_custom_build_flags_mega2560.sh b/check_custom_build_flags_mega2560.sh index acfe945..59a98bc 100755 --- a/check_custom_build_flags_mega2560.sh +++ b/check_custom_build_flags_mega2560.sh @@ -1,7 +1,6 @@ #! /bin/bash CUSTOM_BUILD_FLAGS_FILE="custom-build-flags/build_flags_mega2560.sh" -#CUSTOM_BUILD_FLAGS_FILE="custom-build-flags/build_flags_$PIOENV.sh" -#echo $PIOENV > custom-build-flags/1.txt +export FLAGS="$FLAGS -DPIO_SRC_REV="$(git log --pretty=format:%h_%ad -1 --date=short) #TODO: make one file for all envs if [ -f $CUSTOM_BUILD_FLAGS_FILE ]; then source $CUSTOM_BUILD_FLAGS_FILE diff --git a/check_custom_build_flags_nrf52840.sh b/check_custom_build_flags_nrf52840.sh index f48c2b0..9770f37 100755 --- a/check_custom_build_flags_nrf52840.sh +++ b/check_custom_build_flags_nrf52840.sh @@ -1,5 +1,13 @@ #! /bin/bash export FLAGS="$FLAGS -DWiz5500" +export FLAGS="$FLAGS -DPIO_SRC_REV="$(git log --pretty=format:%h_%ad -1 --date=short) +export FLAGS="$FLAGS -DDMX_DISABLE" +export FLAGS="$FLAGS -DMODBUS_DISABLE" +export FLAGS="$FLAGS -DOWIRE_DISABLE" +export FLAGS="$FLAGS -std=gnu++11" +export FLAGS="$FLAGS -DWIFI_MANAGER_DISABLE" +export FLAGS="$FLAGS -DDHT_COUNTER_DISABLE" + CUSTOM_BUILD_FLAGS_FILE=custom-build-flags/build_flags_nrf52840.sh if [ -f $CUSTOM_BUILD_FLAGS_FILE ]; then source $CUSTOM_BUILD_FLAGS_FILE diff --git a/check_custom_build_flags_stm32.sh b/check_custom_build_flags_stm32.sh index 6f9d7c2..b6169c0 100755 --- a/check_custom_build_flags_stm32.sh +++ b/check_custom_build_flags_stm32.sh @@ -1,5 +1,9 @@ #! /bin/bash CUSTOM_BUILD_FLAGS_FILE=custom-build-flags/build_flags_stm32.sh +export FLAGS="$FLAGS -DPIO_SRC_REV="$(git log --pretty=format:%h_%ad -1 --date=short) +export FLAGS="$FLAGS -DDMX_DISABLE" +export FLAGS="$FLAGS -DMODBUS_DISABLE" +export FLAGS="$FLAGS -DOWIRE_DISABLE" if [ -f $CUSTOM_BUILD_FLAGS_FILE ]; then source $CUSTOM_BUILD_FLAGS_FILE fi diff --git a/lighthub/main.cpp b/lighthub/main.cpp index c16ffdd..cba4047 100644 --- a/lighthub/main.cpp +++ b/lighthub/main.cpp @@ -64,11 +64,9 @@ ESP32 PWM Out */ -#include "Arduino.h" + #include "main.h" -#include "options.h" -#include "utils.h" -#include "homiedef.h" + #if defined(__SAM3X8E__) DueFlashStorage EEPROM; @@ -80,18 +78,12 @@ EthernetClient ethClient; #endif #ifdef ARDUINO_ARCH_ESP8266 -#include -#include WiFiClient ethClient; #endif #ifdef ARDUINO_ARCH_ESP32 -#include -#include -#include -#include -#include "Ethernet3.h" WiFiClient ethClient; +NRFFlashStorage EEPROM; #endif #ifdef ARDUINO_ARCH_STM32F1 @@ -99,7 +91,7 @@ WiFiClient ethClient; //#include //#include "UIPEthernet.h" //#include "UIPUdp.h" -#include +//#include #include #include "Dns.h" @@ -110,7 +102,6 @@ EthernetClient ethClient; #endif #ifdef NRF5 -#include NRFFlashStorage EEPROM; EthernetClient ethClient; #endif @@ -171,7 +162,9 @@ bool wifiInitialized; int mqttErrorRate; +#if defined(__SAM3X8E__) void watchdogSetup(void) {} //Do not remove - strong re-definition WDT Init for DUE +#endif void mqttCallback(char *topic, byte *payload, unsigned int length) { debugSerial< +#include +#include +#endif + +#if defined(ARDUINO_ARCH_AVR) +#include "HTTPClientAVR.h" +#include +#include +#include +#endif + +#if defined(ARDUINO_ARCH_ESP8266) +#include //this needs to be first, or it all crashes and burns... +#include +#include +#include +#include +#include +#include +#include +#endif + +#if defined ARDUINO_ARCH_ESP32 +//#include //this needs to be first, or it all crashes and burns... +//#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define Ethernet WiFi +#endif + +#ifdef NRF5 +#include +#endif #if defined(__SAM3X8E__) #define wdt_res() watchdogReset() @@ -56,18 +99,6 @@ #include "DallasTemperature.h" #endif -#include "Arduino.h" -#include -#include -#include "utils.h" -#include -#include "aJSON.h" -#include -#include "stdarg.h" -#include "item.h" -#include "inputs.h" - - #ifndef MODBUS_DISABLE #include #endif @@ -76,57 +107,23 @@ #include "FastLED.h" #endif -#include "Dns.h" -//#include "hsv2rgb.h" - -#if defined(__SAM3X8E__) -#include -#include -#include -#endif - -#if defined(ARDUINO_ARCH_AVR) -#include "HTTPClientAVR.h" -#include -#include -#include -#endif - -#if defined(ESP8266) -#include //this needs to be first, or it all crashes and burns... -#include -#include -#include -#include -#include - -#endif - #ifdef _owire - #include "owTerm.h" - #endif #if defined(_dmxin) || defined(_dmxout) || defined (_artnet) - #include "dmx.h" - #endif -#if defined(ARDUINO_ARCH_AVR) || defined(__SAM3X8E__) || defined(ESP8266) || defined(NRF5) + #ifdef Wiz5500 #include #else +#if defined(ARDUINO_ARCH_AVR) || defined(__SAM3X8E__) || defined(NRF5) #include #endif #endif -#ifdef ARDUINO_ARCH_ESP32 -#include -//#include -#endif - #ifdef _artnet #include @@ -136,6 +133,18 @@ #include "sd_card_w5100.h" #endif +#include "Arduino.h" +#include "utils.h" +#include "homiedef.h" +#include +#include +#include +#include "aJSON.h" +#include +#include "stdarg.h" +#include "item.h" +#include "inputs.h" + #ifdef _artnet extern Artnet *artnet; #endif diff --git a/lighthub/options.h b/lighthub/options.h index 5dce6e9..466b419 100644 --- a/lighthub/options.h +++ b/lighthub/options.h @@ -129,6 +129,10 @@ #endif #if defined(ARDUINO_ARCH_ESP32) +#undef _dmxin +#undef _modbus +#undef _dmxout +#undef modbusSerial #endif #ifndef _dmxout diff --git a/lighthub/utils.cpp b/lighthub/utils.cpp index bad5a16..dc190d2 100644 --- a/lighthub/utils.cpp +++ b/lighthub/utils.cpp @@ -110,7 +110,7 @@ unsigned long freeRam() { #endif -#if defined(__SAM3X8E__) +#if defined(__SAM3X8E__) extern char _end; extern "C" char *sbrk(int i); @@ -265,5 +265,67 @@ void ReadUniqueID( unsigned int * pdwUniqueID ) } +int inet_aton(const char* aIPAddrString, IPAddress& aResult) +{ + // See if we've been given a valid IP address + const char* p =aIPAddrString; + while (*p && + ( (*p == '.') || (*p >= '0') || (*p <= '9') )) + { + p++; + } + + if (*p == '\0') + { + // It's looking promising, we haven't found any invalid characters + p = aIPAddrString; + int segment =0; + int segmentValue =0; + while (*p && (segment < 4)) + { + if (*p == '.') + { + // We've reached the end of a segment + if (segmentValue > 255) + { + // You can't have IP address segments that don't fit in a byte + return 0; + } + else + { + aResult[segment] = (byte)segmentValue; + segment++; + segmentValue = 0; + } + } + else + { + // Next digit + segmentValue = (segmentValue*10)+(*p - '0'); + } + p++; + } + // We've reached the end of address, but there'll still be the last + // segment to deal with + if ((segmentValue > 255) || (segment > 3)) + { + // You can't have IP address segments that don't fit in a byte, + // or more than four segments + return 0; + } + else + { + aResult[segment] = (byte)segmentValue; + return 1; + } + } + else + + { + return 0; + } +} + + #pragma message(VAR_NAME_VALUE(debugSerial)) #pragma message(VAR_NAME_VALUE(SERIAL_BAUD)) diff --git a/lighthub/utils.h b/lighthub/utils.h index d710a9e..d38cd22 100644 --- a/lighthub/utils.h +++ b/lighthub/utils.h @@ -42,3 +42,4 @@ void parseBytes(const char* str, char separator, byte* bytes, int maxBytes, int int log(const char *str, ...); void printFloatValueToStr(float value, char *valstr); void ReadUniqueID( unsigned int * pdwUniqueID ); +int inet_aton(const char* aIPAddrString, IPAddress& aResult); diff --git a/platformio.ini b/platformio.ini index bc610b7..82f05b8 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,7 +9,7 @@ ; http://docs.platformio.org/page/projectconf.html [platformio] src_dir = lighthub -env_default = due-5500 +env_default = esp32 ;monitor_speed = 115200 ; megaatmega2560 ; megaatmega2560-net @@ -21,11 +21,12 @@ env_default = due-5500 ; controllino ; stm32 ; esp32-evb +; nrf52840_dk ;build_dir = /tmp/pioenvs ;libdeps_dir = /tmp/piolibdeps [env:nrf52840_dk] -platform = nordinrf52 +platform = nordicnrf52 board = nrf52840_dk ;upload_protocol = mbed ;upload_port = /dev/cu.SLAB_USBtoUART @@ -46,6 +47,9 @@ lib_ignore = ESPDMX DueFlashStorage PrintEx + DHT sensor library + DHT sensor library for ESPx + Adafruit Unified Sensor ; Adafruit_Sensor lib_deps = https://github.com/anklimov/Arduino-Temperature-Control-Library.git @@ -58,55 +62,19 @@ lib_deps = https://github.com/knolleary/pubsubclient.git ; https://github.com/anklimov/Artnet.git ; FastLED - Adafruit Unified Sensor +; Adafruit Unified Sensor ; DHT sensor library for ESPx - DHT sensor library +; DHT sensor library Streaming https://github.com/anklimov/NRFFlashStorage ; https://github.com/livello/PrintEx#is-select-redecl -[env:esp32-evb] -platform = espressif32 -framework = arduino -board = esp32-evb -upload_protocol = esptool -upload_speed = 115200 -build_flags = !bash check_custom_build_flags_esp32.sh -lib_ignore = - DmxSimple - DMXSerial - DmxDue - DueFlashStorage - SD - SdFat - WifiManager - Ethernet - Ethernet2 - httpClient - NRFFlashStorage -lib_deps = - https://github.com/anklimov/Arduino-Temperature-Control-Library.git - https://github.com/anklimov/DS2482_OneWire - Ethernet3 - ESP8266HTTPClient - https://github.com/anklimov/aJson - https://github.com/anklimov/CmdArduino - https://github.com/anklimov/ModbusMaster - https://github.com/knolleary/pubsubclient.git - https://github.com/anklimov/Artnet.git - FastLED - Adafruit Unified Sensor - DHT sensor library for ESPx - DHT sensor library - Streaming - ; https://github.com/livello/PrintEx#is-select-redecl - - [env:esp32] platform = espressif32 framework = arduino -board = pico32 +;board = pico32 +board = esp32-evb upload_speed = 115200 build_flags = !bash check_custom_build_flags_esp32.sh lib_ignore = @@ -116,29 +84,38 @@ lib_ignore = DueFlashStorage SD SdFat - WifiManager Ethernet Ethernet2 + Ethernet3 HTTPClient httpClient - NRFFlashStorage -lib_deps = + EEPROM + https://github.com/anklimov/ModbusMaster https://github.com/anklimov/Arduino-Temperature-Control-Library.git https://github.com/anklimov/DS2482_OneWire - Ethernet3 - ESP8266HTTPClient - https://github.com/anklimov/aJson - https://github.com/anklimov/CmdArduino - https://github.com/anklimov/ModbusMaster - https://github.com/knolleary/pubsubclient.git + DS2482_OneWire + OneWire + DallasTemperature + ModbusMaster + Artnet https://github.com/anklimov/Artnet.git FastLED Adafruit Unified Sensor DHT sensor library for ESPx DHT sensor library + Wire + ;WifiManager + ;HTTPClient + ;HttpClient +lib_deps = + https://github.com/ebenolson/WIFIMANAGER-ESP32.git + https://github.com/zhouhan0126/WebServer-esp32.git + https://github.com/arduino-libraries/ArduinoHttpClient.git + https://github.com/anklimov/aJson + https://github.com/anklimov/CmdArduino + https://github.com/knolleary/pubsubclient.git Streaming - https://github.com/livello/PrintEx#is-select-redecl - + https://github.com/anklimov/NRFFlashStorage [env:due] platform = atmelsam framework = arduino