/**************************************************************************
* Souliss - studentenhome Kromme Elleboogstraat - Mechelen
* versie 5/1/2023
* rev1 :8/1/2023
* rev2 :20/1/2023 L22B aangepast
* rev3 ;29/1/2023 trapautomaat aangepast
* rev4 :20/02/2023 test ethernet verbinding
* rev5 :25/4/2023 aanpassingen ingangen
* rev6 :28/772023 herschikken uitgangen voor 48V lichtpunten
* Hardware :
* - processor Arduino Mega pro mini
* - Ethernet module : ENC28J60 mini
* - 2x RS485 module ( Souliss-bus, DMX)
*
*
*modification in vNetCfg.h :
* - line 38 :# define VNET_MAX_PAYLOAD 66
*
* -modification in MaCacoCfg.h :
* lines 261 & 262 : # define MaCaco_NODES 10
* # define MaCaco_SLOT 41
*
*modification in vNetDriver_usart.h : 46 (orig 36)
*
*DMX
*Pins (MEGA): serial1
* 19 - RX1 - RO MAX485
* 18 - TX1 - DI MAX485
*
* Souliss bus
* Pins (MEGA): serial2
* 17 - RX1 - RO MAX485
* 16 - TX1 - DI MAX485
* TXENABLE : enabled on pin 3
*
* pins en28j60 ethernet shield
* CS 10
* SI (ST) 51
* S0 50
* SCK 52
* 5V
* massa
*
***************************************************************************/
// Configure the framework
#include <SoulissFramework.h>
#include "bconf/StandardArduino.h" // Use a standard Arduino
#include "conf/ethENC28J60.h" //ethernet through enc28j60
#include "conf/Gateway.h" // The main node is the Gateway
#include "conf/usart_fast.h" // RS485
#include "conf/usart.h"
// libraries voor de temperuursmetingen
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
// dmx LIBRARY
#define DMX_USE_PORT1
#include "DMXSerial_megaavr.h"
#include <DMXSerial.h>
// Souliss bus
// Use the following if you are using an RS485 transceiver with
// transmission enable pin, otherwise delete this section.
//
#define USARTDRIVER_INSKETCH
#define USART_TXENABLE 1
#define USART_TXENPIN 3
#define USARTDRIVER Serial2
#define USART_COLLISION 0
#define MaCaco_NODESIZE_INSKETCH
#define MaCaco_NODES 10 // Number of remote nodes
#define MaCaco_SLOT 41 // number of slot/node
// define max number of slots
# define VNET_MAX_PAYLOAD_INSKETCH
# define VNET_MAX_PAYLOAD 66
#define VNET_USART_H_INSKETCH
#define USART_MAXPAYLOAD 66
// Include framework code and libraries
#include <SPI.h>
#include "Souliss.h"
// settings dimmers
# define Souliss_T1n_BrightValue 0x17 // Default increase and decrease (origineel 0x10)
# define Souliss_T1n_BrightStep 0x06 // oorspronkelijk 0x0A
# define BrightDefault 0xFF // oorspronkelijk 0x50, andere nodes 0xFF
// Router instellingen
uint8_t ip_address[4] = {192, 168, 0, 77};
uint8_t subnet_mask[4] = {255, 255, 255, 0};
uint8_t ip_gateway[4] = {192, 168, 0, 1};
#define myvNet_address ip_address[3] // The last byte of the IP address (77) is also the vNet address
// Define the RS485 network configuration
#define myvNet_subnet 0xFF00
#define Gateway_RS485 0xCE01
#define PEERNODE1 0xCE02
//#define PEERNODE2 0xCE03
// Definiëren databank (Souliss slots)
// ( 1 slot voor ON/OFF, 2 slots voor dimmer en temperatuur, )
// beschrijving - slotnr -DMX-module -kanaalnr. - beschrijving () = uitvoering woning)
#define L1 0 // hoofdingang
#define L5 1 // gang gelijkvloers
#define L65 2 // deur uitgang
#define L14 3 // gang trap
#define L12 4 // WC gelijkvloers
#define L8 5 // eethoek
#define L7 6 // keuken gootsteen logic control
#define L11 7 // zithoek
#define L10 9 // tuin
#define L2A 10 // K1 vooraan
#define L2B 11 // K1 achteraan
#define L9 12 // patio
#define L3 13 // K1 WC
#define L4A 14 // K1 douche
#define L4B 15 // K1 lavabo
#define L19 16 // K2
#define L20 17 // K2 WC
#define L21A 18 // K2 douche
#define L21B 19 // K2 lavabo
#define L32 20 // K5
#define L33 21 // K5 WC
#define L34A 22 // K5 douche
#define L34B 23 // K5 lavabo
#define L22A 24 // K3 deur
#define L22B 25 // K3 raam
#define L23 26 // K3 WC
#define L24A 27 // K3 douche
#define L24B 28 // K3 lavabo
// define delay time light on PIR-sensor
//#define ONTIME 15 // Light is on for ONTIME number of cycles
// instellingen voor timers
#define LIGHT_ON_CYCLE 50 // instelling timer traphal
byte PIR1; //status pir
unsigned long gtime; //activatietijd
void setup()
{
DMXSerial.init(DMXController);
// Serial.begin(9600); // enkel voor testen programma
Initialize();
// Set network parameters
Souliss_SetIPAddress(ip_address, subnet_mask, ip_gateway);
SetAsGateway(myvNet_address); // Set this node as gateway for SoulissApp
SetAddress(Gateway_RS485, myvNet_subnet, 0); // Set the address on the RS485 bus
// This node as gateway will get data from the Peer
SetAsPeerNode(PEERNODE1, 1);
// SetAsPeerNode(PEERNODE2, 2);
//
// Define the logic
//Set_AutoLight(L1); // pir hoofdingang
Set_AutoLight(L14); //gang trap ( L14+L16+L29+L31+L42)
Set_SimpleLight(L5); //gang gelijkvlers
Set_SimpleLight(L65); //deur uitgang
Set_SimpleLight(L12); //WC gelijkvloers
Set_SimpleLight(L8); //eethoek
Set_SimpleLight(L9); //patio
Set_SimpleLight(L7); //keuken gootsteen
Set_SimpleLight(L10); //tuin
Set_SimpleLight(L2A); //K1 vooraan
Set_SimpleLight(L3); //K1 WC
Set_SimpleLight(L4A); //K1 douche
Set_SimpleLight(L19); //K2
Set_SimpleLight(L20); //K2 WC
Set_SimpleLight(L21A); //K2 douche
Set_SimpleLight(L32); //K5
Set_SimpleLight(L33); //K5 WC
Set_SimpleLight(L34A); //K5 douche
Set_SimpleLight(L22A); //K3
Set_SimpleLight(L23); //K3 WC
Set_SimpleLight(L24A); //K3 douche
Set_DimmableLight(L11); //zithoek
// inputs
pinMode(23, INPUT); // S1
pinMode(25, INPUT); // S5,S6,S7
pinMode(38, INPUT); // S
pinMode(36, INPUT); //
pinMode(27, INPUT); // S65
pinMode(29, INPUT); // S14, S16, S17, S18, S29, S30, S31, S42
pinMode(31, INPUT); // S8
pinMode(30, INPUT); // S13
pinMode(28, INPUT); // S11
pinMode(26, INPUT); // S10
pinMode(24, INPUT); // S12
pinMode(22, INPUT); // S2
pinMode(33, INPUT); // S3
pinMode(35, INPUT); // S4
pinMode(37, INPUT); // S9
pinMode(39, INPUT); // S19
pinMode(41, INPUT); // S20
pinMode(43, INPUT); // S21
pinMode(46, INPUT); // S22
pinMode(44, INPUT); // S23
pinMode(42, INPUT); // S24
pinMode(40, INPUT); // S32
pinMode(38, INPUT); // S33
pinMode(36, INPUT); // S34
pinMode(34, INPUT); // reserve
//outputs
// relais uitgangen (230Vac)
pinMode(A0, OUTPUT); // L14, L16, L29, L31, L42
pinMode(A2, OUTPUT); // L20
pinMode(A4, OUTPUT); // L3
pinMode(A6, OUTPUT); // L10
pinMode(A8, OUTPUT); // L7
pinMode(A10, OUTPUT); // L9
pinMode(A12, OUTPUT); // L8
pinMode(A14, OUTPUT); // L12
pinMode(A5, OUTPUT); // L4B
pinMode(A7, OUTPUT); // L5
pinMode(A9, OUTPUT); // L1
pinMode(A11, OUTPUT); // L34B
pinMode(A13, OUTPUT); // L33
pinMode(A15, OUTPUT); // L21B
pinMode(A3, OUTPUT); // L23
pinMode(A1, OUTPUT); // L224B
// automaat trap en hoofdingang in automatisch forceren
//mInput(L1) = Souliss_T1n_AutoCmd;
mInput(L14) = Souliss_T1n_AutoCmd;
// alle lichten uit bij reset arduino
//DigOut(A0, Souliss_T1n_OffCoil, L14);
DigOut(A2, Souliss_T1n_OffCoil, L20);
DigOut(A4, Souliss_T1n_OffCoil, L3);
DigOut(A6, Souliss_T1n_OffCoil, L10);
DigOut(A8, Souliss_T1n_OffCoil, L7);
DigOut(A10, Souliss_T1n_OffCoil, L9);
DigOut(A12, Souliss_T1n_OffCoil, L8);
DigOut(A14, Souliss_T1n_OffCoil, L12);
DigOut(A5, Souliss_T1n_OffCoil, L4A);
DigOut(A7, Souliss_T1n_OffCoil, L5);
DigOut(A9, Souliss_T1n_OffCoil, L1);
DigOut(A11, Souliss_T1n_OffCoil, L34A);
DigOut(A13, Souliss_T1n_OffCoil, L33);
DigOut(A15, Souliss_T1n_OffCoil, L21A);
DigOut(A3, Souliss_T1n_OffCoil, L23);
DigOut(A1, Souliss_T1n_OffCoil, L24B);
// lichten via DMX resetten nog toe te voegen
for (i= 1; i<16; i++){
DMXSerial.write(i, 0);
}
}
void loop()
{
EXECUTEFAST() {
UPDATEFAST();
// gemeenschappelijke delen & K1
FAST_110ms() { // inlezen drukknoppen iedere 110 milliseconds)
DigIn(25, Souliss_T1n_ToggleCmd, L5);
DigIn(27, Souliss_T1n_ToggleCmd,L65);
DigIn(31, Souliss_T1n_ToggleCmd,L8);
DigIn(30, Souliss_T1n_ToggleCmd,L7);
DigIn(26, Souliss_T1n_ToggleCmd,L10);
DigIn(24, Souliss_T1n_ToggleCmd,L12);
DigIn(22, Souliss_T1n_ToggleCmd,L2A);
DigIn(33, Souliss_T1n_ToggleCmd,L3);
DigIn(35, Souliss_T1n_ToggleCmd,L4A);
DigIn(37, Souliss_T1n_ToggleCmd,L9);
// Execute the logic
Logic_SimpleLight(L5);
Logic_SimpleLight(L12);
Logic_SimpleLight(L8);
Logic_SimpleLight(L9);
Logic_SimpleLight(L7);
Logic_SimpleLight(L10);
Logic_SimpleLight(L2A);
Logic_SimpleLight(L3);
Logic_SimpleLight(L4A);
Logic_SimpleLight(L65);
// sturen relais outputs
DigOut(A7, Souliss_T1n_Coil, L65);
DigOut(A14, Souliss_T1n_Coil, L12);
DigOut(A12, Souliss_T1n_Coil, L8);
DigOut(A10, Souliss_T1n_Coil, L9);
DigOut(A8, Souliss_T1n_Coil, L7);
DigOut(A6, Souliss_T1n_Coil, L10);
DigOut(A4, Souliss_T1n_Coil, L3);
DigOut(A5, Souliss_T1n_Coil, L4A);
// sturen DMX-kanalen
if (mOutput(L5)== Souliss_T1n_OffCoil) DMXSerial.write(1, 0); //DMX1-A-R
if (mOutput(L5)== Souliss_T1n_OnCoil) DMXSerial.write(1, 255);
if (mOutput(L2A)== Souliss_T1n_OffCoil) DMXSerial.write(7, 0); //DMX2-A-R
if (mOutput(L2A)== Souliss_T1n_OnCoil) DMXSerial.write(7, 255);
if (mOutput(L2A)== Souliss_T1n_OffCoil) DMXSerial.write(8, 0); //DMX2-A-G
if (mOutput(L2A)== Souliss_T1n_OnCoil) DMXSerial.write(8, 255);
if (mOutput(L4A)== Souliss_T1n_OffCoil) DMXSerial.write(3, 0); //DMX1-A-B
if (mOutput(L4A)== Souliss_T1n_OnCoil) DMXSerial.write(3, 255);
}
// kamers 2,5,6
SHIFT_110ms(1){
DigIn(39, Souliss_T1n_ToggleCmd, L19);
DigIn(41, Souliss_T1n_ToggleCmd, L20);
DigIn(43, Souliss_T1n_ToggleCmd, L21A);
DigIn(46, Souliss_T1n_ToggleCmd, L22A);
DigIn(44, Souliss_T1n_ToggleCmd, L23);
DigIn(42, Souliss_T1n_ToggleCmd, L24A);
DigIn(40, Souliss_T1n_ToggleCmd, L32);
DigIn(38, Souliss_T1n_ToggleCmd, L33);
DigIn(36, Souliss_T1n_ToggleCmd, L34A);
Logic_SimpleLight(L19);
Logic_SimpleLight(L20);
Logic_SimpleLight(L21A);
Logic_SimpleLight(L32);
Logic_SimpleLight(L33);
Logic_SimpleLight(L34A);
Logic_SimpleLight(L22A);
Logic_SimpleLight(L23);
Logic_SimpleLight(L24A);
// sturen relais outputs
DigOut(A2, Souliss_T1n_Coil, L20);
DigOut(A15, Souliss_T1n_Coil, L21A);// L21A & L21B samen
DigOut(A13, Souliss_T1n_Coil, L33);
DigOut(A11, Souliss_T1n_Coil, L34A);// L34A & L34B samen
DigOut(A5, Souliss_T1n_Coil, L4A); // L4A & L4B samen
DigOut(A3, Souliss_T1n_Coil, L23);
DigOut(A1, Souliss_T1n_Coil, L24A);
DigOut(A4, Souliss_T1n_Coil, L3);
// sturen DMX-kanalen
if (mOutput(L19)== Souliss_T1n_OffCoil) DMXSerial.write(9, 0); //DMX2-A-B
if (mOutput(L19)== Souliss_T1n_OnCoil) DMXSerial.write(9, 255);
if (mOutput(L21A)== Souliss_T1n_OffCoil) DMXSerial.write(4, 0); //DMX1-B-R
if (mOutput(L21A)== Souliss_T1n_OnCoil) DMXSerial.write(4, 255);
if (mOutput(L32)== Souliss_T1n_OffCoil) DMXSerial.write(12, 0); //DMX2-B-B
if (mOutput(L32)== Souliss_T1n_OnCoil) DMXSerial.write(12, 255);
if (mOutput(L34A)== Souliss_T1n_OffCoil) DMXSerial.write(6, 0); //DMX1-B-B
if (mOutput(L34A)== Souliss_T1n_OnCoil) DMXSerial.write(6, 255);
if (mOutput(L22A)== Souliss_T1n_OffCoil) DMXSerial.write(10, 0); //DMX2-B-R
if (mOutput(L22A)== Souliss_T1n_OnCoil) DMXSerial.write(10, 255);
if (mOutput(L22A)== Souliss_T1n_OffCoil) DMXSerial.write(11, 0); //DMX2-B-G
if (mOutput(L22A)== Souliss_T1n_OnCoil) DMXSerial.write(11, 255);
if (mOutput(L24A)== Souliss_T1n_OffCoil) DMXSerial.write(5, 0); //DMX1-B-G
if (mOutput(L24A)== Souliss_T1n_OnCoil) DMXSerial.write(5, 255);
}
//dimmer zithoek
SHIFT_110ms(2) {
// korte puls : de lamp toggled tussen UIT en 100% AAN
// knop inhouden : lichtsterkte loopt omhoog als de lamp UIT was en loopt omlaag als de lamp AAN was.
// Na loslaten van de knop en de lamp stand in DIM-stand, lamp gaat UIT
if(mOutput(L11)== 0){DigKeepHold(28,Souliss_T1n_ToggleCmd, Souliss_T1n_BrightUp, L11);}
if (mOutput(L11)==1){DigKeepHold(28,Souliss_T1n_ToggleCmd,Souliss_T1n_BrightDown,L11);}
Logic_T19(L11);
DMXSerial.write(2, mOutput(L11+1));
}
//automaten
// trap & hoogdingang
FAST_210ms() {
DigIn(29,Souliss_T1n_AutoCmd + LIGHT_ON_CYCLE,L14);
Logic_AutoLight(L14);
DigOut(A0, Souliss_T1n_Coil,L14);
}
FAST_1110ms() {
Timer_AutoLight(L14);
}
FAST_GatewayComms();
}
EXECUTESLOW() {
UPDATESLOW();
SLOW_10s()
{
}
}
// sturing pir hoofdingang
PIR1 = digitalRead (23); // status van de pir inlezen
if ( PIR1 == 1 )
{
digitalWrite (A9, HIGH); // L1 aan
gtime= millis();
Serial.print("gtime :");
Serial.println(gtime);
}
if ( PIR1 == 0 and (millis() - gtime >120000)) // L1 2 minuten aan na laatste beweging
{
digitalWrite (A9, LOW); // L1 uit
}
// Process data communication
}