-
Notifications
You must be signed in to change notification settings - Fork 12
/
Main.cpp
99 lines (85 loc) · 1.9 KB
/
Main.cpp
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
/*
* Copyright (c) 2012 Yeelink.net by dapingliu <[email protected]>
*
* This is the main project file for YeeBox. This version implements
* YeeBox Ethernet-Zigbee solution, so called YeeboxEZ.
* - Atmel Mega328P
* - WIZnet W5100
* - TI CC2530
*/
#include "Main.h"
//CommonData instace
CommonData cmdata;
//BoxLogic instance
BoxLogic logic;
//Create a SSDP instance
SSDP ssdp;
//Create a mobile interface instance
Mobile mobile;
//Create a COM instance
BoxCOM com;
//Create a LED status instance
StatusLED leds;
//Create Button Status check instance
ButtonPushCheck btn;
//IPAddress ip(192,168,1,2);
void (*app_start)(void) = 0x0000;
void wdtSetup() {
cli();
MCUSR = 0;
WDTCSR |= B00011000;
WDTCSR = B01100001;
sei();
}
ISR(WDT_vect)
{
MCUSR = 0;
WDTCSR |= _BV(WDCE) | _BV(WDE);
WDTCSR = 0;
app_start();
}
//The setup function is called once at startup of the sketch
void setup() {
leds.begin(&cmdata);
cmdata._mode = BOXMODE_INIT;
cmdata.leds = &leds;
leds.setLocalOff();
leds.setLocalMiddleFlash(60000); //after 60s(another 60s is triggered by dhcp lib),
//local led will be power off, notify user that
//a network issue should be checked
leds.setGlobalOff();
// initialize data
cmdata.setup();
cmdata.logic = &logic;
cmdata.ssdp = &ssdp;
cmdata.mobile = &mobile;
cmdata.com = &com;
cmdata.btn = &btn;
// start the Ethernet and UDP:
//Ethernet.begin(cmdata.mac, ip);
if (Ethernet.begin(cmdata.mac) != 0) {
logic.begin(&cmdata);
ssdp.begin(&cmdata);
mobile.begin(&cmdata);
com.begin(&cmdata);
btn.begin(&cmdata);
cmdata.leds->setLocalOn();
cmdata.leds->setLocalSlowFlash(15000);
}
else {
cmdata.leds->setLocalOff();
}
//wdt_enable(WDTO_8S);
wdtSetup();
}
// The loop function is called in an endless loop
void loop() {
btn.loop();
ssdp.loop();
mobile.loop();
com.loop();
logic.loop();
leds.loop();
wdt_reset();
// delay(6000);
}