summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdwin Eefting <edwin@datux.nl>2011-08-13 12:14:16 (GMT)
committer Edwin Eefting <edwin@datux.nl>2011-08-13 12:14:16 (GMT)
commit05e98b75dadf677b4112821c04d862b0cd7271ca (patch)
treea08c2b5eac212ba92eebb7b8d8b018e6b783a268
parent731739e06725edd0d3f56506a1727b210d9f4a62 (diff)
fixes
-rw-r--r--modules/dmx.module/module.cpp164
-rw-r--r--wwwdir/dmx.html30
2 files changed, 143 insertions, 51 deletions
diff --git a/modules/dmx.module/module.cpp b/modules/dmx.module/module.cpp
index cb80ac9..11fa1de 100644
--- a/modules/dmx.module/module.cpp
+++ b/modules/dmx.module/module.cpp
@@ -21,14 +21,21 @@
#include <boost/regex.hpp>
#include <sstream>
#include <iomanip>
+#include "exception/cexception.h"
using namespace boost;
using namespace std;
+int moduleSessionId=0;
+int netSessionId=0;
+Cvar dmxValues;
+
SYNAPSE_REGISTER(module_Init)
{
Cmsg out;
+ moduleSessionId=msg.dst;
+
out.clear();
out.event="core_ChangeModule";
out["maxThreads"]=10;
@@ -36,7 +43,7 @@ SYNAPSE_REGISTER(module_Init)
out.clear();
out.event="core_ChangeSession";
- out["maxThreads"]=10;
+ out["maxThreads"]=1;
out.send();
out.clear();
@@ -44,15 +51,37 @@ SYNAPSE_REGISTER(module_Init)
out["name"]="http_json";
out.send();
- //anyone can set
+ out.clear();
+ out.event="core_NewSession";
+ out.send();
+
+ //anyone can set values
out.clear();
out.event="core_ChangeEvent";
out["event"]= "dmx_Set";
out["modifyGroup"]= "modules";
out["sendGroup"]= "anonymous";
+ out["recvGroup"]= "modules";
+ out.send();
+
+ //anyone can receive updates
+ out.clear();
+ out.event="core_ChangeEvent";
+ out["event"]= "dmx_Update";
+ out["modifyGroup"]= "modules";
+ out["sendGroup"]= "modules";
out["recvGroup"]= "anonymous";
out.send();
+ //anyone can request full updates
+ out.clear();
+ out.event="core_ChangeEvent";
+ out["event"]= "dmx_Get";
+ out["modifyGroup"]= "modules";
+ out["sendGroup"]= "anonymous";
+ out["recvGroup"]= "modules";
+ out.send();
+
//just connect something
out.clear();
out.event="dmx_Connect";
@@ -90,39 +119,30 @@ class CnetDmx : public synapse::Cnet
{
//convert streambuf to string
string dataStr(boost::asio::buffer_cast<const char*>(readBuffer.data()), readBuffer.size());
- dataStr.resize(dataStr.find(delimiter)+delimiter.length());
-
-
- /* Example lirc output:
- 0000000000001010 00 sys_00_command_10 PHILIPS_RC-5
- 0000000000001010 01 sys_00_command_10 PHILIPS_RC-5
- 0000000000001010 02 sys_00_command_10 PHILIPS_RC-5
- 0000000000001010 03 sys_00_command_10 PHILIPS_RC-5
- 0000000000001011 00 sys_00_command_11 PHILIPS_RC-5
- 0000000000001011 01 sys_00_command_11 PHILIPS_RC-5
- 0000000000001011 02 sys_00_command_11 PHILIPS_RC-5
- */
+
//parse lirc output
- smatch what;
- if (regex_match(
- dataStr,
- what,
- boost::regex("(.*?) (.*?) (.*?) (.*?)\n")
- ))
- {
- //send to destination -1: this is the user configurable event mapper
- //TODO: different events for long-presses and double presses?
- Cmsg out;
- out.dst=-1;
- out.event="dmx_"+what[4]+"."+what[3];
- out["code"] =what[1];
- out["repeat"] =what[2];
- out.send();
- }
- else
- {
- ERROR("Cant parse dmx output: " << dataStr);
- }
+// smatch what;
+// if (regex_match(
+// dataStr,
+// what,
+// boost::regex("(.*?) (.*?) (.*?) (.*?)\n")
+// ))
+// {
+// //send to destination -1: this is the user configurable event mapper
+// //TODO: different events for long-presses and double presses?
+// Cmsg out;
+// out.dst=-1;
+// out.event="dmx_"+what[4]+"."+what[3];
+// out["code"] =what[1];
+// out["repeat"] =what[2];
+// out.send();
+// }
+// else
+// {
+// ERROR("Cant parse dmx output: " << dataStr);
+// }
+
+ DEB("DMX answer: "<<dataStr);
readBuffer.consume(dataStr.length());
@@ -137,24 +157,46 @@ class CnetDmx : public synapse::Cnet
out.send();
}
-// void startAsyncRead()
-// {
-// asio::async_read_until(
-// tcpSocket,
-// readBuffer,
-// boost::regex("a"),
-// bind(&Cnet::readHandler, this, _1, _2)
-// );
-// }
+ void startAsyncRead()
+ {
+ asio::async_read_until(
+ tcpSocket,
+ readBuffer,
+ boost::regex("."),
+ bind(&Cnet::readHandler, this, _1, _2)
+ );
+ }
};
synapse::CnetMan<CnetDmx> net;
-SYNAPSE_REGISTER(dmx_Connect)
+SYNAPSE_REGISTER(module_SessionStart)
{
- net.runConnect(msg["id"], msg["host"], msg["port"], 5);
+ if (msg.dst!=moduleSessionId)
+ {
+ netSessionId=msg.dst;
+ Cmsg out;
+ out.clear();
+ out.event="core_ChangeSession";
+ out["maxThreads"]=10;
+ out.send();
+ }
+}
+
+
+SYNAPSE_REGISTER(dmx_Connect)
+{
+ if (msg.dst==netSessionId)
+ {
+ net.runConnect(msg["id"], msg["host"], msg["port"], 5);
+ }
+ else
+ {
+ msg.dst=netSessionId;
+ msg.send();
+ }
}
/** Set specified dmx channel to a value
@@ -162,6 +204,14 @@ SYNAPSE_REGISTER(dmx_Connect)
*/
SYNAPSE_REGISTER(dmx_Set)
{
+ if (msg["channel"]>1024 || msg["channel"]<0)
+ throw(synapse::runtime_error("Illegal channel"));
+
+ if (msg["value"]>255 || msg["value"]<0)
+ throw(synapse::runtime_error("Illegal value"));
+
+
+
stringstream dmxStr;
//*C9<layer><channel><value>#
dmxStr << "*C9fe";
@@ -171,9 +221,33 @@ SYNAPSE_REGISTER(dmx_Set)
dmxStr << "#";
string s=dmxStr.str();
net.doWrite(msg["id"], s);
+
+ Cmsg out;
+ out.event="dmx_Update";
+ out["channel"]=msg["channel"];
+ out["value"]=msg["value"];
+ out.send();
+
+ dmxValues[msg["channel"]]["value"]=msg["value"];
+ dmxValues[msg["channel"]]["channel"]=msg["channel"];
}
+SYNAPSE_REGISTER(dmx_Get)
+{
+ FOREACH_VARMAP(value, dmxValues)
+ {
+ Cmsg out;
+ out.dst=msg.src;
+ out.event="dmx_Update";
+ out["channel"]=value.second["channel"];
+ out["value"]=value.second["value"];
+ out.send();
+
+ }
+
+}
+
SYNAPSE_REGISTER(dmx_Disconnect)
{
net.doDisconnect(msg["id"]);
diff --git a/wwwdir/dmx.html b/wwwdir/dmx.html
index 87f1824..c630fd5 100644
--- a/wwwdir/dmx.html
+++ b/wwwdir/dmx.html
@@ -21,12 +21,14 @@
synapse_register("module_SessionStart",function(msg_src, msg_dst, msg_event, msg)
{
+ send(0,"dmx_Get",{});
});
/// JAVA SCRIPT EVENT HANDLERS
$(document).ready(function(){
+
$(".send").click(function()
{
var msg=JSON.parse($(this).parent().children(".message").val());
@@ -50,10 +52,11 @@
});
- synapse_register("dmx_Set",function(msg_src, msg_dst, msg_event, msg)
+ synapse_register("dmx_Update",function(msg_src, msg_dst, msg_event, msg)
{
$("[_channel="+msg["channel"]+"]").slider("option", "value", msg["value"]);
});
+
});
@@ -61,7 +64,7 @@
</script>
<style>
- .slider{
+ .slider {
float:left;
margin:2em;
}
@@ -71,10 +74,25 @@
<body>
-<div class='slider' _channel='5'>red</div>
-<div class='slider' _channel='7'>green</div>
-<div class='slider' _channel='6'>white</div>
-<div class='slider' _channel='8'>blue</div>
+
+<h1>Dyne village light controller</h1>
+<div>
+ <div class='slider' _channel='5'>red</div>
+ <div class='slider' _channel='7'>green</div>
+ <div class='slider' _channel='6'>white</div>
+ <div class='slider' _channel='8'>blue</div>
+</div>
+
+<p>
+Yeah...this actually controls our lights..please turn at least the white light back on after you're done playing :D
+
+<p>
+Powered by <a href='http://lanbox.com/'>LanBox DMX controllers</a>.
+
+<p>
+<a href='http://events.ccc.de/camp/2011/wiki/Dyne#Projects'>Dyne village</a>
+
+
</body>
</html>