Code written by Paul Rabbat, Angel Daruna, Jarel Hawkins, and Cordel Williams
Dependencies: 4DGL-uLCD-SE EthernetInterface HTTPClient NTPClient PinDetect SDFileSystem mbed-rpc mbed-rtos mbed wave_player
Fork of ECE4180_FinalProject by
Revision 1:d7f65be2640d, committed 2014-11-15
- Comitter:
- prabbat3
- Date:
- Sat Nov 15 20:45:33 2014 +0000
- Parent:
- 0:0a99e3fc2a46
- Child:
- 2:0ec5c713bd50
- Commit message:
- pre-weather;
Changed in this revision
Formatter.cpp | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/Formatter.cpp Sat Nov 15 19:36:44 2014 +0000 +++ b/Formatter.cpp Sat Nov 15 20:45:33 2014 +0000 @@ -82,7 +82,8 @@ const char* INTERACTIVE_HTML_CODE_2 = "</body> \ </html>"; -static char chunk[1024]; +//static char chunk[1024]; +static char chunk[4096]; Formatter::Formatter(int nb): currentChunk(0), @@ -121,8 +122,10 @@ if(reply != NULL && strlen(reply) != 0) { + /* strcat(chunk, "RPC reply : "); strcat(chunk, reply); + */ } if(!RPCObjectManager::instance().is_empty()) @@ -158,14 +161,16 @@ { if(reply != NULL && strlen(reply) != 0) { + /* strcat(chunk, "RPC reply : "); strcat(chunk, reply); + */ } if(!RPCObjectManager::instance().is_empty()) { alarmCreated = 1; - strcat(chunk, "<p>Objects created :</p>"); + /*strcat(chunk, "<p>Objects created :</p>"); strcat(chunk, "<ul>"); for(std::list<char*>::iterator itor = RPCObjectManager::instance().begin(); @@ -181,7 +186,7 @@ strcat(chunk, "/delete\">delete</a>)"); strcat(chunk, "</li>"); } - strcat(chunk, "</ul>"); + strcat(chunk, "</ul>");*/ } strcat(chunk, " "); @@ -245,6 +250,183 @@ strcat(chunk, "<option "); if(_alarm.minutes == 1){ strcat(chunk, "selected=\"selected\""); } strcat(chunk, "value=\"1\">01</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 2){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"2\">02</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 3){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"3\">03</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 4){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"4\">04</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 5){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"5\">05</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 6){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"6\">06</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 7){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"7\">07</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 8){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"8\">08</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 9){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"9\">09</option>"); + + strcat(chunk, "<option "); + if(_alarm.minutes == 10){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"10\">10</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 11){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"11\">11</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 12){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"12\">12</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 13){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"13\">13</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 14){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"14\">14</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 15){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"15\">15</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 16){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"16\">16</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 17){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"17\">17</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 18){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"18\">18</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 19){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"19\">19</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 20){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"20\">20</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 21){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"21\">21</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 22){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"22\">22</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 23){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"23\">23</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 24){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"24\">24</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 25){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"25\">25</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 26){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"26\">26</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 27){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"27\">27</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 28){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"28\">28</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 29){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"29\">29</option>"); + + strcat(chunk, "<option "); + if(_alarm.minutes == 30){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"30\">30</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 31){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"31\">31</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 32){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"32\">32</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 33){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"33\">33</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 34){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"34\">34</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 35){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"35\">35</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 36){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"36\">36</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 37){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"37\">37</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 38){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"38\">38</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 39){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"39\">39</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 40){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"40\">40</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 41){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"41\">41</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 42){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"42\">42</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 43){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"43\">43</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 44){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"44\">44</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 45){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"45\">45</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 46){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"46\">46</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 47){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"47\">47</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 48){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"48\">48</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 49){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"49\">49</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 50){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"50\">50</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 51){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"51\">51</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 52){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"52\">52</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 53){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"53\">53</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 54){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"54\">54</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 55){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"55\">55</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 56){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"56\">56</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 57){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"57\">57</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 58){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"58\">58</option>"); + strcat(chunk, "<option "); + if(_alarm.minutes == 59){ strcat(chunk, "selected=\"selected\""); } + strcat(chunk, "value=\"59\">59</option>"); + strcat(chunk, "</select>"); /******* AM PM *******/
--- a/main.cpp Sat Nov 15 19:36:44 2014 +0000 +++ b/main.cpp Sat Nov 15 20:45:33 2014 +0000 @@ -22,23 +22,42 @@ alarmModel _alarm; string dayOfWeek, month, dayNum, ampm; int hour, minute, sec; -DigitalOut led1(LED1); -DigitalOut led2(LED2); -DigitalOut led3(LED3); -DigitalOut led4(LED4); +PwmOut led(LED1); // led 1 indicates dim value +DigitalOut led2(LED2); // led 2 indicates delay time for interrupts +DigitalOut led3(LED3); // Indicates the alarm has been set +DigitalOut led4(LED4); // Indiciates the alarm is going off +int alarmSignaled = 0; + +// pin for ZeroCross tail input +// An external 1K pullup required +InterruptIn zerocross(p22); + +// pin for PowerSSRtail output +DigitalOut SSR(p21); + +//use timer interrupts to control dimming +Timeout SSRtriggerOn; + +// dimmer value 0.0=off and 1.0=full on +volatile float dim; + +// AC power line frequency +const float powerlinefrequency=60.000; + // Function prototypes HTTPServer create_simple_server(); HTTPServer create_interactive_server(); -void parse(char[], int*, char*); void thread_server(void const *args); void thread_display(void const *args); void thread_alarm(void const *args); +void triggerOn(); +void dimmer(); +void turn_on(); int main() { - + dim = -1.0; printf("Getting IP Address.. "); - uLCD.baudrate(2000000); uLCD.cls(); uLCD.background_color(BLACK); @@ -76,6 +95,15 @@ //TIME_OUT= timeout value for request ntpClient.setTime(domainName,123,0x00005000); printf("Time set.\n"); + + + //set up interrupt routine to detect AC line zero crossings + zerocross.mode(PullNone); + wait(.2); + zerocross.rise(&dimmer); + // main program only sets dimmer level (dim) + // interrupt routines dim the light + Thread t1(thread_server); //start thread_server Thread t2(thread_display); @@ -87,11 +115,11 @@ void thread_alarm(void const *args) { while(1){ - if(_alarm.alarmSet){ - led1 = 1; + if(_alarm.alarmSet && !alarmSignaled){ + led3 = 1; if(_alarm.hours == hour && _alarm.minutes == minute && _alarm.amPm == ampm){ - led2 = 1; - led3 = 1; + alarmSignaled = 1; + turn_on(); led4 = 1; } } @@ -200,17 +228,31 @@ srv.add_request_handler("GET", new ComplexRequestHandler()); return srv; } - -//SET FOR CSV FORMAT: NEEDS TO BE EDITED IF DIFFERENT FORMAT -void parse(char buffer[], int *j, char *string) { -//extracts next location string data item from buffer - int i=0; - for (i=0; i<=strlen(buffer); i++) { //TOTAL SIZE OF RETURNED DATA - if ((buffer[*j+i] == ',')||(buffer[*j+i] == '\0' )) { //IF comma or end of string - //comma is the string field delimiter - string[i]=0; //SETS END OF SRTRING TO 0 - *j=*j+i+1; //UPDATES to 1 after comma seperated value - break; - } else string[i]=buffer[*j+i]; //Keep adding to the string + +// this interrupt routine is activated after a time delay set by dim value +void triggerOn() +{ + SSR = 1; + led2=0; +} + +// this interrupt routine is activated by every AC line zero crossing +// it is needed to synchronize the SSR turnon time delay to the AC line +void dimmer() +{ + // turn off SSR at zero crossing + SSR = 0; + // compute time delay using dim value and set timer interrupt + // triggers SSR after a small post zero crossing time delay + SSRtriggerOn.attach(&triggerOn,(1.001-dim)/(2*powerlinefrequency)); + led2=1; +} + +void turn_on(){ + //increase brightness + for(dim = 0.0; dim <= 1.0; dim += 0.025) { + led = (dim < 0 ? 0 : dim); + wait(0.10); } + dim = 1.0; } \ No newline at end of file