diff --git a/.vscode/.browse.c_cpp.db b/.vscode/.browse.c_cpp.db index 4c4c0df..3420cd8 100644 Binary files a/.vscode/.browse.c_cpp.db and b/.vscode/.browse.c_cpp.db differ diff --git a/.vscode/arduino.json b/.vscode/arduino.json index 838c702..f180973 100644 --- a/.vscode/arduino.json +++ b/.vscode/arduino.json @@ -1,5 +1,4 @@ { - "board": "esp8266:esp8266:d1", - "configuration": "CpuFrequency=80,FlashSize=4M1M,LwIPVariant=v2mss536,Debug=Disabled,DebugLevel=None____,UploadSpeed=921600", + "board": "arduino:sam:arduino_due_x", "port": "/dev/cu.usbmodem1411" } \ No newline at end of file diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index a6c2f65..bb0d12b 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -5,6 +5,8 @@ "name": "Mac", "macFrameworkPath": [], "includePath": [ + "/Users/andrey/Library/Arduino15/packages/arduino/tools/**", + "/Users/andrey/Library/Arduino15/packages/arduino/hardware/sam/1.6.11/**", "/Users/andrey/.platformio/packages/framework-arduinosam/cores/sam", "/Users/andrey/.platformio/packages/framework-arduinosam/system/sam/libsam", "/Users/andrey/.platformio/packages/framework-arduinosam/system/sam/CMSIS/CMSIS/Include", @@ -31,12 +33,7 @@ "/Users/andrey/Documents/Arduino/lighthub/.piolibdeps/Streaming_ID560", "/Users/andrey/Documents/Arduino/lighthub/.piolibdeps/Syslog/src", "/Users/andrey/Documents/Arduino/lighthub/.piolibdeps/aJson", - "/Users/andrey/Documents/Arduino/lighthub/.piolibdeps/ArduinoJson_ID64/src", - "/Users/andrey/Documents/Arduino/lighthub/.piolibdeps/AsyncMqttClient_ID346/src", - "/Users/andrey/Documents/Arduino/lighthub/.piolibdeps/Bounce2_ID1106/src", - "/Users/andrey/Documents/Arduino/lighthub/.piolibdeps/ESP Async WebServer_ID306/src", - "/Users/andrey/Documents/Arduino/lighthub/.piolibdeps/Homie_ID555/src", - "/Users/andrey/Documents/Arduino/lighthub/.piolibdeps/HttpClient_ID66", + "/Users/andrey/Documents/Arduino/lighthub/.piolibdeps/Ethernet2_ID261/src", "/Users/andrey/.platformio/packages/framework-arduinosam/libraries/__cores__/sam/HID/src", "/Users/andrey/.platformio/packages/tool-unity", "/Users/andrey/Documents/Arduino/lighthub/include", @@ -73,12 +70,7 @@ "/Users/andrey/Documents/Arduino/lighthub/.piolibdeps/Streaming_ID560", "/Users/andrey/Documents/Arduino/lighthub/.piolibdeps/Syslog/src", "/Users/andrey/Documents/Arduino/lighthub/.piolibdeps/aJson", - "/Users/andrey/Documents/Arduino/lighthub/.piolibdeps/ArduinoJson_ID64/src", - "/Users/andrey/Documents/Arduino/lighthub/.piolibdeps/AsyncMqttClient_ID346/src", - "/Users/andrey/Documents/Arduino/lighthub/.piolibdeps/Bounce2_ID1106/src", - "/Users/andrey/Documents/Arduino/lighthub/.piolibdeps/ESP Async WebServer_ID306/src", - "/Users/andrey/Documents/Arduino/lighthub/.piolibdeps/Homie_ID555/src", - "/Users/andrey/Documents/Arduino/lighthub/.piolibdeps/HttpClient_ID66", + "/Users/andrey/Documents/Arduino/lighthub/.piolibdeps/Ethernet2_ID261/src", "/Users/andrey/.platformio/packages/framework-arduinosam/libraries/__cores__/sam/HID/src", "/Users/andrey/.platformio/packages/tool-unity", "/Users/andrey/Documents/Arduino/lighthub/include", @@ -87,7 +79,7 @@ ] }, "defines": [ - "PLATFORMIO=30603", + "PLATFORMIO=40000", "__SAM3X8E__", "ARDUINO_ARCH_SAM", "ARDUINO_SAM_DUE", @@ -106,7 +98,10 @@ "intelliSenseMode": "clang-x64", "cStandard": "c11", "cppStandard": "c++11", - "compilerPath": "/Users/andrey/.platformio/packages/toolchain-gccarmnoneeabi@1.40804.0/bin/arm-none-eabi-gcc -mthumb -mcpu=cortex-m3" + "compilerPath": "/Users/andrey/.platformio/packages/toolchain-gccarmnoneeabi@1.40804.0/bin/arm-none-eabi-gcc -mthumb -mcpu=cortex-m3", + "forcedInclude": [ + "/Users/andrey/Library/Arduino15/packages/arduino/hardware/sam/1.6.11/cores/arduino/Arduino.h" + ] } ], "version": 4 diff --git a/.vscode/settings.json b/.vscode/settings.json index 889efeb..58adb10 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,6 @@ { "terminal.integrated.env.osx": { - "PATH": "/Users/andrey/.platformio/penv/bin:/Users/andrey/.platformio/penv:/usr/local/opt/python@2/bin:/opt/local/sbin:/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Applications/Wireshark.app/Contents/MacOS", + "PATH": "/Users/andrey/.platformio/penv/bin:/Users/andrey/.platformio/penv:/usr/local/opt/ruby/bin:/usr/local/opt/python@2/bin:/opt/local/sbin:/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Applications/Wireshark.app/Contents/MacOS", "PLATFORMIO_CALLER": "vscode" } } \ No newline at end of file diff --git a/check_custom_build_flags_esp8266.sh b/check_custom_build_flags_esp8266.sh index 37f2331..0e15b05 100755 --- a/check_custom_build_flags_esp8266.sh +++ b/check_custom_build_flags_esp8266.sh @@ -1,4 +1,5 @@ #! /bin/bash +export FLAGS="$FLAGS -DMODBUS_DISABLE" 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_nrf52840.sh b/check_custom_build_flags_nrf52840.sh new file mode 100755 index 0000000..f48c2b0 --- /dev/null +++ b/check_custom_build_flags_nrf52840.sh @@ -0,0 +1,7 @@ +#! /bin/bash +export FLAGS="$FLAGS -DWiz5500" +CUSTOM_BUILD_FLAGS_FILE=custom-build-flags/build_flags_nrf52840.sh +if [ -f $CUSTOM_BUILD_FLAGS_FILE ]; then + source $CUSTOM_BUILD_FLAGS_FILE +fi + echo $FLAGS diff --git a/custom-build-flags/build_flags_controllino.sh b/custom-build-flags/build_flags_controllino.sh index 89f5b45..aefe7aa 100755 --- a/custom-build-flags/build_flags_controllino.sh +++ b/custom-build-flags/build_flags_controllino.sh @@ -6,7 +6,7 @@ # nano my_build_flags.sh # and source it # source my_build_flags.sh - #export FLAGS="-DMY_CONFIG_SERVER=lighthub.elistech.ru" + #export FLAGS="$FLAGS -DMY_CONFIG_SERVER=lighthub.elistech.ru" #export FLAGS="$FLAGS -DWATCH_DOG_TICKER_DISABLE" #export FLAGS="$FLAGS -DUSE_1W_PIN=12" #export FLAGS="$FLAGS -DSD_CARD_INSERTED" diff --git a/custom-build-flags/build_flags_mega2560-net.sh b/custom-build-flags/build_flags_mega2560-net.sh index 3f2c34c..63c1436 100644 --- a/custom-build-flags/build_flags_mega2560-net.sh +++ b/custom-build-flags/build_flags_mega2560-net.sh @@ -3,7 +3,7 @@ # first make your own copy of template # cp build_flags_template.sh build_flags_ENVNAME.sh # then edit, change or comment something - export FLAGS="-DMY_CONFIG_SERVER=lazyhome.ru" + export FLAGS="$FLAGS -DMY_CONFIG_SERVER=lazyhome.ru" #export FLAGS="$FLAGS -DWATCH_DOG_TICKER_DISABLE" #export FLAGS="$FLAGS -DUSE_1W_PIN=12" #export FLAGS="$FLAGS -DSD_CARD_INSERTED" diff --git a/custom-build-flags/build_flags_nrf52840.sh b/custom-build-flags/build_flags_nrf52840.sh new file mode 100644 index 0000000..1d841f2 --- /dev/null +++ b/custom-build-flags/build_flags_nrf52840.sh @@ -0,0 +1,31 @@ +#! /bin/bash +# usage: +# first make your own copy of template +# cp build_flags_template.sh build_flags_ENVNAME.sh +# then edit, change or comment something + export FLAGS="$FLAGS -DMY_CONFIG_SERVER=lazyhome.ru" + export FLAGS="$FLAGS -DWATCH_DOG_TICKER_DISABLE" + #export FLAGS="$FLAGS -DUSE_1W_PIN=12" + #export FLAGS="$FLAGS -DSD_CARD_INSERTED" + export FLAGS="$FLAGS -DSERIAL_BAUD=115200" + #export FLAGS="$FLAGS -DWiz5500" + export FLAGS="$FLAGS -DDISABLE_FREERAM_PRINT" + export FLAGS="$FLAGS -DCUSTOM_FIRMWARE_MAC=de:ad:be:ef:fe:ff" + export FLAGS="$FLAGS -DDMX_DISABLE" + export FLAGS="$FLAGS -DMODBUS_DISABLE" + export FLAGS="$FLAGS -DOWIRE_DISABLE" +# export FLAGS="$FLAGS -DAVR_DMXOUT_PIN=18" +# export FLAGS="$FLAGS -DLAN_INIT_DELAY=2000" +# export FLAGS="$FLAGS -DCONTROLLINO" + export FLAGS="$FLAGS -DWIFI_MANAGER_DISABLE" +# export FLAGS="$FLAGS -DRESET_PIN=5" +# export FLAGS="$FLAGS -DDHCP_RETRY_INTERVAL=60000" +# export FLAGS="$FLAGS -DRESTART_LAN_ON_MQTT_ERRORS" +# export FLAGS="$FLAGS -DW5500_CS_PIN=53" +export FLAGS="$FLAGS -DSYSLOG_DISABLE" +export FLAGS="$FLAGS -std=gnu++11" +#export FLAGS="$FLAGS -DDEVICE_NAME=MYDEVICE" +export FLAGS="$FLAGS -DDHT_COUNTER_DISABLE" +#export FLAGS="$FLAGS -DWITH_PRINTEX_LIB" + export FLAGS="$FLAGS -DPIO_SRC_REV="$(git log --pretty=format:%h_%ad -1 --date=short) + echo $FLAGS diff --git a/custom-build-flags/build_flags_template.sh b/custom-build-flags/build_flags_template.sh index 517a351..667c817 100755 --- a/custom-build-flags/build_flags_template.sh +++ b/custom-build-flags/build_flags_template.sh @@ -3,7 +3,7 @@ # first make your own copy of template # cp build_flags_template.sh build_flags_ENVNAME.sh # then edit, change or comment something - export FLAGS="-DMY_CONFIG_SERVER=lazyhome.ru" + export FLAGS="$FLAGS -DMY_CONFIG_SERVER=lazyhome.ru" #export FLAGS="$FLAGS -DWATCH_DOG_TICKER_DISABLE" #export FLAGS="$FLAGS -DUSE_1W_PIN=12" #export FLAGS="$FLAGS -DSD_CARD_INSERTED" diff --git a/lighthub/inputs.cpp b/lighthub/inputs.cpp index 901b195..94b6aa1 100644 --- a/lighthub/inputs.cpp +++ b/lighthub/inputs.cpp @@ -332,9 +332,9 @@ void Input::contactPoll() { WiringPinMode inputPinMode; #endif #if defined(__SAM3X8E__)||defined(ARDUINO_ARCH_AVR)||defined(ARDUINO_ARCH_ESP8266)||defined(ARDUINO_ARCH_ESP32) - uint32_t inputPinMode; -#endif +#endif + uint32_t inputPinMode; uint8_t inputOnLevel; if (inType & IN_ACTIVE_HIGH) { inputOnLevel = HIGH; @@ -375,10 +375,10 @@ void Input::analogPoll() { #if defined(ARDUINO_ARCH_STM32F1) WiringPinMode inputPinMode; #endif -#if defined(__SAM3X8E__)||defined(ARDUINO_ARCH_AVR)||defined(ARDUINO_ARCH_ESP8266)||defined(ARDUINO_ARCH_ESP32) - uint32_t inputPinMode; -#endif +#if defined(__SAM3X8E__)||defined(ARDUINO_ARCH_AVR)||defined(ARDUINO_ARCH_ESP8266)||defined(ARDUINO_ARCH_ESP32) +#endif + uint32_t inputPinMode; if (inType & IN_ACTIVE_HIGH) { inputPinMode = INPUT; } else { @@ -389,24 +389,25 @@ void Input::analogPoll() { // Mapping if (inputMap && inputMap->type == aJson_Array) { + int max; if (aJson.getArraySize(inputMap)>=4) mappedInputVal = map (mappedInputVal, aJson.getArrayItem(inputMap, 0)->valueint, aJson.getArrayItem(inputMap, 1)->valueint, aJson.getArrayItem(inputMap, 2)->valueint, - aJson.getArrayItem(inputMap, 3)->valueint); + max=aJson.getArrayItem(inputMap, 3)->valueint); if (aJson.getArraySize(inputMap)==5) Noize = aJson.getArrayItem(inputMap, 4)->valueint; - + if (mappedInputVal>max) mappedInputVal=max; if (aJson.getArraySize(inputMap)==2) { simple = 1; if (mappedInputVal < aJson.getArrayItem(inputMap, 0)->valueint) mappedInputVal = 0; else if (mappedInputVal > aJson.getArrayItem(inputMap, 1)->valueint) mappedInputVal = 1; - else mappedInputVal = -1; + else return; } } if (simple) { - if (mappedInputVal!=-1 && mappedInputVal != store->currentValue) + if (mappedInputVal != store->currentValue) { onContactChanged(mappedInputVal); store->currentValue = mappedInputVal; diff --git a/lighthub/item.cpp b/lighthub/item.cpp index 332cad2..4bfd5f8 100644 --- a/lighthub/item.cpp +++ b/lighthub/item.cpp @@ -218,7 +218,7 @@ int Item::Ctrl(char * payload, boolean send){ case -1: //Not known command case -2: //JSON input (not implemented yet break; -#if not defined(ARDUINO_ARCH_ESP32) and not defined(ESP8266) and not defined(ARDUINO_ARCH_STM32F1) +#if not defined(ARDUINO_ARCH_ESP32) and not defined(ESP8266) and not defined(ARDUINO_ARCH_STM32F1) and not defined(DMX_DISABLE) case -3: //RGB color in #RRGGBB notation { CRGB rgb; diff --git a/lighthub/main.cpp b/lighthub/main.cpp index 96740c0..9b3df27 100644 --- a/lighthub/main.cpp +++ b/lighthub/main.cpp @@ -109,6 +109,12 @@ WiFiClient ethClient; EthernetClient ethClient; #endif +#ifdef NRF5 +#include +NRFFlashStorage EEPROM; +EthernetClient ethClient; +#endif + #ifdef SYSLOG_ENABLE #include EthernetUDP udpSyslogClient; @@ -491,12 +497,13 @@ void ip_ready_config_loaded_connecting_to_broker() { strncpy_P(buf, outprefix, sizeof(buf)); strncat(buf, "#", sizeof(buf)); - mqttClient.subscribe(buf,MQTTQOS1); + mqttClient.subscribe(buf); //Subscribing for command topics strncpy_P(buf, inprefix, sizeof(buf)); strncat(buf, "#", sizeof(buf)); - mqttClient.subscribe(buf,MQTTQOS1); + Serial.println(buf); + mqttClient.subscribe(buf); //restoreState(); onMQTTConnect(); @@ -738,7 +745,7 @@ void cmdFunctionKill(int arg_cnt, char **args) { void cmdFunctionReboot(int arg_cnt, char **args) { debugSerial< #endif -#ifndef ARDUINO_ARCH_STM32F1 +#ifndef DMX_DISABLE #include "FastLED.h" #endif @@ -108,7 +114,7 @@ #endif -#if defined(ARDUINO_ARCH_AVR) || defined(__SAM3X8E__) || defined(ESP8266) +#if defined(ARDUINO_ARCH_AVR) || defined(__SAM3X8E__) || defined(ESP8266) || defined(NRF5) #ifdef Wiz5500 #include #else diff --git a/lighthub/options.h b/lighthub/options.h index 2cf2832..5dce6e9 100644 --- a/lighthub/options.h +++ b/lighthub/options.h @@ -66,7 +66,7 @@ #endif #ifndef OUTTOPIC -#define OUTTOPIC "homie/s_out/" +#define OUTTOPIC "/myhome/s_out/" #endif #ifndef CMDTOPIC diff --git a/lighthub/utils.cpp b/lighthub/utils.cpp index 4a4454b..bad5a16 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); @@ -126,6 +126,23 @@ unsigned long freeRam() { #endif +#if defined(NRF5) +extern char _end; +extern "C" char *sbrk(int i); + +unsigned long freeRam() { + char *ramstart = (char *) 0x20070000; + char *ramend = (char *) 0x20088000; + char *heapend = sbrk(0); + register char *stack_ptr asm( "sp" ); + //struct mallinfo mi = mallinfo(); + + return stack_ptr - heapend;// + mi.fordblks; +} + +#endif + + void parseBytes(const char *str, char separator, byte *bytes, int maxBytes, int base) { for (int i = 0; i < maxBytes; i++) { bytes[i] = strtoul(str, NULL, base); // Convert byte diff --git a/platformio.ini b/platformio.ini index fbca15d..bc610b7 100644 --- a/platformio.ini +++ b/platformio.ini @@ -24,6 +24,46 @@ env_default = due-5500 ;build_dir = /tmp/pioenvs ;libdeps_dir = /tmp/piolibdeps +[env:nrf52840_dk] +platform = nordinrf52 +board = nrf52840_dk +;upload_protocol = mbed +;upload_port = /dev/cu.SLAB_USBtoUART +framework = arduino +build_flags = !bash check_custom_build_flags_nrf52840.sh +lib_ignore = + DmxSimple + DMXSerial + DmxDue + EEPROM + SD + SdFat + WifiManager + Ethernet + Ethernet3 + httpClient + FastLED + ESPDMX + DueFlashStorage + PrintEx +; Adafruit_Sensor +lib_deps = + https://github.com/anklimov/Arduino-Temperature-Control-Library.git + https://github.com/anklimov/DS2482_OneWire + Ethernet2 + 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/anklimov/NRFFlashStorage +; https://github.com/livello/PrintEx#is-select-redecl [env:esp32-evb] @@ -44,6 +84,7 @@ lib_ignore = Ethernet Ethernet2 httpClient + NRFFlashStorage lib_deps = https://github.com/anklimov/Arduino-Temperature-Control-Library.git https://github.com/anklimov/DS2482_OneWire @@ -59,7 +100,7 @@ lib_deps = DHT sensor library for ESPx DHT sensor library Streaming - https://github.com/livello/PrintEx#is-select-redecl + ; https://github.com/livello/PrintEx#is-select-redecl [env:esp32] @@ -80,6 +121,7 @@ lib_ignore = Ethernet2 HTTPClient httpClient + NRFFlashStorage lib_deps = https://github.com/anklimov/Arduino-Temperature-Control-Library.git https://github.com/anklimov/DS2482_OneWire @@ -110,6 +152,7 @@ lib_ignore = ESPDMX WifiManager Ethernet3 + NRFFlashStorage lib_deps = https://github.com/sebnil/DueFlashStorage https://github.com/anklimov/Arduino-Temperature-Control-Library.git @@ -144,6 +187,7 @@ lib_ignore = WifiManager Ethernet3 HTTPClient + NRFFlashStorage lib_deps = https://github.com/anklimov/Arduino-Temperature-Control-Library.git https://github.com/anklimov/DS2482_OneWire @@ -177,6 +221,7 @@ lib_ignore = SdFat httpClient Ethernet3 + NRFFlashStorage lib_deps = https://github.com/anklimov/Arduino-Temperature-Control-Library.git https://github.com/anklimov/DS2482_OneWire @@ -209,6 +254,7 @@ lib_ignore = WifiManager Ethernet3 Ethernet2 + NRFFlashStorage lib_deps = https://github.com/anklimov/Arduino-Temperature-Control-Library.git https://github.com/anklimov/DS2482_OneWire @@ -244,6 +290,7 @@ lib_ignore = httpClient Ethernet Ethernet3 + NRFFlashStorage lib_deps = https://github.com/sebnil/DueFlashStorage @@ -279,6 +326,7 @@ lib_ignore = WifiManager Ethernet3 Ethernet2 + NRFFlashStorage lib_deps = https://github.com/anklimov/Arduino-Temperature-Control-Library.git https://github.com/anklimov/DS2482_OneWire @@ -322,6 +370,7 @@ lib_ignore = Ethernet2 Artnet Ethernet3 + NRFFlashStorage lib_deps =