LeeT WiFiLamp code and test
Dependencies: ESP8266_WebServer mbed
Fork of WiFiLamp by
Diff: main.cpp
- Revision:
- 22:6d7a72fab8ff
- Parent:
- 20:f5a6527bfda6
- Child:
- 23:3563e1699fb9
diff -r fab25540a789 -r 6d7a72fab8ff main.cpp --- a/main.cpp Thu Jan 01 10:24:48 2015 +0000 +++ b/main.cpp Thu Jan 01 15:00:33 2015 +0000 @@ -1,6 +1,7 @@ #include "mbed.h" #include "PololuLedStrip.h" #include "ESP8266_WebServer.h" +#include "resource.h" #include <string> //#define DEBUG_WIFI @@ -18,8 +19,7 @@ Serial pc(USBTX,USBRX); ESP8266_WebServer server(&wifiSerial); -const char javascript[] = "function hello() { alert('Hello World'); }"; -const char css[] = "body { background-color:#DDDDDD; font-size:14px; }"; +char temp[200]; #ifdef DEBUG_WIFI void pcrxint(void) { @@ -87,32 +87,40 @@ } std::string httpReply; if( request->URI == "/" ) { - httpReply = "<html><head><title>WiFi Lamp</title> \ -<link rel='stylesheet' href='wifilamp.css'> \ -<script src='wifilamp.js'></script></head> \ -<body><h1>The WiFi Lamp v0.02 is alive ...</h1>Quick colour links:<br> \ -<a href='/red'>Red</a><br><a href='/green'>Green</a><br><a href='/blue'>Blue</a><br><a href='/white'>White</a><br> \ -<form id='setcolour' action='setcolour' > \ - <p> \ - Red: <input type='text' name='r' value='0' /> \ - </p> \ - <p> \ - Green: <input type='text' name='g' value='0' /> \ - </p> \ - <p> \ - Blue: <input type='text' name='b' value='0' /> \ - </p> \ - <p> \ - <input type='submit' /> \ - </p> \ -</form> \ - </body></html>"; - setColor(0,0,0); + httpReply = "<html><head><title>RGB WiFi Lamp</title>\ +<link rel='stylesheet' href='wifilamp.css' />\ +<script src='wifilamp.js'></script>\ +</head>\ +<body onLoad='onLoad()'>\ +<table>\ +<tr>\ +<td style='width:250px' valign='top'>\ +<img style='margin-right:2px' src='colormap.gif' usemap='#colormap' />\ +<map id='colormap' name='colormap'>"; + int startx = 63; + int countx = 7; + for( int y=0; y<=180; y+=15) { + int endx = startx + (countx*18); + for( int x=startx; x<endx; x+= 18) { + sprintf(temp, areaHTML, x,y, x+9,y+4, x+9,y+15, x,y+19, x-9,y+15, x-9,y+4); + httpReply += temp; + } + if( y < 90 ) { + startx -= 9; + countx++; + } else { + startx += 9; + countx--; + } + } + httpReply += "</map><br/><span onClick=\"changeColor('#000000')\">Turn Off</span></td><td align='right'></td></tr></table></body>"; server.SendReply(request->LinkID, httpReply, mimeHTML); } else if( request->URI == "/wifilamp.js" ) { server.SendReply(request->LinkID, javascript, strlen(javascript), mimeJavaScript); } else if( request->URI == "/wifilamp.css" ) { server.SendReply(request->LinkID, css, strlen(css), mimeCSS); + } else if( request->URI == "/colormap.gif" ) { + server.SendReply(request->LinkID, (char*)colormap, sizeof(colormap), "image/gif"); } else if( request->URI == "/red" ) { httpReply = "<html><head><title>WiFi Lamp</title></head><body><h1>The WiFi Lamp is now Red - To Turn <a href='/'>Off</a></h1></body></html>"; setColor(100, 0, 0);