Spidey Wall is the name for a physical wall lit up by multiple addressable LED strips. This program is an LPC1768 web server to control the wall from a browser.
Dependencies: EthernetInterfacePlusHostname RdWebServer mbed-rtos mbed
This project is part of a Light-Wall using addressable LED strips (WS2801). I have published a few posts on my blog about the construction of the wall and building a game to play on it (PacMan). I have also had a guest post from a friend who has set his children the task of producing some interesting animations. The original post is http://robdobson.com/2015/07/spidey-wall/
So far, however, I hadn't fully connected the physical (and electronic) wall with the web-browser creations to drive it. This project is hopefully the final link. A fast and reliable web server using REST commands to drive the 1686 LEDs in the Spidey Wall from code running in a browser (say on an iPad while you are playing a game).
The approach taken here results in the ability to control the RGB values of all 1686 LEDs at a rate of 20 frames per second.
A blog post describing the whole thing is here:
http://robdobson.com/2015/08/a-reliable-mbed-webserver/
Revision 2:99eb4c6e9ea4, committed 2015-08-29
- Comitter:
- Bobty
- Date:
- Sat Aug 29 05:33:30 2015 +0000
- Parent:
- 1:362331cec9b7
- Child:
- 3:e5ea80fae61d
- Commit message:
- Working for simple cases
Changed in this revision
--- a/DrawingManager.cpp Thu Aug 20 07:41:02 2015 +0000
+++ b/DrawingManager.cpp Sat Aug 29 05:33:30 2015 +0000
@@ -6,18 +6,25 @@
#include "DrawingManager.h"
#include "rtos.h"
-DrawingManager::DrawingManager(int numLeds, int splitPoint)
+DrawingManager::DrawingManager()
{
- pLedStrip = new ledstrip(numLeds, splitPoint);
+ pLedStrip = NULL;
isBusy = false;
}
-void DrawingManager::init()
+void DrawingManager::init(int numLeds, int splitPoint)
{
+ pLedStrip = new ledstrip(numLeds, splitPoint);
+ Thread::wait(100);
+ pLedStrip->Clear();
+ pLedStrip->ShowLeds();
+
}
char* DrawingManager::start(const unsigned char* cmdBuf, int cmdLen)
{
+ if (!pLedStrip)
+ return "NOINIT";
if (isBusy)
return "BUSY";
isBusy = true;
--- a/DrawingManager.h Thu Aug 20 07:41:02 2015 +0000
+++ b/DrawingManager.h Sat Aug 29 05:33:30 2015 +0000
@@ -8,8 +8,8 @@
class DrawingManager
{
public:
- DrawingManager(int numLeds, int splitPoint);
- void init();
+ DrawingManager();
+ void init(int numLeds, int splitPoint);
void service();
char* start(const unsigned char* cmdBuf, int cmdLen);
--- a/ledstrip.cpp Thu Aug 20 07:41:02 2015 +0000
+++ b/ledstrip.cpp Sat Aug 29 05:33:30 2015 +0000
@@ -267,6 +267,6 @@
// Check if second strip is used
LPC_SSP0->IMSC = (1 << SSP_IMSC_TX_RDY) & SSP_IMSC_BITMASK;
- if (mSplitPoint < mLedsInStrip)
+ if (mSplitPoint < mLedsInStrip && mSplitPoint > 0)
LPC_SSP1->IMSC = (1 << SSP_IMSC_TX_RDY) & SSP_IMSC_BITMASK;
}
--- a/main.cpp Thu Aug 20 07:41:02 2015 +0000
+++ b/main.cpp Sat Aug 29 05:33:30 2015 +0000
@@ -1,5 +1,5 @@
//
-// Spidey Wall WebServer
+// LightWall WebServer
//
// Rob Dobson 2015
@@ -14,13 +14,18 @@
// Debugging and status
RawSerial pc(USBTX, USBRX);
-DigitalOut led1(LED1); // ticking (flashes)
+DigitalOut led1(LED1); // flashes on command received
DigitalOut led2(LED2); //
DigitalOut led3(LED3); //
DigitalOut led4(LED4); // web server status
+// System configuration
+char systemName[20] = "LightWall";
+int systemNumLEDS = 20;
+int systemLEDSSplitPoint = systemNumLEDS;
+
// Drawing Manager
-DrawingManager drawingManager(1686, 780);
+DrawingManager drawingManager;
//int ledsCount = 904;
//int ledSplitPoint = 448;
@@ -142,7 +147,7 @@
// // Cmd handler
// pLedCmdHandler = new LedCmdHandler(pLedStrip);
//}
-//
+
//int main (void)
//{
// pc.baud(115200);
@@ -169,41 +174,83 @@
// Handle a command
char* lightwallCmd(int method, char* cmdStr, char* argStr, char* msgBuf)
{
+ // Blink LED
+ led1 = !led1;
+
+ // Get message payload
int cmdLen = RdWebServer::getPayloadLengthFromMsg(msgBuf);
unsigned char* cmdBuf = RdWebServer::getPayloadDataFromMsg(msgBuf);
pc.printf("Command Payload Len %d\r\n", cmdLen);
- if (cmdLen == 256)
- {
- for (int i = 0; i < cmdLen; i++)
- if (cmdBuf[i] != i)
- {
- printf("Binary content err at %d\r\n", i);
- break;
- }
- }
+
+ // Process command
char* respStr = "";
respStr = drawingManager.start(cmdBuf, cmdLen);
return respStr;
}
+// Get system name
+char* lightwallGetSystemName(int method, char* cmdStr, char* argStr, char* msgBuf)
+{
+ // Return the system name
+ return systemName;
+}
+
// Create, configure and run the web server
void http_thread(void const* arg)
{
+ // Init the web server
pc.printf("Starting web server\r\n");
char* baseWebFolder = "/sd/"; // should be /sd/ for SDcard files - not used for local file system
RdWebServer webServer;
+
+ // Add commands to handle the home page and favicon
webServer.addCommand("", RdWebServerCmdDef::CMD_LOCALFILE, NULL, "index.htm", true);
webServer.addCommand("favicon.ico", RdWebServerCmdDef::CMD_LOCALFILE, NULL, NULL, true);
+
+ // Add the lightwall control commands
webServer.addCommand("cmd", RdWebServerCmdDef::CMD_CALLBACK, &lightwallCmd);
+ webServer.addCommand("name", RdWebServerCmdDef::CMD_CALLBACK, &lightwallGetSystemName);
+
+ // Start the server
webServer.init(WEBPORT, &led4, baseWebFolder);
webServer.run();
}
+void getSystemConfig()
+{
+ printf("LightWall - Configured for ");
+ // Check for a config file on the local file system
+ strcpy(systemName, "Spidey");
+ LocalFileSystem local("local");
+ FILE* fp = fopen("/local/lights.txt", "r");
+ if (fp != NULL)
+ {
+ char buf[201];
+ buf[sizeof(buf)-1] = 0;
+ int nread = fread(buf, 1, sizeof(buf), fp);
+ if (nread > 0 && nread <= sizeof(buf))
+ {
+ buf[nread] = 0;
+ // Read config details from the file
+ sscanf(buf, "%s %d %d", systemName, &systemNumLEDS, &systemLEDSSplitPoint);
+ }
+ fclose(fp);
+ printf("%s (%d LEDs, Split at %d)", systemName, systemNumLEDS, systemLEDSSplitPoint);
+ printf("\r\n");
+ }
+}
+
int main()
{
// Init
pc.baud(115200);
pc.printf("Light Wall - Rob Dobson 2015\r\n");
+
+ // Get the configuration of the system
+ getSystemConfig();
+
+ // Drawing manager controls the LEDs
+ drawingManager.init(systemNumLEDS, systemLEDSSplitPoint);
// Setup ethernet interface
char macAddr[6];
@@ -215,16 +262,12 @@
pc.printf("IP Address: %s\r\n", EthernetInterface::getIPAddress());
// Web Server
- Thread httpServer(&http_thread, NULL, osPriorityNormal, (DEFAULT_STACK_SIZE * 4));
+ Thread httpServer(&http_thread, NULL, osPriorityNormal, (DEFAULT_STACK_SIZE * 3));
- // Home
- drawingManager.init();
-
+ // Forever
while(true)
{
-// led1=!led1;
// Service drawing manager
drawingManager.service();
-// Thread::wait(500);
}
}