My favorites | Sign in
Project Home Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions

Issue 5 attachment: MEGA_ALARMA.ino (9.6 KB)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
/**************************************************************************
Souliss - Fiat Lux

Fiat Lux is a latin phrase that means Let There Be Light, this example
show how handle light via hardwired pushbutton geographically distributed
over the home, the Android (or any other direct) user interface can also
be used.

It require an Ethernet board based on Wiznet W5100 or Microchip ENC28J60.

Applicable for :
- Lights controller via relay,
- Plugs and other ON/OFF devices.

The first device has
- A coil (relay or other) on Pin 8 and Pin 9
- A couple of inputs on Pin 2 and 3, pulldown required

The Remote Device has
- A couple of inputs on Pin 2 and 3, pulldown required

CONFIGURATION IS MANDATORY BEFORE COMPILING
Before compiling this code, is mandatory the configuration of the framework
this ensure the use of proper drivers based functionalities and requested
communication interface.

Configuration files are located on /conf folder, is suggested to use this
code on one of the boards listed below, the code can also compile on other
boards but may require modification on I/O definitions.

Run this code on one of the following boards:

Board Conf Code Board Model
0x03 Arduino Ethernet (W5100)
0x04 Arduino with Ethernet Shield (W5100)
0x05 Arduino with ENC28J60 Ethernet Shield

******************** Configuration Parameters *********************

Configuration file Parameter
QuickCfg.h #define QC_ENABLE 0x01
QuickCfg.h #define QC_BOARDTYPE 0x03, 0x04, 0x05

Is required an additional IP configuration using the following parameters
QuickCfg.h const uint8_t DEFAULT_BASEIPADDRESS[] = {...}
QuickCfg.h const uint8_t DEFAULT_SUBMASK[] = {...}
QuickCfg.h const uint8_t DEFAULT_GATEWAY[] = {...}

***************************************************************************/
#include "Souliss.h"
#include "Typicals.h"
#include <SPI.h>

#define network_address_1 0x0011
#define network_address_2 0x0012
#define network_address_3 0x0013
#define network_address_4 0x0014
#define network_my_subnet 0xFF00
#define network_my_supern 0x0000

#define ANTITHEFT 0
#define ANTITHEFT1 1
#define ANTITHEFT2 2
#define ANTITHEFT3 3



//SLOT PENTRU PIR ALARM
#define BURGLAR 4
#define BURGLAR1 5
#define BURGLAR2 6
#define BURGLAR3 7



//SLOT PENTRU CONTACTE LA GEAMURI
#define SMOKE 8 //SLOT PENTRU SENSOR DE FUM
#define SMOKE1 9
#define SMOKE2 10
#define SMOKE3 11 //SLOT PENTRU SENSOR DE FLACARA





// define the shared memory map
U8 memory_map[MaCaco_MEMMAP];

// flag
U8 data_changed = 0;

#define time_base_fast 10 // Time cycle in milliseconds
#define time_base_slow 10000 // Time cycle in milliseconds
#define num_phases 255 // Number of phases

U8 phase_speedy=0, phase_fast=0, phase_slow=0;
unsigned long tmr_fast=0, tmr_slow=0;

void setup()
{
// Setup the network configuration
//
// The vNet address is 11(hex) that is 17(dec), so the IP address is
// the DEFAULT_BASEIPADDRESS[] defined in ethUsrCfg.h plus 17 on last
// octect. If DEFAULT_BASEIPADDRESS[] = {192, 168, 1, 0} the IP address
// for the board will be 192.168.1.17
Souliss_SetAddress(network_address_1, network_my_subnet, network_my_supern);

// Load the address also in the memory_map
Souliss_SetLocalAddress(memory_map, network_address_1);



// Set the typical logic to handle the lights

Souliss_SetT41(memory_map, ANTITHEFT);
Souliss_SetT42(memory_map, ANTITHEFT1);
Souliss_SetT42(memory_map, ANTITHEFT2);
Souliss_SetT42(memory_map, ANTITHEFT3);

Souliss_SetT41(memory_map, BURGLAR);
Souliss_SetT42(memory_map, BURGLAR1);
Souliss_SetT42(memory_map, BURGLAR2);
Souliss_SetT42(memory_map, BURGLAR3);

Souliss_SetT41(memory_map, SMOKE);
Souliss_SetT42(memory_map, SMOKE1);
Souliss_SetT42(memory_map, SMOKE2);
Souliss_SetT42(memory_map, SMOKE3);




// Define inputs, outputs pins


pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT);
pinMode(A3, INPUT);
pinMode(A4, INPUT);
pinMode(A5, INPUT);
pinMode(2, INPUT); // Hardware pulldown required
pinMode(3, INPUT);
pinMode(20, INPUT);
pinMode(21, INPUT);
pinMode(22, INPUT);
pinMode(23, INPUT);

