Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

updated server code and added some client code

  • Loading branch information...
commit d426bc4eaeb03c5c51ba2d126812e7361450ba6c 1 parent 99f7864
@awentz awentz authored
View
22 src/renard_clojure/run.clj
@@ -1,9 +1,13 @@
-(ns renard-clojure.run
- (:gen-class))
-
-(use 'ring.adapter.jetty)
-(require '[renard-clojure.web :as web])
-
-(defn -main [& args]
- (run-jetty #'web/app {:port 50000}))
-
+(ns renard-clojure.run
+ (:gen-class))
+
+(use 'ring.adapter.jetty)
+(require '[renard-clojure.web :as web])
+
+(defn -main [& args]
+ (run-jetty #'web/app {:port 50000}))
+
+(defn start-app []
+ (do
+ (web/add-fader-handles web/server)
+ (run-jetty #'web/app {:port 50000})))
View
45 src/renservice/renard.py
@@ -0,0 +1,45 @@
+import serial
+import renservice
+import time
+
+pb = 0x7D #pad byte
+sb = 0x7E #sync byte
+cb = 0x80 #command byte
+pad_offset = 100
+
+def special_replace(n):
+ if n == 0x7D:
+ return 0x7C
+ elif n == 0x7E:
+ return 0x7C
+ elif n == 0x7F:
+ return 0x80
+ else:
+ return n
+
+def package_bytes(light_values, channels):
+ """Packages the light dimming values into a readable format for the renard controller"""
+ pv = map(special_replace, light_values)
+ #insert a pad byte every pad_offset byte
+ if len(pv) > pad_offset:
+ for i in range(pad_offset, len(pv), pad_offset):
+ pv.insert(i, pb)
+
+ if len(pv) > channels:
+ a = len(pv) - (len(pv) % channels)
+ for i in range(a, 0, -channels):
+ pv.insert(i,cb)
+ pv.insert(i,sb)
+
+ pv.insert(0, cb)
+ pv.insert(0, sb)
+
+ return pv
+
+serport = serial.Serial('COM7', '57600', timeout=2)
+
+while True:
+ lvals = renservice.getlightvals()
+ plvals = package_bytes(lvals, 32)
+ serport.write(bytearray(plvals))
+ time.sleep(0.5)
View
15 src/renservice/renservice.py
@@ -0,0 +1,15 @@
+import httplib2
+import jsonrpclib
+import json
+
+oscuri = 'http://107.22.230.121:50000/'
+
+h = httplib2.Http()
+
+def getlightvals():
+ resp, content = h.request(oscuri)
+ lightvals = []
+ if resp['status'] == '200':
+ lightvals = json.loads(content)
+ return lightvals
+
View
29 src/renservice/renservice.pyproj
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>e98bd69a-7e0d-4cba-9ae1-2b4b3a2f42da</ProjectGuid>
+ <ProjectHome>.</ProjectHome>
+ <StartupFile>renservice.py</StartupFile>
+ <SearchPath>
+ </SearchPath>
+ <WorkingDirectory>.</WorkingDirectory>
+ <OutputPath>.</OutputPath>
+ <Name>renservice</Name>
+ <RootNamespace>renservice</RootNamespace>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
+ <DebugSymbols>true</DebugSymbols>
+ <EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
+ <DebugSymbols>true</DebugSymbols>
+ <EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
+ </PropertyGroup>
+ <ItemGroup>
+ <Compile Include="renard.py" />
+ <Compile Include="renservice.py" />
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.Common.targets" />
+</Project>
Please sign in to comment.
Something went wrong with that request. Please try again.