From 642f20de8c85eb00185b5383acd8053422001a32 Mon Sep 17 00:00:00 2001 From: livello Date: Fri, 23 Mar 2018 13:35:52 +0300 Subject: [PATCH] DMX Modbus OneWire support now can be disabled --- README.md | 6 ++ build_flags_template.sh | 3 + lighthub/main.cpp | 18 ++---- lighthub/options.h | 11 +++- lighthub/utils.cpp | 118 ++++++++++++++++++++-------------------- platformio.ini | 4 +- 6 files changed, 86 insertions(+), 74 deletions(-) diff --git a/README.md b/README.md index 166bd74..f73de3c 100644 --- a/README.md +++ b/README.md @@ -125,6 +125,9 @@ platformio device monitor -b 115200 * Wiz5500 //Use Wiznet 5500 library instead Wiznet 5100 * DISABLE_FREERAM_PRINT // disable printing free Ram in bytes * CUSTOM_FIRMWARE_MAC=de:ad:be:ef:fe:00 //set firmware macaddress +* DMX_DISABLE //disable DMX support +* MODBUS_DISABLE // disable Modbus support +* OWIRE_DISABLE // disable OneWire support Look at build_flags_template.sh for customizing. @@ -137,3 +140,6 @@ Look at build_flags_template.sh for customizing. * Wiznet 5100 (for MEGA & DUE) * Free Ram printing enabled * de:ad:be:ef:fe:00 +* DMX support enabled +* Modbus support enabled +* OneWire support enabled diff --git a/build_flags_template.sh b/build_flags_template.sh index c2a5a89..0e97a40 100644 --- a/build_flags_template.sh +++ b/build_flags_template.sh @@ -14,5 +14,8 @@ export FLAGS="$FLAGS -DWiz5500" export FLAGS="$FLAGS -DDISABLE_FREERAM_PRINT" export FLAGS="$FLAGS -DCUSTOM_FIRMWARE_MAC=de:ad:be:ef:fe:00" + export FLAGS="$FLAGS -DDMX_DISABLE" + export FLAGS="$FLAGS -DMODBUS_DISABLE" + export FLAGS="$FLAGS -DOWIRE_DISABLE" export PLATFORMIO_BUILD_FLAGS="$FLAGS" unset FLAGS \ No newline at end of file diff --git a/lighthub/main.cpp b/lighthub/main.cpp index 5741a06..395f994 100644 --- a/lighthub/main.cpp +++ b/lighthub/main.cpp @@ -122,9 +122,10 @@ DueFlashStorage EEPROM; #define wdt_en() #define wdt_dis() - #else +#include "Dhcp.h" + #ifdef Wiz5500 #include #else @@ -447,31 +448,24 @@ if((wifiMulti.run() == WL_CONNECTED)) lanStatus=1; wdt_dis(); if (lanStatus > 0) switch (Ethernet.maintain()) { - case 1: + case DHCP_CHECK_RENEW_FAIL: //renewed fail Serial.println(F("Error: renewed fail")); lanStatus = -10; break; - case 2: - //renewed success + case DHCP_CHECK_RENEW_OK: Serial.println(F("Renewed success")); - - //print your local IP address: printIPAddress(); break; - case 3: - //rebind fail + case DHCP_CHECK_REBIND_FAIL: Serial.println(F("Error: rebind fail")); lanStatus = -10; break; - case 4: - //rebind success + case DHCP_CHECK_REBIND_OK: Serial.println(F("Rebind success")); - - //print your local IP address: printIPAddress(); break; diff --git a/lighthub/options.h b/lighthub/options.h index ce8d76e..92bbdd0 100644 --- a/lighthub/options.h +++ b/lighthub/options.h @@ -1,8 +1,17 @@ // Configuration of drivers enabled +#ifndef DMX_DISABLE #define _dmxin #define _dmxout +#endif + +#ifndef OWIRE_DISABLE #define _owire -#define _modbus +#endif + +#ifndef MODBUS_DISABLE +#define _modbus +#endif + #define _artnet #if defined(ESP8266) diff --git a/lighthub/utils.cpp b/lighthub/utils.cpp index b3178af..0509cf0 100644 --- a/lighthub/utils.cpp +++ b/lighthub/utils.cpp @@ -19,6 +19,7 @@ e-mail anklimov@gmail.com */ #include "utils.h" + #if defined(__SAM3X8E__) #include #endif @@ -29,63 +30,62 @@ extern "C" { } #endif -void PrintBytes(uint8_t* addr, uint8_t count, bool newline) { - for (uint8_t i = 0; i < count; i++) { - Serial.print(addr[i]>>4, HEX); - Serial.print(addr[i]&0x0f, HEX); - } - if (newline) - Serial.println(); +void PrintBytes(uint8_t *addr, uint8_t count, bool newline) { + for (uint8_t i = 0; i < count; i++) { + Serial.print(addr[i] >> 4, HEX); + Serial.print(addr[i] & 0x0f, HEX); + } + if (newline) + Serial.println(); } -const char HEXSTR[]="0123456789ABCDEF"; +const char HEXSTR[] = "0123456789ABCDEF"; + +void SetBytes(uint8_t *addr, uint8_t count, char *out) { + // Serial.println("SB:"); + for (uint8_t i = 0; i < count; i++) { + *(out++) = HEXSTR[(addr[i] >> 4)]; + *(out++) = HEXSTR[(addr[i] & 0x0f)]; + } + *out = 0; -void SetBytes(uint8_t* addr, uint8_t count, char * out) { - // Serial.println("SB:"); - for (uint8_t i = 0; i < count; i++) { - *(out++)=HEXSTR[(addr[i]>>4)]; - *(out++)=HEXSTR[(addr[i]&0x0f)]; - } - *out=0; - } -byte HEX2DEC(char i) -{ byte v; -if ('a' <= i && i <='f') { v=i-97+10; } - else if ('A' <= i && i <='F') { v=i-65+10; } - else if ('0' <= i && i <='9') { v=i-48; } - return v; - } +byte HEX2DEC(char i) { + byte v; + if ('a' <= i && i <= 'f') { v = i - 97 + 10; } + else if ('A' <= i && i <= 'F') { v = i - 65 + 10; } + else if ('0' <= i && i <= '9') { v = i - 48; } + return v; +} -void SetAddr(char * out, uint8_t* addr) { - - for (uint8_t i = 0; i < 8; i++) { - *addr=HEX2DEC(*out++)<<4; - *addr++|=HEX2DEC(*out++); - } +void SetAddr(char *out, uint8_t *addr) { + + for (uint8_t i = 0; i < 8; i++) { + *addr = HEX2DEC(*out++) << 4; + *addr++ |= HEX2DEC(*out++); + } } -int getInt(char ** chan) -{ - int ch = atoi(*chan); - *chan=strchr(*chan,','); - - if (*chan) *chan+=1; - //Serial.print(F("Par:")); Serial.println(ch); - return ch; - +int getInt(char **chan) { + int ch = atoi(*chan); + *chan = strchr(*chan, ','); + + if (*chan) *chan += 1; + //Serial.print(F("Par:")); Serial.println(ch); + return ch; + } #if defined(ESP8266) -unsigned long freeRam () +unsigned long freeRam () {return system_get_free_heap_size();} #endif -#if defined(__AVR__) +#if defined(__AVR__) unsigned long freeRam () { extern int __heap_start, *__brkval; @@ -98,25 +98,25 @@ unsigned long freeRam () 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 +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(); -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 - str = strchr(str, separator); // Find next separator - if (str == NULL || *str == '\0') { - break; // No more separators, exit + 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 + str = strchr(str, separator); // Find next separator + if (str == NULL || *str == '\0') { + break; // No more separators, exit + } + str++; // Point to next character after separator } - str++; // Point to next character after separator - } } \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index de602e4..5e4e1d5 100644 --- a/platformio.ini +++ b/platformio.ini @@ -10,8 +10,8 @@ [platformio] src_dir = lighthub env_default = - megaatmega2560 -; due +; megaatmega2560 + due ; esp8266 [env:due]