pinMode(40, INPUT);
pinMode(41, INPUT);
pinMode(42, INPUT);
pinMode(43, INPUT);
// Hardware pulldown required
pinMode(3, INPUT); // Hardware pulldown required
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT); // //
pinMode(7, OUTPUT); // Power to relay coil for light 1
pinMode(8, OUTPUT);
pinMode(9, OUTPUT); // Power to relay coil for light 2
}
void loop()
{


if(abs(millis()-tmr_fast) > time_base_fast)
{
tmr_fast = millis();
phase_fast = (phase_fast + 1) % num_phases;


if (!(phase_fast % 3))
{
// Input from anti-theft sensor
Souliss_LowDigIn(20, Souliss_T4n_Alarm, memory_map, ANTITHEFT);
Souliss_LowDigIn(21, Souliss_T4n_Alarm, memory_map, ANTITHEFT1);

Souliss_LowDigIn(22, Souliss_T4n_Alarm, memory_map, ANTITHEFT2);
Souliss_LowDigIn(23, Souliss_T4n_Alarm, memory_map, ANTITHEFT3);

Souliss_LowDigIn(40, Souliss_T4n_Alarm, memory_map, BURGLAR);
Souliss_LowDigIn(41, Souliss_T4n_Alarm, memory_map, BURGLAR1);
Souliss_LowDigIn(42, Souliss_T4n_Alarm, memory_map, BURGLAR2);
Souliss_LowDigIn(43, Souliss_T4n_Alarm, memory_map, BURGLAR3);



Souliss_LowDigIn(A2, Souliss_T4n_Alarm, memory_map, SMOKE);
Souliss_LowDigIn(A3, Souliss_T4n_Alarm, memory_map, SMOKE1);
Souliss_LowDigIn(A4, Souliss_T4n_Alarm, memory_map, SMOKE2);



// Use Pin3 as ON/OFF command


// Use Pin4 as ON/OFF command


// Execute the anti-theft logic
Souliss_Logic_T41(memory_map, ANTITHEFT, &data_changed);
Souliss_Logic_T41(memory_map, SMOKE, &data_changed);
Souliss_Logic_T41(memory_map, BURGLAR, &data_changed);

Souliss_Logic_T42(memory_map, ANTITHEFT1, &data_changed, ANTITHEFT);
Souliss_Logic_T42(memory_map, ANTITHEFT2, &data_changed, ANTITHEFT);
Souliss_Logic_T42(memory_map, ANTITHEFT3, &data_changed, ANTITHEFT);

Souliss_Logic_T42(memory_map, BURGLAR1, &data_changed, BURGLAR);
Souliss_Logic_T42(memory_map, BURGLAR2, &data_changed, BURGLAR);
Souliss_Logic_T42(memory_map, BURGLAR3, &data_changed, BURGLAR);

Souliss_Logic_T42(memory_map, SMOKE1, &data_changed, SMOKE);
Souliss_Logic_T42(memory_map, SMOKE2, &data_changed, SMOKE);
Souliss_Logic_T42(memory_map, SMOKE3, &data_changed, SMOKE);



// Set the Pin7 if the anti-theft is activated
Souliss_nDigOut(4, Souliss_T4n_Antitheft, memory_map, ANTITHEFT);
Souliss_nDigOut(5, Souliss_T4n_Antitheft, memory_map, SMOKE);
Souliss_nDigOut(6, Souliss_T4n_Antitheft, memory_map, BURGLAR);
// Set the Pin8 if the alarm is rised
Souliss_LowDigOut(7, Souliss_T4n_InAlarm, memory_map, ANTITHEFT);
// Use Pin6 as output on the electrical load
Souliss_LowDigOut(8, Souliss_T4n_InAlarm, memory_map, SMOKE);
Souliss_LowDigOut(9, Souliss_T4n_InAlarm, memory_map, BURGLAR);

// Use Pin9 as output on the electrical load






}

// Execute the code every 5 time_base_fast
if (!(phase_fast % 5))
{
// Retreive data from the communication channel
Souliss_CommunicationData(memory_map, &data_changed);
}

// Execute the code every 31 time_base_fast
if (!(phase_fast % 31))
{
// Get logic typicals once and at every refresh
Souliss_GetTypicals(memory_map, 1);
}

// Execute the code every 51 time_base_fast
if (!(phase_fast % 51))
{
// Open a communication channel with remote nodes
Souliss_CommunicationChannels(memory_map, 1);
}

if (!(phase_fast % 251))
{
// Build a watchdog chain to monitor the nodes healt
Souliss_LinkOI(memory_map, ANTITHEFT, ANTITHEFT1);
Souliss_LinkOI(memory_map, ANTITHEFT, ANTITHEFT2);
Souliss_LinkOI(memory_map, ANTITHEFT, ANTITHEFT3);

Souliss_LinkOI(memory_map, BURGLAR, BURGLAR1);
Souliss_LinkOI(memory_map, BURGLAR, BURGLAR2);
Souliss_LinkOI(memory_map, BURGLAR, BURGLAR3);


Souliss_LinkOI(memory_map, SMOKE, SMOKE1);
Souliss_LinkOI(memory_map, SMOKE, SMOKE2);
Souliss_LinkOI(memory_map, SMOKE, SMOKE3);
// Use the output of the watchdog as input for anti-theft
}
}
else if(abs(millis()-tmr_slow) > time_base_slow)
{
tmr_slow = millis();
phase_slow = (phase_slow + 1) % num_phases;

// Execute the code every 7 time_base_slow
if (!(phase_slow % 7))
{
// Refresh typical definitions
Souliss_RefreshTypicals();
}
}



}


Powered by Google Project Hosting