mirror of
https://github.com/anklimov/lighthub
synced 2025-12-06 19:59:50 +03:00
NWRAM write fixed, startup algoritm improved to achive more independancy from net, DUE: WDT deployed, HTTP client redeveloped
This commit is contained in:
15
README.md
15
README.md
@@ -31,6 +31,7 @@ to flash your DUE
|
|||||||
(need to correct path and port, of course)
|
(need to correct path and port, of course)
|
||||||
# Dependences
|
# Dependences
|
||||||
(quite big number of libs required. Use git clone to have your local copy in your Arduino libs folder)
|
(quite big number of libs required. Use git clone to have your local copy in your Arduino libs folder)
|
||||||
|
Please check updates for all dependences.
|
||||||
|
|
||||||
For patched libraries, appropriate GitHub repo URL provided:
|
For patched libraries, appropriate GitHub repo URL provided:
|
||||||
|
|
||||||
@@ -40,7 +41,7 @@ For patched libraries, appropriate GitHub repo URL provided:
|
|||||||
* Wire (standard)
|
* Wire (standard)
|
||||||
* Artnet
|
* Artnet
|
||||||
* DmxSimple https://github.com/anklimov/DmxSimple (for AVR) or https://github.com/anklimov/ESP-Dmx (for ESP) or https://github.com/anklimov/DmxDue (for DUE)
|
* DmxSimple https://github.com/anklimov/DmxSimple (for AVR) or https://github.com/anklimov/ESP-Dmx (for ESP) or https://github.com/anklimov/DmxDue (for DUE)
|
||||||
* HTTPClient https://github.com/anklimov/HTTPClient
|
* HTTPClient (for AVR) https://github.com/anklimov/HTTPClient or https://github.com/arduino-libraries/ArduinoHttpClient for other platforms
|
||||||
* aJson https://github.com/anklimov/aJson
|
* aJson https://github.com/anklimov/aJson
|
||||||
* CmdArduino https://github.com/anklimov/CmdArduino
|
* CmdArduino https://github.com/anklimov/CmdArduino
|
||||||
* EEPROM (standard for AVR) or DueFlashStorage for DUE
|
* EEPROM (standard for AVR) or DueFlashStorage for DUE
|
||||||
@@ -50,17 +51,15 @@ For patched libraries, appropriate GitHub repo URL provided:
|
|||||||
* Ethernet https://github.com/anklimov/Ethernet
|
* Ethernet https://github.com/anklimov/Ethernet
|
||||||
* SPI (standard)
|
* SPI (standard)
|
||||||
|
|
||||||
Portation from AVR Mega 2560 to SAM3X8E (Arduino DUE) and ESP not completed yet and on early stage now.
|
Portation from AVR Mega 2560 to SAM3X8E (Arduino DUE) and ESP is not completed yet.
|
||||||
Core is mostly migrated (except EEPROM in DUE)
|
Core is mostly migrated
|
||||||
|
|
||||||
AVR version is basic and have all functions
|
AVR version is basic and have all functions
|
||||||
|
|
||||||
Another platforms limitations (todo):
|
Another platforms limitations (todo):
|
||||||
SAM3X8E:
|
SAM3X8E:
|
||||||
-EEPROM issues to be fixed
|
*DMX-in - not deployed yet
|
||||||
-DMX-in - not deployed yet
|
|
||||||
-Improve http client
|
|
||||||
|
|
||||||
ESP:
|
ESP:
|
||||||
-Wifi instead Ether not implemented yet
|
*Wifi instead Ether not implemented yet
|
||||||
-DMX-IN
|
*DMX-IN not possible to deploy
|
||||||
|
|||||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
51
dmx.cpp
51
dmx.cpp
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright © 2017 Andrey Klimov. All rights reserved.
|
/* Copyright © 2017-2018 Andrey Klimov. All rights reserved.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -35,7 +35,54 @@ unsigned long D_checkT=0;
|
|||||||
Artnet *artnet = NULL;
|
Artnet *artnet = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
aJsonObject *dmxArr = NULL;
|
|
||||||
|
extern aJsonObject *items;
|
||||||
|
extern aJsonObject *dmxArr;
|
||||||
|
|
||||||
|
|
||||||
|
int itemCtrl2(char* name,int r,int g, int b, int w)
|
||||||
|
{
|
||||||
|
aJsonObject *itemArr= aJson.getObjectItem(items, name);
|
||||||
|
|
||||||
|
if (itemArr && (itemArr->type==aJson_Array))
|
||||||
|
{
|
||||||
|
|
||||||
|
short itemtype = aJson.getArrayItem(itemArr,0)->valueint;
|
||||||
|
short itemaddr = aJson.getArrayItem(itemArr,1)->valueint;
|
||||||
|
switch (itemtype){
|
||||||
|
#ifdef _dmxout
|
||||||
|
case 0: //Dimmed light
|
||||||
|
|
||||||
|
DmxWrite(itemaddr, w);
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
case 1: //Colour RGBW
|
||||||
|
DmxWrite(itemaddr+3, w);
|
||||||
|
|
||||||
|
case 2: // RGB
|
||||||
|
{
|
||||||
|
|
||||||
|
DmxWrite(itemaddr, r);
|
||||||
|
DmxWrite(itemaddr+1, g);
|
||||||
|
DmxWrite(itemaddr+2, b);
|
||||||
|
|
||||||
|
break; }
|
||||||
|
#endif
|
||||||
|
case 7: //Group
|
||||||
|
aJsonObject *groupArr= aJson.getArrayItem(itemArr, 1);
|
||||||
|
if (groupArr && (groupArr->type==aJson_Array))
|
||||||
|
{ aJsonObject *i =groupArr->child;
|
||||||
|
while (i)
|
||||||
|
{ //Serial.println(i->valuestring);
|
||||||
|
itemCtrl2(i->valuestring,r,g,b,w);
|
||||||
|
i=i->next;}
|
||||||
|
}
|
||||||
|
} //itemtype
|
||||||
|
// break;
|
||||||
|
} //if have correct array
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void DMXImmediateUpdate(short tch,short r, short g, short b, short w) {
|
void DMXImmediateUpdate(short tch,short r, short g, short b, short w) {
|
||||||
//Here only safe re-interable code for quick passthrow between DMX IN and DMX OUT
|
//Here only safe re-interable code for quick passthrow between DMX IN and DMX OUT
|
||||||
|
|||||||
2
dmx.h
2
dmx.h
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright © 2017 Andrey Klimov. All rights reserved.
|
/* Copyright © 2017-2018 Andrey Klimov. All rights reserved.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright © 2017 Andrey Klimov. All rights reserved.
|
/* Copyright © 2017-2018 Andrey Klimov. All rights reserved.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
|||||||
2
inputs.h
2
inputs.h
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright © 2017 Andrey Klimov. All rights reserved.
|
/* Copyright © 2017-2018 Andrey Klimov. All rights reserved.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
|||||||
50
item.cpp
50
item.cpp
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright © 2017 Andrey Klimov. All rights reserved.
|
/* Copyright © 2017-2018 Andrey Klimov. All rights reserved.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -665,17 +665,6 @@ int Item::VacomSetFan (int8_t val, int8_t cmd)
|
|||||||
uint8_t j, result;
|
uint8_t j, result;
|
||||||
uint16_t data[1];
|
uint16_t data[1];
|
||||||
|
|
||||||
/*
|
|
||||||
#ifdef __SAM3X8E__
|
|
||||||
node.begin(9600,UARTClass::Mode_8E1,13);
|
|
||||||
#else
|
|
||||||
node.begin(9600,SERIAL_8E1,13);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
node.setSlave(addr);
|
|
||||||
*/
|
|
||||||
modbusSerial.begin(9600,fmPar);
|
modbusSerial.begin(9600,fmPar);
|
||||||
node.begin(addr,modbusSerial);
|
node.begin(addr,modbusSerial);
|
||||||
|
|
||||||
@@ -689,9 +678,6 @@ node.begin(addr,modbusSerial);
|
|||||||
|
|
||||||
modbusBusy=0;
|
modbusBusy=0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define a 0.1842
|
#define a 0.1842
|
||||||
@@ -703,15 +689,6 @@ int Item::VacomSetHeat(int addr,int8_t val, int8_t cmd)
|
|||||||
Serial.print(F("VC_heat#"));Serial.print(addr);Serial.print(F("="));Serial.print(val);Serial.print(F(" cmd="));Serial.println(cmd);
|
Serial.print(F("VC_heat#"));Serial.print(addr);Serial.print(F("="));Serial.print(val);Serial.print(F(" cmd="));Serial.println(cmd);
|
||||||
if (modbusBusy) {mb_fail(2,addr,val,cmd);return -1;}
|
if (modbusBusy) {mb_fail(2,addr,val,cmd);return -1;}
|
||||||
modbusBusy=1;
|
modbusBusy=1;
|
||||||
/*
|
|
||||||
#ifdef __SAM3X8E__
|
|
||||||
node.begin(9600,UARTClass::Mode_8E1,13);
|
|
||||||
#else
|
|
||||||
node.begin(9600,SERIAL_8E1,13);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
node.setSlave(addr);
|
|
||||||
*/
|
|
||||||
|
|
||||||
modbusSerial.begin(9600,fmPar);
|
modbusSerial.begin(9600,fmPar);
|
||||||
node.begin(addr,modbusSerial);
|
node.begin(addr,modbusSerial);
|
||||||
@@ -791,15 +768,7 @@ int Item::SendCmd(short cmd,short n, int * Par)
|
|||||||
|
|
||||||
if (modbusBusy) {mb_fail(3,addr,value,0);return -1;};
|
if (modbusBusy) {mb_fail(3,addr,value,0);return -1;};
|
||||||
modbusBusy=1;
|
modbusBusy=1;
|
||||||
/*
|
|
||||||
#ifdef __SAM3X8E__
|
|
||||||
node.begin(9600,UARTClass::Mode_8E1,13);
|
|
||||||
#else
|
|
||||||
node.begin(9600,SERIAL_8E1,13);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
node.setSlave(addr);
|
|
||||||
*/
|
|
||||||
modbusSerial.begin(9600,dimPar);
|
modbusSerial.begin(9600,dimPar);
|
||||||
node.begin(addr,modbusSerial);
|
node.begin(addr,modbusSerial);
|
||||||
|
|
||||||
@@ -834,17 +803,8 @@ int Item::checkFM()
|
|||||||
strncat(addrstr,"_stat",sizeof(addrstr)-1);
|
strncat(addrstr,"_stat",sizeof(addrstr)-1);
|
||||||
|
|
||||||
// aJson.addStringToObject(out,"type", "rect");
|
// aJson.addStringToObject(out,"type", "rect");
|
||||||
/*
|
|
||||||
#ifdef __SAM3X8E__
|
|
||||||
node.begin(9600,UARTClass::Mode_8E1,13);
|
|
||||||
#else
|
|
||||||
node.begin(9600,SERIAL_8E1,13);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
node.setSlave(getArg());
|
|
||||||
*/
|
|
||||||
|
|
||||||
modbusSerial.begin(9600,fmPar);
|
modbusSerial.begin(9600,fmPar);
|
||||||
node.begin(getArg(),modbusSerial);
|
node.begin(getArg(),modbusSerial);
|
||||||
|
|
||||||
@@ -920,14 +880,6 @@ result = node.readHoldingRegisters(20-1, 4);
|
|||||||
if (modbusBusy) return -1;
|
if (modbusBusy) return -1;
|
||||||
modbusBusy=1;
|
modbusBusy=1;
|
||||||
|
|
||||||
/*
|
|
||||||
#ifdef __SAM3X8E__
|
|
||||||
node.begin(9600,UARTClass::Mode_8E1,13);
|
|
||||||
#else
|
|
||||||
node.begin(9600,SERIAL_8E1,13);
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
|
|
||||||
uint8_t result;
|
uint8_t result;
|
||||||
|
|
||||||
uint16_t addr = getArg(0);
|
uint16_t addr = getArg(0);
|
||||||
|
|||||||
2
item.h
2
item.h
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright © 2017 Andrey Klimov. All rights reserved.
|
/* Copyright © 2017-2018 Andrey Klimov. All rights reserved.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
|||||||
338
lighthub.ino
338
lighthub.ino
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright © 2017 Andrey Klimov. All rights reserved.
|
/* Copyright © 2017-2018 Andrey Klimov. All rights reserved.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -25,7 +25,7 @@ e-mail anklimov@gmail.com
|
|||||||
* 1-wire
|
* 1-wire
|
||||||
* DMX - out
|
* DMX - out
|
||||||
* DMX IN
|
* DMX IN
|
||||||
* 1809 strip out
|
* 1809 strip out (discarded)
|
||||||
* Modbus master Out
|
* Modbus master Out
|
||||||
* DHCP
|
* DHCP
|
||||||
* JSON config
|
* JSON config
|
||||||
@@ -44,26 +44,24 @@ PID Termostat out
|
|||||||
dmx relay out
|
dmx relay out
|
||||||
Relay array channel
|
Relay array channel
|
||||||
Relay DMX array channel
|
Relay DMX array channel
|
||||||
|
Config URL configuration
|
||||||
|
|
||||||
Portation issues DUE:
|
todo DUE related:
|
||||||
DMX in (new lib) - to do
|
DMX in (new lib) - to do
|
||||||
load and get fails (and then hungs)
|
|
||||||
EEPROM
|
|
||||||
HTTP
|
HTTP
|
||||||
|
PWM freq fix
|
||||||
|
Config webserver
|
||||||
|
|
||||||
Portation ESP:
|
todo ESP:
|
||||||
Ethernet
|
Ethernet - to wifi portation
|
||||||
|
DMX-OUT deploy on USART1
|
||||||
|
Config webserver
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//define NOETHER
|
|
||||||
// Configuration of drivers enabled
|
// Configuration of drivers enabled
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include <Ethernet.h>
|
#include <Ethernet.h>
|
||||||
#include <PubSubClient2.h>
|
#include <PubSubClient2.h>
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
@@ -76,24 +74,29 @@ Ethernet
|
|||||||
#include "stdarg.h"
|
#include "stdarg.h"
|
||||||
|
|
||||||
#if defined(__AVR__)
|
#if defined(__AVR__)
|
||||||
|
#include "HTTPClient.h"
|
||||||
#include <avr/pgmspace.h>
|
#include <avr/pgmspace.h>
|
||||||
#include <avr/wdt.h>
|
#include <avr/wdt.h>
|
||||||
#include "HTTPClient.h"
|
#define wdt_en() wdt_enable(WDTO_8S)
|
||||||
|
#define wdt_dis() wdt_disable()
|
||||||
|
#define wdt_res() wdt_reset()
|
||||||
|
#else
|
||||||
|
#include <ArduinoHttpClient.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__SAM3X8E__)
|
#if defined(__SAM3X8E__)
|
||||||
#include <DueFlashStorage.h>
|
#include <DueFlashStorage.h>
|
||||||
DueFlashStorage EEPROM;
|
DueFlashStorage EEPROM;
|
||||||
#include <malloc.h>
|
#include <watchdog.h>
|
||||||
|
#define wdt_res() watchdogReset()
|
||||||
|
#define wdt_en()
|
||||||
|
#define wdt_dis()
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#include <EEPROM.h>
|
#include <EEPROM.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(ESP_PLATFORM)
|
#if defined(ESP_PLATFORM)
|
||||||
//extern "C" {
|
|
||||||
//#include "user_interface.h"
|
|
||||||
//}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _owire
|
#ifdef _owire
|
||||||
@@ -115,8 +118,8 @@ extern Artnet *artnet;
|
|||||||
// Hardcoded definitions
|
// Hardcoded definitions
|
||||||
//Thermostate histeresys
|
//Thermostate histeresys
|
||||||
#define GIST 2
|
#define GIST 2
|
||||||
#define serverip "192.168.88.2"
|
//#define serverip "192.168.88.2"
|
||||||
IPAddress server(192, 168, 88, 2); //TODO - configure it
|
//IPAddress server(192, 168, 88, 2); //TODO - configure it
|
||||||
//char* inprefix=("/myhome/in/");
|
//char* inprefix=("/myhome/in/");
|
||||||
//char* outprefix=("/myhome/s_out/");
|
//char* outprefix=("/myhome/s_out/");
|
||||||
//char* subprefix=("/myhome/in/#");
|
//char* subprefix=("/myhome/in/#");
|
||||||
@@ -132,6 +135,7 @@ aJsonObject *inputs = NULL;
|
|||||||
aJsonObject *mqttArr = NULL;
|
aJsonObject *mqttArr = NULL;
|
||||||
aJsonObject *modbusArr = NULL;
|
aJsonObject *modbusArr = NULL;
|
||||||
aJsonObject *owArr = NULL;
|
aJsonObject *owArr = NULL;
|
||||||
|
aJsonObject *dmxArr = NULL;
|
||||||
|
|
||||||
unsigned long modbuscheck=0;
|
unsigned long modbuscheck=0;
|
||||||
unsigned long incheck =0;
|
unsigned long incheck =0;
|
||||||
@@ -153,54 +157,9 @@ EthernetClient ethClient;
|
|||||||
PubSubClient client(ethClient);
|
PubSubClient client(ethClient);
|
||||||
|
|
||||||
|
|
||||||
int modbusSet(int addr, uint16_t _reg, int _mask, uint16_t value);
|
void watchdogSetup(void){} //Do not remove - strong re-definition WDT Init for DUE
|
||||||
short thermoSetCurTemp(char * name, short t);
|
|
||||||
int freeRam (void) ;
|
|
||||||
|
|
||||||
|
|
||||||
int itemCtrl2(char* name,int r,int g, int b, int w)
|
|
||||||
{
|
|
||||||
aJsonObject *itemArr= aJson.getObjectItem(items, name);
|
|
||||||
|
|
||||||
if (itemArr && (itemArr->type==aJson_Array))
|
|
||||||
{
|
|
||||||
|
|
||||||
short itemtype = aJson.getArrayItem(itemArr,0)->valueint;
|
|
||||||
short itemaddr = aJson.getArrayItem(itemArr,1)->valueint;
|
|
||||||
switch (itemtype){
|
|
||||||
case 0: //Dimmed light
|
|
||||||
//// if (is_on) DmxWrite(5, 255); //ArduinoDmx2.TxBuffer[itemaddr[ch]]=255;//
|
|
||||||
//// else DmxWrite(itemaddr, map(Par1,0,100,0,255)); //ArduinoDmx2.TxBuffer[itemaddr[ch]]=map(Par1,0,100,0,255);//
|
|
||||||
break;
|
|
||||||
|
|
||||||
#ifdef _dmxout
|
|
||||||
case 1: //Colour RGBW
|
|
||||||
DmxWrite(itemaddr+3, w);
|
|
||||||
|
|
||||||
case 2: // RGB
|
|
||||||
{
|
|
||||||
|
|
||||||
DmxWrite(itemaddr, r);
|
|
||||||
DmxWrite(itemaddr+1, g);
|
|
||||||
DmxWrite(itemaddr+2, b);
|
|
||||||
|
|
||||||
break; }
|
|
||||||
#endif
|
|
||||||
case 7: //Group
|
|
||||||
aJsonObject *groupArr= aJson.getArrayItem(itemArr, 1);
|
|
||||||
if (groupArr && (groupArr->type==aJson_Array))
|
|
||||||
{ aJsonObject *i =groupArr->child;
|
|
||||||
while (i)
|
|
||||||
{ //Serial.println(i->valuestring);
|
|
||||||
itemCtrl2(i->valuestring,r,g,b,w);
|
|
||||||
i=i->next;}
|
|
||||||
}
|
|
||||||
} //itemtype
|
|
||||||
// break;
|
|
||||||
} //if have correct array
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
// MQTT Callback routine
|
||||||
void callback(char* topic, byte* payload, unsigned int length) {
|
void callback(char* topic, byte* payload, unsigned int length) {
|
||||||
payload[length]=0;
|
payload[length]=0;
|
||||||
Serial.print(F("["));
|
Serial.print(F("["));
|
||||||
@@ -314,41 +273,43 @@ void restoreState()
|
|||||||
|
|
||||||
int getConfig (int arg_cnt, char **args);
|
int getConfig (int arg_cnt, char **args);
|
||||||
int lanLoop() {
|
int lanLoop() {
|
||||||
static short _once=1;
|
|
||||||
|
|
||||||
#ifdef NOETHER
|
#ifdef NOETHER
|
||||||
lanStatus=-11;
|
lanStatus=-14;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//Serial.println(lanStatus);
|
//Serial.println(lanStatus);
|
||||||
switch (lanStatus)
|
switch (lanStatus)
|
||||||
|
|
||||||
{
|
{
|
||||||
|
//Initial state
|
||||||
case 0: //Ethernet.begin(mac,ip);
|
case 0: //Ethernet.begin(mac,ip);
|
||||||
Serial.println(F("Starting lan"));
|
Serial.println(F("Starting lan"));
|
||||||
if (Ethernet.begin(mac) == 0) {
|
wdt_dis();
|
||||||
|
if (Ethernet.begin(mac,12000) == 0) {
|
||||||
Serial.println(F("Failed to configure Ethernet using DHCP"));
|
Serial.println(F("Failed to configure Ethernet using DHCP"));
|
||||||
lanStatus = -10;
|
lanStatus = -10;
|
||||||
lanCheck=millis()+5000;
|
lanCheck=millis()+60000;
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
printIPAddress();
|
printIPAddress();
|
||||||
lanStatus = 1;
|
lanStatus = 1;
|
||||||
}
|
}
|
||||||
|
wdt_en();
|
||||||
|
wdt_res();
|
||||||
break;
|
break;
|
||||||
|
//Have IP address
|
||||||
case 1:
|
case 1:
|
||||||
|
|
||||||
lanStatus=getConfig(0,NULL); //from server
|
lanStatus=getConfig(0,NULL); //got config from server or load from NVRAM
|
||||||
#ifdef _artnet
|
#ifdef _artnet
|
||||||
if (artnet) artnet->begin();
|
if (artnet) artnet->begin();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 2: // IP Ready, Connecting & subscribe
|
case 2: // IP Ready, config loaded, Connecting broker & subscribe
|
||||||
//Arming Watchdog
|
//Arming Watchdog
|
||||||
#if defined(__AVR_ATmega2560__)
|
wdt_res();
|
||||||
wdt_enable(WDTO_8S);
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
short n=0;
|
short n=0;
|
||||||
int port=1883;
|
int port=1883;
|
||||||
@@ -412,21 +373,16 @@ break;
|
|||||||
case -11:
|
case -11:
|
||||||
if (loadConfig(0,NULL)) lanStatus=2;
|
if (loadConfig(0,NULL)) lanStatus=2;
|
||||||
else {lanCheck=millis()+5000;lanStatus=-10;}
|
else {lanCheck=millis()+5000;lanStatus=-10;}
|
||||||
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case -14: ;
|
||||||
|
// do notghing with net
|
||||||
}
|
}
|
||||||
//static long mtnCnt=0;
|
|
||||||
// Maintain dynamic IP
|
|
||||||
//if (millis()>mtnCnt)
|
|
||||||
{
|
|
||||||
//mtnCnt=millis()+2;
|
|
||||||
#if defined(__AVR_ATmega2560__)
|
|
||||||
wdt_disable();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
switch (Ethernet.maintain())
|
{
|
||||||
|
wdt_dis();
|
||||||
|
if (lanStatus>0)
|
||||||
|
switch (Ethernet.maintain())
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
//renewed fail
|
//renewed fail
|
||||||
@@ -461,9 +417,9 @@ switch (Ethernet.maintain())
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
#if defined(__AVR_ATmega2560__)
|
|
||||||
wdt_enable(WDTO_8S);
|
wdt_en();
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return lanStatus;
|
return lanStatus;
|
||||||
@@ -553,15 +509,6 @@ void Changed (int i, DeviceAddress addr, int val)
|
|||||||
{
|
{
|
||||||
thermoSetCurTemp(owItem,val); ///TODO: Refactore using Items interface
|
thermoSetCurTemp(owItem,val); ///TODO: Refactore using Items interface
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//client.publish(addrstr, valstr);
|
|
||||||
|
|
||||||
//Serial.print(addrstr);
|
|
||||||
//Serial.print(" = ");
|
|
||||||
//Serial.println(valstr);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -575,10 +522,10 @@ void _handleHelp(int arg_cnt, char **args)
|
|||||||
|
|
||||||
void _kill(int arg_cnt, char **args)
|
void _kill(int arg_cnt, char **args)
|
||||||
{
|
{
|
||||||
for (short i=9;i>0;i--) {delay(1000);Serial.println(i);};
|
for (short i=17;i>0;i--) {delay(1000);Serial.println(i);};
|
||||||
}
|
}
|
||||||
|
|
||||||
#define EEPROM_offset 40
|
#define EEPROM_offset 32+6
|
||||||
|
|
||||||
void parseConfig()
|
void parseConfig()
|
||||||
{ int mc,incnt;
|
{ int mc,incnt;
|
||||||
@@ -650,8 +597,12 @@ void parseConfig()
|
|||||||
void _loadConfig (int arg_cnt, char **args) {loadConfig(arg_cnt,args);restoreState();}
|
void _loadConfig (int arg_cnt, char **args) {loadConfig(arg_cnt,args);restoreState();}
|
||||||
int loadConfig (int arg_cnt, char **args)
|
int loadConfig (int arg_cnt, char **args)
|
||||||
//(char* tokens)
|
//(char* tokens)
|
||||||
{
|
{ char ch;
|
||||||
Serial.println(F("loading Config"));
|
Serial.println(F("loading Config"));
|
||||||
|
|
||||||
|
ch=EEPROM.read(EEPROM_offset);
|
||||||
|
if (ch=='{')
|
||||||
|
{
|
||||||
aJsonEEPROMStream as=aJsonEEPROMStream(EEPROM_offset);
|
aJsonEEPROMStream as=aJsonEEPROMStream(EEPROM_offset);
|
||||||
aJson.deleteItem(root);
|
aJson.deleteItem(root);
|
||||||
root = aJson.parse(&as);
|
root = aJson.parse(&as);
|
||||||
@@ -664,6 +615,13 @@ int loadConfig (int arg_cnt, char **args)
|
|||||||
Serial.println(F("Loaded"));
|
Serial.println(F("Loaded"));
|
||||||
parseConfig();
|
parseConfig();
|
||||||
return 1;
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Serial.println(F("No stored config"));
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _mqttConfigReq (int arg_cnt, char **args) {mqttConfigReq(arg_cnt,args);restoreState();}
|
void _mqttConfigReq (int arg_cnt, char **args) {mqttConfigReq(arg_cnt,args);restoreState();}
|
||||||
@@ -746,28 +704,42 @@ void _getConfig(int arg_cnt, char **args) {getConfig(arg_cnt,args);restoreState(
|
|||||||
void printBool (bool arg)
|
void printBool (bool arg)
|
||||||
{if (arg) Serial.println(F("on")); else Serial.println(F("off"));}
|
{if (arg) Serial.println(F("on")); else Serial.println(F("off"));}
|
||||||
|
|
||||||
|
|
||||||
|
void saveFlash(short n, char* str)
|
||||||
|
{}
|
||||||
|
|
||||||
|
void loadFlash(short n, char* str)
|
||||||
|
{}
|
||||||
|
|
||||||
int getConfig (int arg_cnt, char **args)
|
int getConfig (int arg_cnt, char **args)
|
||||||
//(char *tokens)
|
//(char *tokens)
|
||||||
{
|
{
|
||||||
FILE* result;
|
|
||||||
int returnCode ;
|
|
||||||
char ch;
|
|
||||||
char URI[32];
|
|
||||||
|
|
||||||
char server[] = "lazyhome.ru";
|
|
||||||
|
int returnCode =0;
|
||||||
|
char ch;
|
||||||
|
char URI [32];
|
||||||
|
char server[32] = "lazyhome.ru";
|
||||||
|
if (arg_cnt>0) {
|
||||||
|
strncpy(server,args[1],sizeof(server)-1);
|
||||||
|
saveFlash(0,server);
|
||||||
|
}
|
||||||
|
else loadFlash(0,server);
|
||||||
|
|
||||||
snprintf(URI, sizeof(URI), "/%02x-%02x-%02x-%02x-%02x-%02x.config.json",mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
snprintf(URI, sizeof(URI), "/%02x-%02x-%02x-%02x-%02x-%02x.config.json",mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||||
Serial.println(F("Config URI: "));Serial.println(URI);
|
Serial.println(F("Config URI: "));Serial.print(F("http://"));Serial.print(server);Serial.println(URI);
|
||||||
|
|
||||||
#if defined(__AVR__)
|
#if defined(__AVR__)
|
||||||
byte hserver[] = { 192,168,88,2 };
|
FILE* result;
|
||||||
HTTPClient hclient(serverip,hserver,80);
|
//byte hserver[] = { 192,168,88,2 };
|
||||||
|
wdt_dis();
|
||||||
|
HTTPClient hclient(server,80);
|
||||||
|
|
||||||
|
|
||||||
// FILE is the return STREAM type of the HTTPClient
|
// FILE is the return STREAM type of the HTTPClient
|
||||||
result = hclient.getURI( URI);
|
result = hclient.getURI( URI);
|
||||||
returnCode = hclient.getLastReturnCode();
|
returnCode = hclient.getLastReturnCode();
|
||||||
|
wdt_en();
|
||||||
if (result!=NULL) {
|
if (result!=NULL) {
|
||||||
if (returnCode==200) {
|
if (returnCode==200) {
|
||||||
|
|
||||||
@@ -809,60 +781,60 @@ int getConfig (int arg_cnt, char **args)
|
|||||||
lanCheck=millis()+5000;
|
lanCheck=millis()+5000;
|
||||||
return -11;
|
return -11;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
// Dummy http client
|
//Non AVR code
|
||||||
// if you get a connection, report back via serial:
|
String response;
|
||||||
if (ethClient.connect(server, 80)) {
|
|
||||||
Serial.println(F("connected"));
|
HttpClient htclient = HttpClient(ethClient, server, 80);
|
||||||
// Make a HTTP request:
|
htclient.setHttpResponseTimeout(4000);
|
||||||
ethClient.print(F("GET "));
|
wdt_res();
|
||||||
ethClient.print(URI);
|
//Serial.println("making GET request");
|
||||||
ethClient.println(F(" HTTP/1.1"));
|
htclient.beginRequest();
|
||||||
ethClient.print(F("Host: "));
|
htclient.get(URI);
|
||||||
ethClient.println(server);
|
htclient.endRequest();
|
||||||
ethClient.println("Connection: close");
|
|
||||||
ethClient.println();
|
|
||||||
} else {
|
// read the status code and body of the response
|
||||||
// if you didn't get a connection to the server:
|
returnCode = htclient.responseStatusCode();
|
||||||
Serial.println("connection failed");
|
response = htclient.responseBody();
|
||||||
}
|
htclient.stop();
|
||||||
#define buflen 16000
|
wdt_res();
|
||||||
unsigned long t=millis()+10000;
|
Serial.print("HTTP Status code: ");
|
||||||
char buf [buflen];
|
Serial.println(returnCode);
|
||||||
int i=0;
|
//Serial.print("GET Response: ");
|
||||||
while (millis()<t)
|
|
||||||
|
if (returnCode==200)
|
||||||
{
|
{
|
||||||
if (ethClient.available()) {
|
|
||||||
buf[i] = ethClient.read();
|
|
||||||
Serial.print(buf[i]);
|
|
||||||
if (buf[i]=='{' || i>0) i++;
|
|
||||||
if (i>=buflen-1) break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ethClient.stop();
|
|
||||||
|
|
||||||
buf[i]=0;
|
|
||||||
Serial.println(buf);
|
|
||||||
|
|
||||||
aJson.deleteItem(root);
|
aJson.deleteItem(root);
|
||||||
root = aJson.parse(buf);
|
root = aJson.parse((char*) response.c_str());
|
||||||
|
|
||||||
if (!root)
|
if (!root)
|
||||||
{
|
{
|
||||||
Serial.println(F("Config parsing failed"));
|
Serial.println(F("Config parsing failed"));
|
||||||
lanCheck=millis()+15000;
|
// lanCheck=millis()+15000;
|
||||||
return -11;
|
return -11; //Load from NVRAM
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
char * outstr=aJson.print(root);
|
char * outstr=aJson.print(root);
|
||||||
Serial.println(outstr);
|
Serial.println(outstr);
|
||||||
free (outstr);
|
free (outstr);
|
||||||
|
*/
|
||||||
|
Serial.println(response);
|
||||||
parseConfig();
|
parseConfig();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Serial.println(F("Config retrieving failed"));
|
||||||
|
//lanCheck=millis()+15000;
|
||||||
|
return -11; //Load from NVRAM
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
return 2;
|
return 2;
|
||||||
@@ -876,7 +848,7 @@ void preTransmission()
|
|||||||
|
|
||||||
void postTransmission()
|
void postTransmission()
|
||||||
{
|
{
|
||||||
modbusSerial.flush();
|
//modbusSerial.flush();
|
||||||
digitalWrite(TXEnablePin, 0);
|
digitalWrite(TXEnablePin, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -885,7 +857,7 @@ void setup() {
|
|||||||
|
|
||||||
cmdInit(115200);
|
cmdInit(115200);
|
||||||
|
|
||||||
Serial.println(F("\nLazyhome.ru LightHub controller v0.94"));
|
Serial.println(F("\nLazyhome.ru LightHub controller v0.95"));
|
||||||
|
|
||||||
short macvalid=0;
|
short macvalid=0;
|
||||||
byte defmac[6]={0xDE,0xAD,0xBE,0xEF,0xFE,0};
|
byte defmac[6]={0xDE,0xAD,0xBE,0xEF,0xFE,0};
|
||||||
@@ -902,22 +874,13 @@ void setup() {
|
|||||||
}
|
}
|
||||||
printMACAddress();
|
printMACAddress();
|
||||||
|
|
||||||
|
loadConfig(0,NULL);
|
||||||
|
|
||||||
#ifdef _modbus
|
#ifdef _modbus
|
||||||
pinMode(TXEnablePin,OUTPUT);
|
pinMode(TXEnablePin,OUTPUT);
|
||||||
modbusSerial.begin(9600);
|
modbusSerial.begin(9600);
|
||||||
|
|
||||||
/*
|
|
||||||
// initialize Modbus communication baud rate
|
|
||||||
#ifdef __SAM3X8E__
|
|
||||||
node.begin(9600,UARTClass::Mode_8E1,13);
|
|
||||||
#else
|
|
||||||
node.begin(9600,SERIAL_8E1,13);
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
node.idle(&modbusIdle);
|
node.idle(&modbusIdle);
|
||||||
|
|
||||||
// Callbacks allow us to configure the RS485 transceiver correctly
|
// Callbacks allow us to configure the RS485 transceiver correctly
|
||||||
node.preTransmission(preTransmission);
|
node.preTransmission(preTransmission);
|
||||||
node.postTransmission(postTransmission);
|
node.postTransmission(postTransmission);
|
||||||
@@ -926,15 +889,12 @@ void setup() {
|
|||||||
delay(20);
|
delay(20);
|
||||||
|
|
||||||
owReady=0;
|
owReady=0;
|
||||||
//=owSetup(&Changed);
|
|
||||||
|
|
||||||
#ifdef _owire
|
#ifdef _owire
|
||||||
if (net) net->idle(&owIdle);
|
if (net) net->idle(&owIdle);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
//client.setServer(server, 1883);
|
||||||
|
|
||||||
client.setServer(server, 1883);
|
|
||||||
client.setCallback(callback);
|
client.setCallback(callback);
|
||||||
|
|
||||||
|
|
||||||
@@ -959,9 +919,7 @@ void setup() {
|
|||||||
|
|
||||||
|
|
||||||
void loop(){
|
void loop(){
|
||||||
#if defined(__AVR_ATmega2560__)
|
wdt_res();
|
||||||
wdt_reset();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//commandLine.update();
|
//commandLine.update();
|
||||||
cmdPoll();
|
cmdPoll();
|
||||||
@@ -1004,9 +962,7 @@ void owIdle(void)
|
|||||||
if (artnet) artnet->read();
|
if (artnet) artnet->read();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__AVR_ATmega2560__)
|
wdt_res();
|
||||||
wdt_reset();
|
|
||||||
#endif
|
|
||||||
return;///
|
return;///
|
||||||
Serial.print("o");
|
Serial.print("o");
|
||||||
|
|
||||||
@@ -1024,9 +980,8 @@ if (lanLoop() == 1) client.loop();
|
|||||||
void modbusIdle(void)
|
void modbusIdle(void)
|
||||||
{
|
{
|
||||||
//Serial.print("m");
|
//Serial.print("m");
|
||||||
#if defined(__AVR_ATmega2560__)
|
|
||||||
wdt_reset();
|
wdt_res();
|
||||||
#endif
|
|
||||||
if (lanLoop() > 1)
|
if (lanLoop() > 1)
|
||||||
{
|
{
|
||||||
client.loop();
|
client.loop();
|
||||||
@@ -1073,8 +1028,6 @@ void inputLoop(void)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void modbusLoop(void)
|
void modbusLoop(void)
|
||||||
{
|
{
|
||||||
boolean done=false;
|
boolean done=false;
|
||||||
@@ -1203,40 +1156,3 @@ if (items)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if defined(ESP_PLATFORM)
|
|
||||||
int freeRam ()
|
|
||||||
{return system_get_free_heap_size();}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(__AVR__)
|
|
||||||
int freeRam ()
|
|
||||||
{
|
|
||||||
extern int __heap_start, *__brkval;
|
|
||||||
int v;
|
|
||||||
return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(__SAM3X8E__)
|
|
||||||
extern char _end;
|
|
||||||
extern "C" char *sbrk(int i);
|
|
||||||
|
|
||||||
int freeRam()
|
|
||||||
{
|
|
||||||
char *ramstart = (char *) 0x20070000;
|
|
||||||
char *ramend = (char *) 0x20088000;
|
|
||||||
char *heapend = sbrk(0);
|
|
||||||
register char * stack_ptr asm( "sp" );
|
|
||||||
struct mallinfo mi = mallinfo();
|
|
||||||
/*
|
|
||||||
Serial << "Ram used (bytes): " << endl
|
|
||||||
<< " dynamic: " << mi.uordblks << endl
|
|
||||||
<< " static: " << &_end - ramstart << endl
|
|
||||||
<< " stack: " << ramend - stack_ptr << endl;
|
|
||||||
Serial << "Estimation free Ram: " << stack_ptr - heapend + mi.fordblks << endl;
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
return stack_ptr - heapend + mi.fordblks;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|||||||
@@ -14,9 +14,7 @@
|
|||||||
#if defined(__SAM3X8E__)
|
#if defined(__SAM3X8E__)
|
||||||
/// DMX not deployed yet
|
/// DMX not deployed yet
|
||||||
#undef _dmxin
|
#undef _dmxin
|
||||||
//#undef _dmxout
|
|
||||||
#define modbusSerial Serial2
|
#define modbusSerial Serial2
|
||||||
//#include <DmxDue.h>
|
|
||||||
#define dmxout DmxDue4
|
#define dmxout DmxDue4
|
||||||
#define dmxin DmxDue1
|
#define dmxin DmxDue1
|
||||||
#endif
|
#endif
|
||||||
@@ -24,7 +22,6 @@
|
|||||||
#if defined(ESP_PLATFORM)
|
#if defined(ESP_PLATFORM)
|
||||||
#undef _dmxin
|
#undef _dmxin
|
||||||
#undef _dmxout
|
#undef _dmxout
|
||||||
//#undef _modbus
|
|
||||||
#define modbusSerial Serial
|
#define modbusSerial Serial
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright © 2017 Andrey Klimov. (anklimov@gmail.com) All rights reserved.
|
/* Copyright © 2017-2018 Andrey Klimov. (anklimov@gmail.com) All rights reserved.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright © 2017 Andrey Klimov. All rights reserved.
|
/* Copyright © 2017-2018 Andrey Klimov. All rights reserved.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright © 2017 Andrey Klimov. All rights reserved.
|
/* Copyright © 2017-2018 Andrey Klimov. All rights reserved.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
|||||||
2
owTerm.h
2
owTerm.h
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright © 2017 Andrey Klimov. All rights reserved.
|
/* Copyright © 2017-2018 Andrey Klimov. All rights reserved.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
|||||||
35
utils.cpp
35
utils.cpp
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright © 2017 Andrey Klimov. All rights reserved.
|
/* Copyright © 2017-2018 Andrey Klimov. All rights reserved.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -19,6 +19,9 @@ e-mail anklimov@gmail.com
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#if defined(__SAM3X8E__)
|
||||||
|
#include <malloc.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
void PrintBytes(uint8_t* addr, uint8_t count, bool newline) {
|
void PrintBytes(uint8_t* addr, uint8_t count, bool newline) {
|
||||||
for (uint8_t i = 0; i < count; i++) {
|
for (uint8_t i = 0; i < count; i++) {
|
||||||
@@ -70,3 +73,33 @@ int getInt(char ** chan)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(ESP_PLATFORM)
|
||||||
|
int freeRam ()
|
||||||
|
{return system_get_free_heap_size();}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(__AVR__)
|
||||||
|
int freeRam ()
|
||||||
|
{
|
||||||
|
extern int __heap_start, *__brkval;
|
||||||
|
int v;
|
||||||
|
return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(__SAM3X8E__)
|
||||||
|
extern char _end;
|
||||||
|
extern "C" char *sbrk(int i);
|
||||||
|
|
||||||
|
int 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
|
||||||
|
|||||||
3
utils.h
3
utils.h
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright © 2017 Andrey Klimov. All rights reserved.
|
/* Copyright © 2017-2018 Andrey Klimov. All rights reserved.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -24,3 +24,4 @@ void SetBytes(uint8_t* addr, uint8_t count, char * out);
|
|||||||
void SetAddr(char * out, uint8_t* addr);
|
void SetAddr(char * out, uint8_t* addr);
|
||||||
uint8_t HEX2DEC(char i);
|
uint8_t HEX2DEC(char i);
|
||||||
int getInt(char ** chan);
|
int getInt(char ** chan);
|
||||||
|
int freeRam ();
|
||||||
|
|||||||
Reference in New Issue
Block a user