mirror of
https://github.com/anklimov/lighthub
synced 2025-12-06 11:49:51 +03:00
Many portation and conditional compilation directives added, Modbus refactored and moved to almost original lib, MQTT server,port,user,password configuration added to JSON
This commit is contained in:
4
DUE_to_replace_sysfile/path.txt
Normal file
4
DUE_to_replace_sysfile/path.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
To avoid interrupt corflicts between DmxDue an USART1 need to copy patched file over DUE sys lib
|
||||
|
||||
Patch example for OSX:
|
||||
/Users/andrey/Library/Arduino15/packages/arduino/hardware/sam/1.6.11/variants/arduino_due_x/variant.cpp
|
||||
453
DUE_to_replace_sysfile/variant.cpp
Normal file
453
DUE_to_replace_sysfile/variant.cpp
Normal file
@@ -0,0 +1,453 @@
|
||||
/*
|
||||
Copyright (c) 2011 Arduino. All right reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
See the GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "variant.h"
|
||||
|
||||
/*
|
||||
* DUE Board pin | PORT | Label
|
||||
* ----------------+--------+-------
|
||||
* 0 | PA8 | "RX0"
|
||||
* 1 | PA9 | "TX0"
|
||||
* 2 TIOA0 | PB25 |
|
||||
* 3 TIOA7 | PC28 |
|
||||
* 4 NPCS1 | PA29 |
|
||||
* TIOB6 | PC26 |
|
||||
* 5 TIOA6 | PC25 |
|
||||
* 6 PWML7 | PC24 |
|
||||
* 7 PWML6 | PC23 |
|
||||
* 8 PWML5 | PC22 |
|
||||
* 9 PWML4 | PC21 |
|
||||
* 10 NPCS0 | PA28 |
|
||||
* TIOB7 | PC29 |
|
||||
* 11 TIOA8 | PD7 |
|
||||
* 12 TIOB8 | PD8 |
|
||||
* 13 TIOB0 | PB27 | LED AMBER "L"
|
||||
* 14 TXD3 | PD4 | "TX3"
|
||||
* 15 RXD3 | PD5 | "RX3"
|
||||
* 16 TXD1 | PA13 | "TX2"
|
||||
* 17 RXD1 | PA12 | "RX2"
|
||||
* 18 TXD0 | PA11 | "TX1"
|
||||
* 19 RXD0 | PA10 | "RX1"
|
||||
* 20 | PB12 | "SDA"
|
||||
* 21 | PB13 | "SCL"
|
||||
* 22 | PB26 |
|
||||
* 23 | PA14 |
|
||||
* 24 | PA15 |
|
||||
* 25 | PD0 |
|
||||
* 26 | PD1 |
|
||||
* 27 | PD2 |
|
||||
* 28 | PD3 |
|
||||
* 29 | PD6 |
|
||||
* 30 | PD9 |
|
||||
* 31 | PA7 |
|
||||
* 32 | PD10 |
|
||||
* 33 | PC1 |
|
||||
* 34 | PC2 |
|
||||
* 35 | PC3 |
|
||||
* 36 | PC4 |
|
||||
* 37 | PC5 |
|
||||
* 38 | PC6 |
|
||||
* 39 | PC7 |
|
||||
* 40 | PC8 |
|
||||
* 41 | PC9 |
|
||||
* 42 | PA19 |
|
||||
* 43 | PA20 |
|
||||
* 44 | PC19 |
|
||||
* 45 | PC18 |
|
||||
* 46 | PC17 |
|
||||
* 47 | PC16 |
|
||||
* 48 | PC15 |
|
||||
* 49 | PC14 |
|
||||
* 50 | PC13 |
|
||||
* 51 | PC12 |
|
||||
* 52 NPCS2 | PB21 |
|
||||
* 53 | PB14 |
|
||||
* 54 | PA16 | "A0"
|
||||
* 55 | PA24 | "A1"
|
||||
* 56 | PA23 | "A2"
|
||||
* 57 | PA22 | "A3"
|
||||
* 58 TIOB2 | PA6 | "A4"
|
||||
* 69 | PA4 | "A5"
|
||||
* 60 TIOB1 | PA3 | "A6"
|
||||
* 61 TIOA1 | PA2 | "A7"
|
||||
* 62 | PB17 | "A8"
|
||||
* 63 | PB18 | "A9"
|
||||
* 64 | PB19 | "A10"
|
||||
* 65 | PB20 | "A11"
|
||||
* 66 | PB15 | "DAC0"
|
||||
* 67 | PB16 | "DAC1"
|
||||
* 68 | PA1 | "CANRX"
|
||||
* 69 | PA0 | "CANTX"
|
||||
* 70 | PA17 | "SDA1"
|
||||
* 71 | PA18 | "SCL1"
|
||||
* 72 | PC30 | LED AMBER "RX"
|
||||
* 73 | PA21 | LED AMBER "TX"
|
||||
* 74 MISO | PA25 |
|
||||
* 75 MOSI | PA26 |
|
||||
* 76 SCLK | PA27 |
|
||||
* 77 NPCS0 | PA28 |
|
||||
* 78 NPCS3 | PB23 | unconnected!
|
||||
*
|
||||
* USB pin | PORT
|
||||
* ----------------+--------
|
||||
* ID | PB11
|
||||
* VBOF | PB10
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Pins descriptions
|
||||
*/
|
||||
extern const PinDescription g_APinDescription[]=
|
||||
{
|
||||
// 0 .. 53 - Digital pins
|
||||
// ----------------------
|
||||
// 0/1 - UART (Serial)
|
||||
{ PIOA, PIO_PA8A_URXD, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // URXD
|
||||
{ PIOA, PIO_PA9A_UTXD, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // UTXD
|
||||
|
||||
// 2
|
||||
{ PIOB, PIO_PB25B_TIOA0, ID_PIOB, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_TIMER), NO_ADC, NO_ADC, NOT_ON_PWM, TC0_CHA0 }, // TIOA0
|
||||
{ PIOC, PIO_PC28B_TIOA7, ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_TIMER), NO_ADC, NO_ADC, NOT_ON_PWM, TC2_CHA7 }, // TIOA7
|
||||
{ PIOC, PIO_PC26B_TIOB6, ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_TIMER), NO_ADC, NO_ADC, NOT_ON_PWM, TC2_CHB6 }, // TIOB6
|
||||
|
||||
// 5
|
||||
{ PIOC, PIO_PC25B_TIOA6, ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_TIMER), NO_ADC, NO_ADC, NOT_ON_PWM, TC2_CHA6 }, // TIOA6
|
||||
{ PIOC, PIO_PC24B_PWML7, ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), NO_ADC, NO_ADC, PWM_CH7, NOT_ON_TIMER }, // PWML7
|
||||
{ PIOC, PIO_PC23B_PWML6, ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), NO_ADC, NO_ADC, PWM_CH6, NOT_ON_TIMER }, // PWML6
|
||||
{ PIOC, PIO_PC22B_PWML5, ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), NO_ADC, NO_ADC, PWM_CH5, NOT_ON_TIMER }, // PWML5
|
||||
{ PIOC, PIO_PC21B_PWML4, ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), NO_ADC, NO_ADC, PWM_CH4, NOT_ON_TIMER }, // PWML4
|
||||
// 10
|
||||
{ PIOC, PIO_PC29B_TIOB7, ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_TIMER), NO_ADC, NO_ADC, NOT_ON_PWM, TC2_CHB7 }, // TIOB7
|
||||
{ PIOD, PIO_PD7B_TIOA8, ID_PIOD, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_TIMER), NO_ADC, NO_ADC, NOT_ON_PWM, TC2_CHA8 }, // TIOA8
|
||||
{ PIOD, PIO_PD8B_TIOB8, ID_PIOD, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_TIMER), NO_ADC, NO_ADC, NOT_ON_PWM, TC2_CHB8 }, // TIOB8
|
||||
|
||||
// 13 - AMBER LED
|
||||
{ PIOB, PIO_PB27B_TIOB0, ID_PIOB, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_TIMER), NO_ADC, NO_ADC, NOT_ON_PWM, TC0_CHB0 }, // TIOB0
|
||||
|
||||
// 14/15 - USART3 (Serial3)
|
||||
{ PIOD, PIO_PD4B_TXD3, ID_PIOD, PIO_PERIPH_B, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // TXD3
|
||||
{ PIOD, PIO_PD5B_RXD3, ID_PIOD, PIO_PERIPH_B, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // RXD3
|
||||
|
||||
// 16/17 - USART1 (Serial2)
|
||||
{ PIOA, PIO_PA13A_TXD1, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // TXD1
|
||||
{ PIOA, PIO_PA12A_RXD1, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // RXD1
|
||||
|
||||
// 18/19 - USART0 (Serial1)
|
||||
{ PIOA, PIO_PA11A_TXD0, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // TXD0
|
||||
{ PIOA, PIO_PA10A_RXD0, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // RXD0
|
||||
|
||||
// 20/21 - TWI1
|
||||
{ PIOB, PIO_PB12A_TWD1, ID_PIOB, PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // TWD1 - SDA0
|
||||
{ PIOB, PIO_PB13A_TWCK1, ID_PIOB, PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // TWCK1 - SCL0
|
||||
|
||||
// 22
|
||||
{ PIOB, PIO_PB26, ID_PIOB, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 22
|
||||
{ PIOA, PIO_PA14, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 23
|
||||
{ PIOA, PIO_PA15, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 24
|
||||
{ PIOD, PIO_PD0, ID_PIOD, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 25
|
||||
|
||||
// 26
|
||||
{ PIOD, PIO_PD1, ID_PIOD, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 26
|
||||
{ PIOD, PIO_PD2, ID_PIOD, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 27
|
||||
{ PIOD, PIO_PD3, ID_PIOD, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 28
|
||||
{ PIOD, PIO_PD6, ID_PIOD, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 29
|
||||
|
||||
// 30
|
||||
{ PIOD, PIO_PD9, ID_PIOD, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 30
|
||||
{ PIOA, PIO_PA7, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 31
|
||||
{ PIOD, PIO_PD10, ID_PIOD, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 32
|
||||
{ PIOC, PIO_PC1, ID_PIOC, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 33
|
||||
|
||||
// 34
|
||||
{ PIOC, PIO_PC2, ID_PIOC, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 34
|
||||
{ PIOC, PIO_PC3, ID_PIOC, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 35
|
||||
{ PIOC, PIO_PC4, ID_PIOC, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 36
|
||||
{ PIOC, PIO_PC5, ID_PIOC, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 37
|
||||
|
||||
// 38
|
||||
{ PIOC, PIO_PC6, ID_PIOC, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 38
|
||||
{ PIOC, PIO_PC7, ID_PIOC, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 39
|
||||
{ PIOC, PIO_PC8, ID_PIOC, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 40
|
||||
{ PIOC, PIO_PC9, ID_PIOC, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 41
|
||||
|
||||
// 42
|
||||
{ PIOA, PIO_PA19, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 42
|
||||
{ PIOA, PIO_PA20, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 43
|
||||
{ PIOC, PIO_PC19, ID_PIOC, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 44
|
||||
{ PIOC, PIO_PC18, ID_PIOC, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 45
|
||||
|
||||
// 46
|
||||
{ PIOC, PIO_PC17, ID_PIOC, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 46
|
||||
{ PIOC, PIO_PC16, ID_PIOC, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 47
|
||||
{ PIOC, PIO_PC15, ID_PIOC, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 48
|
||||
{ PIOC, PIO_PC14, ID_PIOC, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 49
|
||||
|
||||
// 50
|
||||
{ PIOC, PIO_PC13, ID_PIOC, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 50
|
||||
{ PIOC, PIO_PC12, ID_PIOC, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 51
|
||||
{ PIOB, PIO_PB21, ID_PIOB, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 52
|
||||
{ PIOB, PIO_PB14, ID_PIOB, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // PIN 53
|
||||
|
||||
|
||||
// 54 .. 65 - Analog pins
|
||||
// ----------------------
|
||||
{ PIOA, PIO_PA16X1_AD7, ID_PIOA, PIO_INPUT, PIO_DEFAULT, PIN_ATTR_ANALOG, ADC0, ADC7, NOT_ON_PWM, NOT_ON_TIMER }, // AD0
|
||||
{ PIOA, PIO_PA24X1_AD6, ID_PIOA, PIO_INPUT, PIO_DEFAULT, PIN_ATTR_ANALOG, ADC1, ADC6, NOT_ON_PWM, NOT_ON_TIMER }, // AD1
|
||||
{ PIOA, PIO_PA23X1_AD5, ID_PIOA, PIO_INPUT, PIO_DEFAULT, PIN_ATTR_ANALOG, ADC2, ADC5, NOT_ON_PWM, NOT_ON_TIMER }, // AD2
|
||||
{ PIOA, PIO_PA22X1_AD4, ID_PIOA, PIO_INPUT, PIO_DEFAULT, PIN_ATTR_ANALOG, ADC3, ADC4, NOT_ON_PWM, NOT_ON_TIMER }, // AD3
|
||||
// 58
|
||||
{ PIOA, PIO_PA6X1_AD3, ID_PIOA, PIO_INPUT, PIO_DEFAULT, PIN_ATTR_ANALOG, ADC4, ADC3, NOT_ON_PWM, TC0_CHB2 }, // AD4
|
||||
{ PIOA, PIO_PA4X1_AD2, ID_PIOA, PIO_INPUT, PIO_DEFAULT, PIN_ATTR_ANALOG, ADC5, ADC2, NOT_ON_PWM, NOT_ON_TIMER }, // AD5
|
||||
{ PIOA, PIO_PA3X1_AD1, ID_PIOA, PIO_INPUT, PIO_DEFAULT, PIN_ATTR_ANALOG, ADC6, ADC1, NOT_ON_PWM, TC0_CHB1 }, // AD6
|
||||
{ PIOA, PIO_PA2X1_AD0, ID_PIOA, PIO_INPUT, PIO_DEFAULT, PIN_ATTR_ANALOG, ADC7, ADC0, NOT_ON_PWM, TC0_CHA1 }, // AD7
|
||||
// 62
|
||||
{ PIOB, PIO_PB17X1_AD10, ID_PIOB, PIO_INPUT, PIO_DEFAULT, PIN_ATTR_ANALOG, ADC8, ADC10, NOT_ON_PWM, NOT_ON_TIMER }, // AD8
|
||||
{ PIOB, PIO_PB18X1_AD11, ID_PIOB, PIO_INPUT, PIO_DEFAULT, PIN_ATTR_ANALOG, ADC9, ADC11, NOT_ON_PWM, NOT_ON_TIMER }, // AD9
|
||||
{ PIOB, PIO_PB19X1_AD12, ID_PIOB, PIO_INPUT, PIO_DEFAULT, PIN_ATTR_ANALOG, ADC10, ADC12, NOT_ON_PWM, NOT_ON_TIMER }, // AD10
|
||||
{ PIOB, PIO_PB20X1_AD13, ID_PIOB, PIO_INPUT, PIO_DEFAULT, PIN_ATTR_ANALOG, ADC11, ADC13, NOT_ON_PWM, NOT_ON_TIMER }, // AD11
|
||||
|
||||
// 66/67 - DAC0/DAC1
|
||||
{ PIOB, PIO_PB15X1_DAC0, ID_PIOB, PIO_INPUT, PIO_DEFAULT, PIN_ATTR_ANALOG, ADC12, DA0, NOT_ON_PWM, NOT_ON_TIMER }, // DAC0
|
||||
{ PIOB, PIO_PB16X1_DAC1, ID_PIOB, PIO_INPUT, PIO_DEFAULT, PIN_ATTR_ANALOG, ADC13, DA1, NOT_ON_PWM, NOT_ON_TIMER }, // DAC1
|
||||
|
||||
// 68/69 - CANRX0/CANTX0
|
||||
{ PIOA, PIO_PA1A_CANRX0, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL, ADC14, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // CANRX
|
||||
{ PIOA, PIO_PA0A_CANTX0, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL, ADC15, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // CANTX
|
||||
|
||||
// 70/71 - TWI0
|
||||
{ PIOA, PIO_PA17A_TWD0, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // TWD0 - SDA1
|
||||
{ PIOA, PIO_PA18A_TWCK0, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // TWCK0 - SCL1
|
||||
|
||||
// 72/73 - LEDs
|
||||
{ PIOC, PIO_PC30, ID_PIOC, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // LED AMBER RXL
|
||||
{ PIOA, PIO_PA21, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // LED AMBER TXL
|
||||
|
||||
// 74/75/76 - SPI
|
||||
{ PIOA, PIO_PA25A_SPI0_MISO,ID_PIOA,PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // MISO
|
||||
{ PIOA, PIO_PA26A_SPI0_MOSI,ID_PIOA,PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // MOSI
|
||||
{ PIOA, PIO_PA27A_SPI0_SPCK,ID_PIOA,PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // SPCK
|
||||
|
||||
// 77 - SPI CS0
|
||||
{ PIOA, PIO_PA28A_SPI0_NPCS0,ID_PIOA,PIO_PERIPH_A,PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // NPCS0
|
||||
|
||||
// 78 - SPI CS3 (unconnected)
|
||||
{ PIOB, PIO_PB23B_SPI0_NPCS3,ID_PIOB,PIO_PERIPH_B,PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // NPCS3
|
||||
|
||||
// 79 .. 84 - "All pins" masks
|
||||
|
||||
// 79 - TWI0 all pins
|
||||
{ PIOA, PIO_PA17A_TWD0|PIO_PA18A_TWCK0, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_COMBO), NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER },
|
||||
// 80 - TWI1 all pins
|
||||
{ PIOB, PIO_PB12A_TWD1|PIO_PB13A_TWCK1, ID_PIOB, PIO_PERIPH_A, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_COMBO), NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER },
|
||||
// 81 - UART (Serial) all pins
|
||||
{ PIOA, PIO_PA8A_URXD|PIO_PA9A_UTXD, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_COMBO), NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER },
|
||||
// 82 - USART0 (Serial1) all pins
|
||||
{ PIOA, PIO_PA11A_TXD0|PIO_PA10A_RXD0, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_COMBO), NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER },
|
||||
// 83 - USART1 (Serial2) all pins
|
||||
{ PIOA, PIO_PA13A_TXD1|PIO_PA12A_RXD1, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_COMBO), NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER },
|
||||
// 84 - USART3 (Serial3) all pins
|
||||
{ PIOD, PIO_PD4B_TXD3|PIO_PD5B_RXD3, ID_PIOD, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_COMBO), NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER },
|
||||
|
||||
// 85 - USB
|
||||
{ PIOB, PIO_PB11A_UOTGID|PIO_PB10A_UOTGVBOF, ID_PIOB, PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL,NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // ID - VBOF
|
||||
|
||||
// 86 - SPI CS2
|
||||
{ PIOB, PIO_PB21B_SPI0_NPCS2, ID_PIOB, PIO_PERIPH_B, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // NPCS2
|
||||
|
||||
// 87 - SPI CS1
|
||||
{ PIOA, PIO_PA29A_SPI0_NPCS1, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // NPCS1
|
||||
|
||||
// 88/89 - CANRX1/CANTX1 (same physical pin for 66/53)
|
||||
{ PIOB, PIO_PB15A_CANRX1, ID_PIOB, PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // CANRX1
|
||||
{ PIOB, PIO_PB14A_CANTX1, ID_PIOB, PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // CANTX1
|
||||
|
||||
// 90 .. 91 - "All CAN pins" masks
|
||||
// 90 - CAN0 all pins
|
||||
{ PIOA, PIO_PA1A_CANRX0|PIO_PA0A_CANTX0, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_COMBO), NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER },
|
||||
// 91 - CAN1 all pins
|
||||
{ PIOB, PIO_PB15A_CANRX1|PIO_PB14A_CANTX1, ID_PIOB, PIO_PERIPH_A, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_COMBO), NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER },
|
||||
|
||||
// END
|
||||
{ NULL, 0, 0, PIO_NOT_A_PIN, PIO_DEFAULT, 0, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }
|
||||
} ;
|
||||
|
||||
|
||||
uint8_t g_pinStatus[PINS_COUNT] = {0};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* UART objects
|
||||
*/
|
||||
RingBuffer rx_buffer1;
|
||||
RingBuffer tx_buffer1;
|
||||
|
||||
UARTClass Serial(UART, UART_IRQn, ID_UART, &rx_buffer1, &tx_buffer1);
|
||||
void serialEvent() __attribute__((weak));
|
||||
void serialEvent() { }
|
||||
|
||||
// IT handlers
|
||||
void UART_Handler(void)
|
||||
{
|
||||
Serial.IrqHandler();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/*
|
||||
* USART objects
|
||||
*/
|
||||
RingBuffer rx_buffer2;
|
||||
RingBuffer rx_buffer3;
|
||||
RingBuffer rx_buffer4;
|
||||
RingBuffer tx_buffer2;
|
||||
RingBuffer tx_buffer3;
|
||||
RingBuffer tx_buffer4;
|
||||
|
||||
USARTClass Serial1(USART0, USART0_IRQn, ID_USART0, &rx_buffer2, &tx_buffer2);
|
||||
void serialEvent1() __attribute__((weak));
|
||||
void serialEvent1() { }
|
||||
USARTClass Serial2(USART1, USART1_IRQn, ID_USART1, &rx_buffer3, &tx_buffer3);
|
||||
void serialEvent2() __attribute__((weak));
|
||||
void serialEvent2() { }
|
||||
USARTClass Serial3(USART3, USART3_IRQn, ID_USART3, &rx_buffer4, &tx_buffer4);
|
||||
void serialEvent3() __attribute__((weak));
|
||||
void serialEvent3() { }
|
||||
|
||||
// IT handlers
|
||||
void USART0_Handler(void)
|
||||
{
|
||||
Serial1.IrqHandler();
|
||||
}
|
||||
|
||||
///void USART1_Handler(void)
|
||||
///{
|
||||
/// Serial2.IrqHandler();
|
||||
///}
|
||||
|
||||
void USART3_Handler(void)
|
||||
{
|
||||
Serial3.IrqHandler();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void serialEventRun(void)
|
||||
{
|
||||
if (Serial.available()) serialEvent();
|
||||
if (Serial1.available()) serialEvent1();
|
||||
/// if (Serial2.available()) serialEvent2();
|
||||
if (Serial3.available()) serialEvent3();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void __libc_init_array(void);
|
||||
|
||||
void init( void )
|
||||
{
|
||||
SystemInit();
|
||||
|
||||
// Set Systick to 1ms interval, common to all SAM3 variants
|
||||
if (SysTick_Config(SystemCoreClock / 1000))
|
||||
{
|
||||
// Capture error
|
||||
while (true);
|
||||
}
|
||||
|
||||
// Initialize C library
|
||||
__libc_init_array();
|
||||
|
||||
// Disable pull-up on every pin
|
||||
for (unsigned i = 0; i < PINS_COUNT; i++)
|
||||
digitalWrite(i, LOW);
|
||||
|
||||
// Enable parallel access on PIO output data registers
|
||||
PIOA->PIO_OWER = 0xFFFFFFFF;
|
||||
PIOB->PIO_OWER = 0xFFFFFFFF;
|
||||
PIOC->PIO_OWER = 0xFFFFFFFF;
|
||||
PIOD->PIO_OWER = 0xFFFFFFFF;
|
||||
|
||||
// Initialize Serial port U(S)ART pins
|
||||
PIO_Configure(
|
||||
g_APinDescription[PINS_UART].pPort,
|
||||
g_APinDescription[PINS_UART].ulPinType,
|
||||
g_APinDescription[PINS_UART].ulPin,
|
||||
g_APinDescription[PINS_UART].ulPinConfiguration);
|
||||
digitalWrite(0, HIGH); // Enable pullup for RX0
|
||||
PIO_Configure(
|
||||
g_APinDescription[PINS_USART0].pPort,
|
||||
g_APinDescription[PINS_USART0].ulPinType,
|
||||
g_APinDescription[PINS_USART0].ulPin,
|
||||
g_APinDescription[PINS_USART0].ulPinConfiguration);
|
||||
PIO_Configure(
|
||||
g_APinDescription[PINS_USART1].pPort,
|
||||
g_APinDescription[PINS_USART1].ulPinType,
|
||||
g_APinDescription[PINS_USART1].ulPin,
|
||||
g_APinDescription[PINS_USART1].ulPinConfiguration);
|
||||
PIO_Configure(
|
||||
g_APinDescription[PINS_USART3].pPort,
|
||||
g_APinDescription[PINS_USART3].ulPinType,
|
||||
g_APinDescription[PINS_USART3].ulPin,
|
||||
g_APinDescription[PINS_USART3].ulPinConfiguration);
|
||||
|
||||
// Initialize USB pins
|
||||
PIO_Configure(
|
||||
g_APinDescription[PINS_USB].pPort,
|
||||
g_APinDescription[PINS_USB].ulPinType,
|
||||
g_APinDescription[PINS_USB].ulPin,
|
||||
g_APinDescription[PINS_USB].ulPinConfiguration);
|
||||
|
||||
// Initialize CAN pins
|
||||
PIO_Configure(
|
||||
g_APinDescription[PINS_CAN0].pPort,
|
||||
g_APinDescription[PINS_CAN0].ulPinType,
|
||||
g_APinDescription[PINS_CAN0].ulPin,
|
||||
g_APinDescription[PINS_CAN0].ulPinConfiguration);
|
||||
PIO_Configure(
|
||||
g_APinDescription[PINS_CAN1].pPort,
|
||||
g_APinDescription[PINS_CAN1].ulPinType,
|
||||
g_APinDescription[PINS_CAN1].ulPin,
|
||||
g_APinDescription[PINS_CAN1].ulPinConfiguration);
|
||||
|
||||
// Initialize Analog Controller
|
||||
pmc_enable_periph_clk(ID_ADC);
|
||||
adc_init(ADC, SystemCoreClock, ADC_FREQ_MAX, ADC_STARTUP_FAST);
|
||||
adc_configure_timing(ADC, 0, ADC_SETTLING_TIME_3, 1);
|
||||
adc_configure_trigger(ADC, ADC_TRIG_SW, 0); // Disable hardware trigger.
|
||||
adc_disable_interrupt(ADC, 0xFFFFFFFF); // Disable all ADC interrupts.
|
||||
adc_disable_all_channel(ADC);
|
||||
|
||||
// Initialize analogOutput module
|
||||
analogOutputInit();
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
21
README.md
21
README.md
@@ -23,6 +23,12 @@ use
|
||||
avrdude -v -V -patmega2560 -cwiring -b115200 -D -Uflash:w:lighthub.ino.hex:i
|
||||
to flash your Mega 2560
|
||||
|
||||
or
|
||||
|
||||
/Users/<user>/Library/Arduino15/packages/arduino/tools/bossac/1.6.1-arduino/bossac -i -d --port=cu.usbmodem1451 -U false -e -w -v -b lighthub.ino.bin -R
|
||||
to flash your DUE
|
||||
|
||||
(need to correct path and port, of course)
|
||||
# Dependences
|
||||
(quite big number of libs required. Use git clone to have your local copy in your Arduino libs folder)
|
||||
|
||||
@@ -43,3 +49,18 @@ For patched libraries, appropriate GitHub repo URL provided:
|
||||
* DMXSerial-master (for AVR) https://github.com/anklimov/DMXSerial
|
||||
* Ethernet https://github.com/anklimov/Ethernet
|
||||
* SPI (standard)
|
||||
|
||||
Portation from AVR Mega 2560 to SAM3X8E (Arduino DUE) and ESP not completed yet and on early stage now.
|
||||
Core is mostly migrated (except EEPROM in DUE)
|
||||
|
||||
AVR version is basic and have all functions
|
||||
|
||||
Another platforms limitations (todo):
|
||||
SAM3X8E:
|
||||
-EEPROM issues to be fixed
|
||||
-DMX-in - not deployed yet
|
||||
-Improve http client
|
||||
|
||||
ESP:
|
||||
-Wifi instead Ether not implemented yet
|
||||
-DMX-IN
|
||||
|
||||
BIN
compiled/DUE/lighthub.ino.bin
Executable file
BIN
compiled/DUE/lighthub.ino.bin
Executable file
Binary file not shown.
3348
compiled/Mega2560/lighthub.ino.hex
Normal file
3348
compiled/Mega2560/lighthub.ino.hex
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -40,6 +40,7 @@
|
||||
"fm_h":[8,"fm"]
|
||||
|
||||
},
|
||||
"mqtt":["192.168.88.2","light"]
|
||||
"mqtt":["public_test2","m21.cloudmqtt.com",12299,"bkyyvlha","RpHF-x6v4YWb"]
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"mqtt":["192.168.88.2","teplo"],
|
||||
"mqtt":["public_test1","m21.cloudmqtt.com",12299,"bkyyvlha","RpHF-x6v4YWb"],
|
||||
"ow":{
|
||||
"2807FFD503000036":{"emit":"t_balk1","item":"h_balk1"},
|
||||
"284811170400005B":{"emit":"t_entr"},
|
||||
|
||||
46
dmx.cpp
46
dmx.cpp
@@ -19,14 +19,22 @@ e-mail anklimov@gmail.com
|
||||
*/
|
||||
#include "dmx.h"
|
||||
//#include <DmxSimple.h>
|
||||
//#include <Artnet.h>
|
||||
//#include <DMXSerial.h>
|
||||
#include "options.h"
|
||||
#ifdef _dmxin
|
||||
#include <DMXSerial.h>
|
||||
#endif
|
||||
|
||||
uint8_t * DMXin = NULL;
|
||||
int D_State=0;
|
||||
|
||||
unsigned long D_checkT=0;
|
||||
|
||||
#ifdef _artnet
|
||||
#include <Artnet.h>
|
||||
Artnet *artnet = NULL;
|
||||
#endif
|
||||
|
||||
aJsonObject *dmxArr = NULL;
|
||||
|
||||
void DMXImmediateUpdate(short tch,short r, short g, short b, short w) {
|
||||
@@ -57,7 +65,7 @@ for (short tch=0; tch<=3 ; tch++)
|
||||
|
||||
void DMXUpdate(void)
|
||||
{
|
||||
#if defined(__AVR_ATmega2560__)
|
||||
#if defined(_dmxin)
|
||||
int t;
|
||||
for (short tch=0; tch<=3 ; tch++)
|
||||
{
|
||||
@@ -90,7 +98,7 @@ for (short tch=0; tch<=3 ; tch++)
|
||||
{
|
||||
// CHSV hsv;
|
||||
// CRGB rgb;
|
||||
#if defined(__AVR_ATmega2560__)
|
||||
#if defined(_dmxin)
|
||||
|
||||
short t,tch;
|
||||
//Here code for semi-immediate update
|
||||
@@ -110,7 +118,9 @@ D_checkT=0;
|
||||
// Here code for network update
|
||||
//int ch = 0;
|
||||
DMXput();
|
||||
#ifdef _dmxout
|
||||
for (int i=1; i<17; i++) {Serial.print(DMXSerial.read(i));Serial.print(";");}
|
||||
#endif
|
||||
Serial.println();
|
||||
#endif
|
||||
}
|
||||
@@ -118,10 +128,12 @@ for (int i=1; i<17; i++) {Serial.print(DMXSerial.read(i));Serial.print(";");}
|
||||
|
||||
void onDmxFrame(uint16_t universe, uint16_t length, uint8_t sequence, uint8_t* data)
|
||||
{
|
||||
#ifdef _dmxout
|
||||
for (int i = 0 ; i < length && i<MAX_CHANNELS ; i++)
|
||||
{
|
||||
DmxSimple.write(i+1,data[i]);
|
||||
DmxWrite(i+1,data[i]);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void DMXinSetup(int channels)
|
||||
@@ -129,8 +141,8 @@ void DMXinSetup(int channels)
|
||||
// //Use digital pin 3 for DMX output. Must be a PWM channel.
|
||||
// DmxSimple.usePin(pin);
|
||||
//DmxSimple.maxChannel(channels);
|
||||
#if defined(__AVR_ATmega2560__)
|
||||
|
||||
#if defined(_dmxin)
|
||||
DMXin = new uint8_t [channels];
|
||||
|
||||
DMXSerial.init(DMXReceiver,0,channels);
|
||||
@@ -138,13 +150,37 @@ void DMXinSetup(int channels)
|
||||
//DMXSerial.maxChannel(channels);
|
||||
DMXSerial.attachOnUpdate(&DMXUpdate);
|
||||
#endif
|
||||
|
||||
#ifdef _artnet
|
||||
// this will be called for each packet received
|
||||
if (artnet) artnet->setArtDmxCallback(onDmxFrame);
|
||||
#endif
|
||||
}
|
||||
|
||||
void DMXoutSetup(int channels,int pin)
|
||||
{
|
||||
#ifdef _dmxout
|
||||
#if defined(__AVR__)
|
||||
DmxSimple.usePin(pin);
|
||||
DmxSimple.maxChannel(channels);
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(__ESP__)
|
||||
#endif
|
||||
|
||||
#if defined(__SAM3X8E__)
|
||||
dmxout.setTxMaxChannels(channels);
|
||||
dmxout.beginWrite();
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void ArtnetSetup()
|
||||
{
|
||||
#ifdef _artnet
|
||||
if (!artnet) artnet = new Artnet;
|
||||
// this will be called for each packet received
|
||||
if (artnet) artnet->setArtDmxCallback(onDmxFrame);
|
||||
#endif
|
||||
}
|
||||
|
||||
17
dmx.h
17
dmx.h
@@ -29,8 +29,13 @@ e-mail anklimov@gmail.com
|
||||
|
||||
//#define DMX_OUT_PIN 3
|
||||
|
||||
#include "options.h"
|
||||
|
||||
#if defined(_dmxout)
|
||||
|
||||
#if defined(__AVR__)
|
||||
#include <DmxSimple.h>
|
||||
#define DmxWrite DmxSimple.write
|
||||
#endif
|
||||
|
||||
#if defined(__ESP__)
|
||||
@@ -38,23 +43,29 @@ e-mail anklimov@gmail.com
|
||||
#endif
|
||||
|
||||
#if defined(__SAM3X8E__)
|
||||
#include <DmxSimple.h>
|
||||
#include <DmxDue.h>
|
||||
#define DmxWrite dmxout.write
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef _artnet
|
||||
#include <Artnet.h>
|
||||
extern Artnet *artnet;
|
||||
#endif
|
||||
|
||||
#if defined(__AVR_ATmega2560__)
|
||||
#ifdef _dmxin
|
||||
#include <DMXSerial.h>
|
||||
#endif
|
||||
|
||||
#include "aJSON.h"
|
||||
|
||||
extern aJsonObject *dmxArr;
|
||||
extern Artnet *artnet;
|
||||
|
||||
|
||||
void DMXput(void);
|
||||
void DMXinSetup(int channels);
|
||||
void DMXoutSetup(int channels,int pin);
|
||||
void ArtnetSetup();
|
||||
void DMXCheck(void);
|
||||
int itemCtrl2(char* name,int r,int g, int b, int w);
|
||||
void ArtnetSetup();
|
||||
|
||||
124
item.cpp
124
item.cpp
@@ -20,6 +20,10 @@ e-mail anklimov@gmail.com
|
||||
|
||||
#include "item.h"
|
||||
#include "aJSON.h"
|
||||
|
||||
#ifdef _dmxout
|
||||
|
||||
/*
|
||||
#if defined(__AVR__)
|
||||
#include <DmxSimple.h>
|
||||
#endif
|
||||
@@ -29,14 +33,18 @@ e-mail anklimov@gmail.com
|
||||
#endif
|
||||
|
||||
#if defined(__SAM3X8E__)
|
||||
#include <DmxSimple.h>
|
||||
#include <DmxDue.h>
|
||||
#endif
|
||||
*/
|
||||
#include "dmx.h"
|
||||
#include "FastLED.h"
|
||||
#endif
|
||||
|
||||
#include "FastLED.h"
|
||||
#include <ModbusMaster.h>
|
||||
#include <PubSubClient2.h>
|
||||
|
||||
|
||||
#define dimPar SERIAL_8E1
|
||||
#define fmPar SERIAL_8N1
|
||||
|
||||
short modbusBusy=0;
|
||||
extern aJsonObject * modbusitem;
|
||||
@@ -183,6 +191,14 @@ void Item::copyPar (aJsonObject *itemV)
|
||||
}
|
||||
*/
|
||||
|
||||
#ifdef ESP32
|
||||
void analogWrite(int pin, int val)
|
||||
{
|
||||
//TBD
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
boolean Item::getEnableCMD(int delta)
|
||||
{
|
||||
return ((millis()-lastctrl>(unsigned long) delta) );//|| (itemArr!=lastobj));
|
||||
@@ -387,18 +403,23 @@ int Item::Ctrl(short cmd, short n, int * Par, boolean send)
|
||||
|
||||
switch (itemType)
|
||||
{
|
||||
|
||||
#ifdef _dmxout
|
||||
case CH_DIMMER: //Dimmed light
|
||||
|
||||
DmxSimple.write(iaddr, map(Par[0],0,100,0,255));
|
||||
DmxWrite(iaddr, map(Par[0],0,100,0,255));
|
||||
|
||||
break;
|
||||
|
||||
|
||||
case CH_RGBW: //Colour RGBW
|
||||
{
|
||||
int k;
|
||||
DmxSimple.write(iaddr+3, k=map((100-Par[1])*Par[2],0,10000,0,255));
|
||||
DmxWrite(iaddr+3, k=map((100-Par[1])*Par[2],0,10000,0,255));
|
||||
Serial.print(F("W:"));Serial.println(k);
|
||||
}
|
||||
|
||||
|
||||
case CH_RGB: // RGB
|
||||
|
||||
{
|
||||
@@ -406,20 +427,23 @@ int Item::Ctrl(short cmd, short n, int * Par, boolean send)
|
||||
|
||||
CRGB rgb= CHSV(map(Par[0],0,365,0,255),map(Par[1],0,100,0,255),map(Par[2],0,100,0,255));
|
||||
|
||||
DmxSimple.write(iaddr, rgb.r);
|
||||
DmxSimple.write(iaddr+1, rgb.g);
|
||||
DmxSimple.write(iaddr+2, rgb.b);
|
||||
DmxWrite(iaddr, rgb.r);
|
||||
DmxWrite(iaddr+1, rgb.g);
|
||||
DmxWrite(iaddr+2, rgb.b);
|
||||
|
||||
|
||||
break; }
|
||||
|
||||
case CH_WHITE:
|
||||
DmxSimple.write(iaddr, 0);
|
||||
DmxSimple.write(iaddr+1, 0);
|
||||
DmxSimple.write(iaddr+2, 0);
|
||||
DmxSimple.write(iaddr+3, map(Par[2],0,100,0,255));
|
||||
break;
|
||||
|
||||
case CH_WHITE:
|
||||
DmxWrite(iaddr, 0);
|
||||
DmxWrite(iaddr+1, 0);
|
||||
DmxWrite(iaddr+2, 0);
|
||||
DmxWrite(iaddr+3, map(Par[2],0,100,0,255));
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef _modbus
|
||||
case CH_MODBUS:
|
||||
{
|
||||
|
||||
@@ -432,6 +456,7 @@ int Item::Ctrl(short cmd, short n, int * Par, boolean send)
|
||||
modbusSet(_addr,_reg,_mask,map(Par[0],0,100,0,0x3f));
|
||||
}
|
||||
break;}
|
||||
#endif
|
||||
|
||||
case CH_GROUP://Group
|
||||
{
|
||||
@@ -489,7 +514,7 @@ int Item::Ctrl(short cmd, short n, int * Par, boolean send)
|
||||
Serial.print(F("Pin:"));Serial.print(iaddr);Serial.print(F("="));Serial.println(k);
|
||||
break;
|
||||
}
|
||||
|
||||
#ifdef _modbus
|
||||
case CH_VC:
|
||||
|
||||
VacomSetFan(Par[0],cmd);
|
||||
@@ -503,7 +528,7 @@ int Item::Ctrl(short cmd, short n, int * Par, boolean send)
|
||||
VacomSetHeat(it.getArg(),Par[0],cmd);
|
||||
break;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} // switch itemtype
|
||||
// break;
|
||||
@@ -639,9 +664,20 @@ int Item::VacomSetFan (int8_t val, int8_t cmd)
|
||||
|
||||
uint8_t j, result;
|
||||
uint16_t data[1];
|
||||
node.begin(9600,SERIAL_8N1,13);
|
||||
|
||||
/*
|
||||
#ifdef __SAM3X8E__
|
||||
node.begin(9600,UARTClass::Mode_8E1,13);
|
||||
#else
|
||||
node.begin(9600,SERIAL_8E1,13);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
node.setSlave(addr);
|
||||
*/
|
||||
modbusSerial.begin(9600,fmPar);
|
||||
node.begin(addr,modbusSerial);
|
||||
|
||||
if (val) {
|
||||
node.writeSingleRegister(2001-1,4+1);//delay(500);
|
||||
@@ -667,9 +703,19 @@ 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);
|
||||
if (modbusBusy) {mb_fail(2,addr,val,cmd);return -1;}
|
||||
modbusBusy=1;
|
||||
/*
|
||||
#ifdef __SAM3X8E__
|
||||
node.begin(9600,UARTClass::Mode_8E1,13);
|
||||
#else
|
||||
node.begin(9600,SERIAL_8E1,13);
|
||||
#endif
|
||||
|
||||
node.begin(9600,SERIAL_8N1,13);
|
||||
node.setSlave(addr);
|
||||
*/
|
||||
|
||||
modbusSerial.begin(9600,fmPar);
|
||||
node.begin(addr,modbusSerial);
|
||||
|
||||
uint16_t regval;
|
||||
|
||||
switch (cmd)
|
||||
@@ -745,8 +791,18 @@ int Item::SendCmd(short cmd,short n, int * Par)
|
||||
|
||||
if (modbusBusy) {mb_fail(3,addr,value,0);return -1;};
|
||||
modbusBusy=1;
|
||||
node.begin(9600,SERIAL_8E1,13);
|
||||
/*
|
||||
#ifdef __SAM3X8E__
|
||||
node.begin(9600,UARTClass::Mode_8E1,13);
|
||||
#else
|
||||
node.begin(9600,SERIAL_8E1,13);
|
||||
#endif
|
||||
|
||||
node.setSlave(addr);
|
||||
*/
|
||||
modbusSerial.begin(9600,dimPar);
|
||||
node.begin(addr,modbusSerial);
|
||||
|
||||
|
||||
if (_mask)
|
||||
{value <<= 8; value |= (0xff);}
|
||||
@@ -778,12 +834,20 @@ int Item::checkFM()
|
||||
strncat(addrstr,"_stat",sizeof(addrstr)-1);
|
||||
|
||||
// aJson.addStringToObject(out,"type", "rect");
|
||||
/*
|
||||
#ifdef __SAM3X8E__
|
||||
node.begin(9600,UARTClass::Mode_8E1,13);
|
||||
#else
|
||||
node.begin(9600,SERIAL_8E1,13);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
node.begin(9600,SERIAL_8N1,13);
|
||||
|
||||
node.setSlave(getArg());
|
||||
*/
|
||||
|
||||
modbusSerial.begin(9600,fmPar);
|
||||
node.begin(getArg(),modbusSerial);
|
||||
|
||||
|
||||
result = node.readHoldingRegisters(2101-1, 10);
|
||||
|
||||
@@ -856,8 +920,13 @@ result = node.readHoldingRegisters(20-1, 4);
|
||||
if (modbusBusy) return -1;
|
||||
modbusBusy=1;
|
||||
|
||||
node.begin(9600,SERIAL_8E1,13);
|
||||
//node.begin(9600,UARTClass::Mode_8E1,13);
|
||||
/*
|
||||
#ifdef __SAM3X8E__
|
||||
node.begin(9600,UARTClass::Mode_8E1,13);
|
||||
#else
|
||||
node.begin(9600,SERIAL_8E1,13);
|
||||
#endif
|
||||
*/
|
||||
|
||||
uint8_t result;
|
||||
|
||||
@@ -867,7 +936,12 @@ result = node.readHoldingRegisters(20-1, 4);
|
||||
|
||||
int data;
|
||||
|
||||
node.setSlave(addr);
|
||||
//node.setSlave(addr);
|
||||
|
||||
modbusSerial.begin(9600,dimPar);
|
||||
node.begin(addr,modbusSerial);
|
||||
|
||||
|
||||
result = node.readHoldingRegisters(reg, 1);
|
||||
|
||||
if (result == node.ku8MBSuccess)
|
||||
|
||||
1
item.h
1
item.h
@@ -17,6 +17,7 @@ GIT: https://github.com/anklimov/lighthub
|
||||
e-mail anklimov@gmail.com
|
||||
|
||||
*/
|
||||
#include "options.h"
|
||||
|
||||
#define CH_DIMMER 0 //DMX 1 ch
|
||||
#define CH_RGBW 1 //DMX 4 ch
|
||||
|
||||
335
lighthub.ino
335
lighthub.ino
@@ -42,44 +42,75 @@ analog in local ctrl
|
||||
Smooth regulation/fading
|
||||
PID Termostat out
|
||||
dmx relay out
|
||||
Relay array channel
|
||||
Relay DMX array channel
|
||||
|
||||
Portation issues DUE:
|
||||
DMX in (new lib) - to do
|
||||
load and get fails (and then hungs)
|
||||
EEPROM
|
||||
HTTP
|
||||
|
||||
Portation ESP:
|
||||
Ethernet
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
//define NOETHER
|
||||
// Configuration of drivers enabled
|
||||
#include "options.h"
|
||||
|
||||
|
||||
|
||||
#include <Ethernet.h>
|
||||
#include <PubSubClient2.h>
|
||||
#include <SPI.h>
|
||||
#include "utils.h"
|
||||
#include "owTerm.h"
|
||||
|
||||
//#include "led_sysdefs.h"
|
||||
//#include "pixeltypes.h"
|
||||
//#include "hsv2rgb.h"
|
||||
#include <string.h>
|
||||
#include <ModbusMaster.h>
|
||||
#include "aJSON.h"
|
||||
#include "HTTPClient.h"
|
||||
#include <Cmd.h>
|
||||
#include "stdarg.h"
|
||||
|
||||
#if defined(__AVR__)
|
||||
#include <avr/pgmspace.h>
|
||||
#include <avr/wdt.h>
|
||||
#include "dmx.h"
|
||||
#include "HTTPClient.h"
|
||||
#endif
|
||||
|
||||
#if defined(__SAM3X8E__)
|
||||
#include <DueFlashStorage.h>
|
||||
DueFlashStorage EEPROM;
|
||||
DueFlashStorage EEPROM;
|
||||
#include <malloc.h>
|
||||
|
||||
#else
|
||||
#include <EEPROM.h>
|
||||
#endif
|
||||
|
||||
#if defined(ESP_PLATFORM)
|
||||
//extern "C" {
|
||||
//#include "user_interface.h"
|
||||
//}
|
||||
#endif
|
||||
|
||||
#ifdef _owire
|
||||
#include "owTerm.h"
|
||||
#endif
|
||||
|
||||
#if defined(_dmxin) || defined(_dmxout) || defined (_artnet)
|
||||
#include "dmx.h"
|
||||
#endif
|
||||
|
||||
#include "item.h"
|
||||
#include "inputs.h"
|
||||
#include "dmx.h"
|
||||
|
||||
#ifdef _artnet
|
||||
#include <Artnet.h>
|
||||
extern Artnet *artnet;
|
||||
#endif
|
||||
|
||||
// Hardcoded definitions
|
||||
//Thermostate histeresys
|
||||
@@ -93,7 +124,6 @@ IPAddress server(192, 168, 88, 2); //TODO - configure it
|
||||
#define inprefix "/myhome/in/"
|
||||
const char outprefix[] PROGMEM = "/myhome/s_out/";
|
||||
#define subprefix "/myhome/in/#"
|
||||
//
|
||||
|
||||
aJsonObject *root = NULL;
|
||||
aJsonObject *items = NULL;
|
||||
@@ -110,16 +140,12 @@ unsigned long thermocheck=0;
|
||||
|
||||
aJsonObject * modbusitem= NULL;
|
||||
|
||||
|
||||
// CommandLine instance.
|
||||
//CommandLine commandLine(Serial, "> ");
|
||||
|
||||
|
||||
bool owReady = false;
|
||||
int lanStatus = 0;
|
||||
|
||||
ModbusMaster node(2,0x60); //TODO dynamic alloc
|
||||
|
||||
#ifdef _modbus
|
||||
ModbusMaster node;
|
||||
#endif
|
||||
|
||||
byte mac[6];
|
||||
|
||||
@@ -128,6 +154,7 @@ PubSubClient client(ethClient);
|
||||
|
||||
|
||||
int modbusSet(int addr, uint16_t _reg, int _mask, uint16_t value);
|
||||
short thermoSetCurTemp(char * name, short t);
|
||||
int freeRam (void) ;
|
||||
|
||||
|
||||
@@ -142,21 +169,23 @@ int itemCtrl2(char* name,int r,int g, int b, int w)
|
||||
short itemaddr = aJson.getArrayItem(itemArr,1)->valueint;
|
||||
switch (itemtype){
|
||||
case 0: //Dimmed light
|
||||
//// if (is_on) DmxSimple.write(5, 255); //ArduinoDmx2.TxBuffer[itemaddr[ch]]=255;//
|
||||
//// else DmxSimple.write(itemaddr, map(Par1,0,100,0,255)); //ArduinoDmx2.TxBuffer[itemaddr[ch]]=map(Par1,0,100,0,255);//
|
||||
//// 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
|
||||
DmxSimple.write(itemaddr+3, w);
|
||||
DmxWrite(itemaddr+3, w);
|
||||
|
||||
case 2: // RGB
|
||||
{
|
||||
|
||||
DmxSimple.write(itemaddr, r);
|
||||
DmxSimple.write(itemaddr+1, g);
|
||||
DmxSimple.write(itemaddr+2, b);
|
||||
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))
|
||||
@@ -181,7 +210,8 @@ void callback(char* topic, byte* payload, unsigned int length) {
|
||||
int fr = freeRam();
|
||||
if (fr<250) {Serial.println(F("OOM!"));return;}
|
||||
|
||||
char subtopic[20]="";
|
||||
#define sublen 20
|
||||
char subtopic[sublen]="";
|
||||
int cmd = 0;
|
||||
|
||||
for (int i=0;i<length;i++) {
|
||||
@@ -194,7 +224,7 @@ void callback(char* topic, byte* payload, unsigned int length) {
|
||||
|
||||
cmd= txt2cmd((char*) payload);
|
||||
char * t;
|
||||
if (t=strrchr (topic,'/')) strncpy(subtopic,t+1 , 20);
|
||||
if (t=strrchr (topic,'/')) strncpy(subtopic,t+1 , sublen-1);
|
||||
|
||||
|
||||
|
||||
@@ -309,7 +339,9 @@ break;
|
||||
case 1:
|
||||
|
||||
lanStatus=getConfig(0,NULL); //from server
|
||||
#ifdef _artnet
|
||||
if (artnet) artnet->begin();
|
||||
#endif
|
||||
|
||||
break;
|
||||
case 2: // IP Ready, Connecting & subscribe
|
||||
@@ -317,11 +349,32 @@ break;
|
||||
#if defined(__AVR_ATmega2560__)
|
||||
wdt_enable(WDTO_8S);
|
||||
#endif
|
||||
{
|
||||
short n=0;
|
||||
int port=1883;
|
||||
char empty=0;
|
||||
char * user = ∅
|
||||
char * pass = ∅
|
||||
|
||||
if (!client.connected() && mqttArr && (aJson.getArraySize(mqttArr)>1)) {
|
||||
char *c=aJson.getArrayItem(mqttArr,1)->valuestring;
|
||||
Serial.print(F("Attempting MQTT connection..."));
|
||||
if (client.connect(c)) {
|
||||
if (!client.connected() && mqttArr && ((n=aJson.getArraySize(mqttArr))>1)) {
|
||||
char *c=aJson.getArrayItem(mqttArr,0)->valuestring;
|
||||
char *servername=aJson.getArrayItem(mqttArr,1)->valuestring;
|
||||
if (n>=3) port=aJson.getArrayItem(mqttArr,2)->valueint;
|
||||
|
||||
if (n>=4) user=aJson.getArrayItem(mqttArr,3)->valuestring;
|
||||
if (n>=5) pass=aJson.getArrayItem(mqttArr,4)->valuestring;
|
||||
|
||||
client.setServer(servername,port);
|
||||
|
||||
Serial.print(F("Attempting MQTT connection to "));
|
||||
Serial.print(servername);
|
||||
Serial.print(F(":"));
|
||||
Serial.print(port);
|
||||
Serial.print(F(" user:"));
|
||||
Serial.print(user);
|
||||
Serial.print(F(" ..."));
|
||||
|
||||
if (client.connect(c,user,pass)) {
|
||||
Serial.print(F("connected as "));Serial.println(c);
|
||||
|
||||
|
||||
@@ -341,6 +394,7 @@ if (!client.connected() && mqttArr && (aJson.getArraySize(mqttArr)>1)) {
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 3: //operation
|
||||
if (!client.connected()) lanStatus=2;
|
||||
break;
|
||||
@@ -416,7 +470,7 @@ return lanStatus;
|
||||
|
||||
}
|
||||
|
||||
|
||||
#ifdef _owire
|
||||
void Changed (int i, DeviceAddress addr, int val)
|
||||
{
|
||||
char addrstr[32]="NIL";
|
||||
@@ -509,7 +563,7 @@ void Changed (int i, DeviceAddress addr, int val)
|
||||
//Serial.println(valstr);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void modbusIdle(void) ;
|
||||
|
||||
@@ -530,15 +584,16 @@ void parseConfig()
|
||||
{ int mc,incnt;
|
||||
//DMX out is configured
|
||||
aJsonObject *dmxoutArr = aJson.getObjectItem(root, "dmx");
|
||||
#ifdef _dmxout
|
||||
if (dmxoutArr && aJson.getArraySize(dmxoutArr)==2)
|
||||
{
|
||||
DmxSimple.usePin(aJson.getArrayItem(dmxoutArr,0)->valueint);
|
||||
DmxSimple.maxChannel(mc=aJson.getArrayItem(dmxoutArr,1)->valueint);
|
||||
DMXoutSetup(mc=aJson.getArrayItem(dmxoutArr,1)->valueint,aJson.getArrayItem(dmxoutArr,0)->valueint);
|
||||
Serial.print(F("DMX out started. Channels: "));
|
||||
Serial.println(mc);
|
||||
}
|
||||
|
||||
#endif
|
||||
//DMX in is configured
|
||||
#ifdef _dmxin
|
||||
dmxArr= aJson.getObjectItem(root, "dmxin");
|
||||
if (dmxArr && (incnt=aJson.getArraySize(dmxArr)))
|
||||
{
|
||||
@@ -546,15 +601,21 @@ void parseConfig()
|
||||
Serial.print(F("DMX in started. Channels:"));
|
||||
Serial.println(incnt*4);
|
||||
}
|
||||
#endif
|
||||
|
||||
items = aJson.getObjectItem(root,"items");
|
||||
modbusitem = items->child;
|
||||
inputs = aJson.getObjectItem(root,"in");
|
||||
|
||||
#ifdef _modbus
|
||||
modbusArr= aJson.getObjectItem(root, "modbus");
|
||||
mqttArr= aJson.getObjectItem(root, "mqtt");
|
||||
owArr= aJson.getObjectItem(root, "ow");
|
||||
#endif
|
||||
|
||||
mqttArr= aJson.getObjectItem(root, "mqtt");
|
||||
|
||||
#ifdef _owire
|
||||
owArr= aJson.getObjectItem(root, "ow");
|
||||
#endif
|
||||
|
||||
Serial.println(F("Configured:"));
|
||||
|
||||
@@ -564,6 +625,7 @@ void parseConfig()
|
||||
Serial.print(F("mqtt ")); printBool(mqttArr);
|
||||
Serial.print(F("1-wire ")); printBool(owArr);
|
||||
|
||||
#ifdef _owire
|
||||
if (owArr && !owReady)
|
||||
{
|
||||
aJsonObject * item= owArr->child;
|
||||
@@ -582,7 +644,7 @@ void parseConfig()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
void _loadConfig (int arg_cnt, char **args) {loadConfig(arg_cnt,args);restoreState();}
|
||||
@@ -691,14 +753,17 @@ int getConfig (int arg_cnt, char **args)
|
||||
int returnCode ;
|
||||
char ch;
|
||||
char URI[32];
|
||||
byte hserver[] = { 192,168,88,2 };
|
||||
|
||||
char server[] = "lazyhome.ru";
|
||||
|
||||
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);
|
||||
|
||||
#if defined(__AVR__)
|
||||
byte hserver[] = { 192,168,88,2 };
|
||||
HTTPClient hclient(serverip,hserver,80);
|
||||
|
||||
|
||||
// FILE is the return STREAM type of the HTTPClient
|
||||
result = hclient.getURI( URI);
|
||||
returnCode = hclient.getLastReturnCode();
|
||||
@@ -744,42 +809,141 @@ int getConfig (int arg_cnt, char **args)
|
||||
lanCheck=millis()+5000;
|
||||
return -11;
|
||||
}
|
||||
#else
|
||||
// Dummy http client
|
||||
// if you get a connection, report back via serial:
|
||||
if (ethClient.connect(server, 80)) {
|
||||
Serial.println(F("connected"));
|
||||
// Make a HTTP request:
|
||||
ethClient.print(F("GET "));
|
||||
ethClient.print(URI);
|
||||
ethClient.println(F(" HTTP/1.1"));
|
||||
ethClient.print(F("Host: "));
|
||||
ethClient.println(server);
|
||||
ethClient.println("Connection: close");
|
||||
ethClient.println();
|
||||
} else {
|
||||
// if you didn't get a connection to the server:
|
||||
Serial.println("connection failed");
|
||||
}
|
||||
#define buflen 16000
|
||||
unsigned long t=millis()+10000;
|
||||
char buf [buflen];
|
||||
int i=0;
|
||||
while (millis()<t)
|
||||
{
|
||||
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);
|
||||
root = aJson.parse(buf);
|
||||
|
||||
if (!root)
|
||||
{
|
||||
Serial.println(F("Config parsing failed"));
|
||||
lanCheck=millis()+15000;
|
||||
return -11;
|
||||
}
|
||||
else
|
||||
{
|
||||
char * outstr=aJson.print(root);
|
||||
Serial.println(outstr);
|
||||
free (outstr);
|
||||
|
||||
parseConfig();
|
||||
|
||||
|
||||
}
|
||||
|
||||
return 2;
|
||||
#endif
|
||||
return 2;
|
||||
}
|
||||
|
||||
#define TXEnablePin 13
|
||||
void preTransmission()
|
||||
{
|
||||
digitalWrite(TXEnablePin, 1);
|
||||
}
|
||||
|
||||
void postTransmission()
|
||||
{
|
||||
modbusSerial.flush();
|
||||
digitalWrite(TXEnablePin, 0);
|
||||
}
|
||||
|
||||
void setup() {
|
||||
//Serial.begin(115200);
|
||||
|
||||
|
||||
cmdInit(115200);
|
||||
|
||||
Serial.println(F("\nLazyhome.ru LightHub controller v0.92"));
|
||||
Serial.println(F("\nLazyhome.ru LightHub controller v0.94"));
|
||||
|
||||
short macvalid=0;
|
||||
byte defmac[6]={0xDE,0xAD,0xBE,0xEF,0xFE,0};
|
||||
|
||||
for (short i=0;i<6;i++) mac[i]=EEPROM.read(i);
|
||||
for (short i=0;i<6;i++)
|
||||
{
|
||||
mac[i]=EEPROM.read(i);
|
||||
if (mac[i]!=0 && mac[i]!=0xff) macvalid=1;
|
||||
}
|
||||
if (!macvalid)
|
||||
{
|
||||
Serial.println(F("Invalid MAC: set default"));
|
||||
memcpy(mac,defmac,6);
|
||||
}
|
||||
printMACAddress();
|
||||
|
||||
// initialize Modbus communication baud rate
|
||||
node.begin(9600,SERIAL_8N1,13);
|
||||
|
||||
|
||||
#ifdef _modbus
|
||||
pinMode(TXEnablePin,OUTPUT);
|
||||
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);
|
||||
|
||||
// Callbacks allow us to configure the RS485 transceiver correctly
|
||||
node.preTransmission(preTransmission);
|
||||
node.postTransmission(postTransmission);
|
||||
#endif
|
||||
|
||||
delay(20);
|
||||
|
||||
owReady=0;
|
||||
//=owSetup(&Changed);
|
||||
|
||||
#ifdef _owire
|
||||
if (net) net->idle(&owIdle);
|
||||
node.idle(&modbusIdle);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
client.setServer(server, 1883);
|
||||
client.setCallback(callback);
|
||||
|
||||
|
||||
|
||||
#ifdef _artnet
|
||||
ArtnetSetup();
|
||||
#endif
|
||||
|
||||
#if defined(__SAM3X8E__)
|
||||
checkForRemoteSketchUpdate();
|
||||
// checkForRemoteSketchUpdate();
|
||||
#endif
|
||||
|
||||
cmdAdd("help", _handleHelp);
|
||||
@@ -801,24 +965,45 @@ void loop(){
|
||||
|
||||
//commandLine.update();
|
||||
cmdPoll();
|
||||
if (lanLoop() >1) {client.loop(); if (artnet) artnet->read();}
|
||||
if (owReady && owArr) owLoop();
|
||||
if (lanLoop() >1)
|
||||
{
|
||||
client.loop();
|
||||
#ifdef _artnet
|
||||
if (artnet) artnet->read();
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(__AVR_ATmega2560__)
|
||||
#ifdef _owire
|
||||
if (owReady && owArr) owLoop();
|
||||
#endif
|
||||
|
||||
#ifdef _dmxin
|
||||
unsigned long lastpacket = DMXSerial.noDataSince();
|
||||
DMXCheck();
|
||||
#endif
|
||||
// if (lastpacket && (lastpacket%10==0)) Serial.println(lastpacket);
|
||||
|
||||
DMXCheck();
|
||||
|
||||
|
||||
#ifdef _modbus
|
||||
if (modbusArr && items) modbusLoop();
|
||||
#endif
|
||||
|
||||
#ifdef _owire
|
||||
if (items) thermoLoop();
|
||||
#endif
|
||||
|
||||
if (inputs) inputLoop();
|
||||
|
||||
}
|
||||
|
||||
// Idle handlers
|
||||
void owIdle(void)
|
||||
{ if (artnet) artnet->read();
|
||||
{
|
||||
#ifdef _artnet
|
||||
if (artnet) artnet->read();
|
||||
#endif
|
||||
|
||||
#if defined(__AVR_ATmega2560__)
|
||||
wdt_reset();
|
||||
#endif
|
||||
@@ -827,7 +1012,11 @@ void owIdle(void)
|
||||
|
||||
if (lanLoop() == 1) client.loop();
|
||||
//if (owReady) owLoop();
|
||||
|
||||
#ifdef _dmxin
|
||||
DMXCheck();
|
||||
#endif
|
||||
|
||||
//modbusLoop();
|
||||
}
|
||||
|
||||
@@ -838,9 +1027,18 @@ void modbusIdle(void)
|
||||
#if defined(__AVR_ATmega2560__)
|
||||
wdt_reset();
|
||||
#endif
|
||||
if (lanLoop() > 1) {client.loop();if (artnet) artnet->read();}
|
||||
if (lanLoop() > 1)
|
||||
{
|
||||
client.loop();
|
||||
#ifdef _artnet
|
||||
if (artnet) artnet->read();
|
||||
#endif
|
||||
}
|
||||
|
||||
//if (owReady) owLoop();
|
||||
#ifdef _dmxin
|
||||
DMXCheck();
|
||||
#endif
|
||||
//modbusloop();
|
||||
}
|
||||
|
||||
@@ -1004,10 +1202,41 @@ if (items)
|
||||
} //proc
|
||||
|
||||
|
||||
|
||||
#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
|
||||
|
||||
33
options.h
Normal file
33
options.h
Normal file
@@ -0,0 +1,33 @@
|
||||
// Configuration of drivers enabled
|
||||
#define _dmxin
|
||||
#define _dmxout
|
||||
#define _owire
|
||||
#define _modbus
|
||||
#define _artnet
|
||||
|
||||
|
||||
#if defined(__AVR__)
|
||||
//All options available
|
||||
#define modbusSerial Serial2
|
||||
#endif
|
||||
|
||||
#if defined(__SAM3X8E__)
|
||||
/// DMX not deployed yet
|
||||
#undef _dmxin
|
||||
//#undef _dmxout
|
||||
#define modbusSerial Serial2
|
||||
//#include <DmxDue.h>
|
||||
#define dmxout DmxDue4
|
||||
#define dmxin DmxDue1
|
||||
#endif
|
||||
|
||||
#if defined(ESP_PLATFORM)
|
||||
#undef _dmxin
|
||||
#undef _dmxout
|
||||
//#undef _modbus
|
||||
#define modbusSerial Serial
|
||||
#endif
|
||||
|
||||
#ifndef _dmxout
|
||||
#undef _artnet
|
||||
#endif
|
||||
Reference in New Issue
Block a user