2 # -*- coding: utf-8 -*-
9 from pylibcerebrum
.serial_mux
import SerialMux
11 BASE_URI
= 'http://10.0.1.43/dmxacl/json/'
12 CBEAM
= 'http://c-beam.cbrp3.c-base.org/rpc/'
13 PORT
= '/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A700fmkX-if00-port0'
16 CACERT
= os
.path
.join(os
.path
.dirname(__file__
), 'cacert.pem')
18 s
= SerialMux(PORT
, BAUDRATE
)
19 print('discovering cerebrum devices')
22 results
= s
.discover()
24 print('opening first device')
26 print('initializing device')
28 g
.schnurlinks
.state
= 1
29 g
.schnurmitte
.state
= 1
30 g
.schnurrechts
.state
= 1
31 print('starting event loop')
34 c
= (o
/255)**(1/GAMMA
) #inverse gamma correction
38 return round((c
**GAMMA
)*255)
41 state
= requests
.post(BASE_URI
, data
='{"method": "lightSync.pull", "params": [], "id": 0}').json()['result']
43 v
['red'] = xform(v
['red'], r
)
44 v
['green'] = xform(v
['green'], g
)
45 v
['blue'] = xform(v
['blue'], b
)
47 requests
.post(BASE_URI
, data
=json
.dumps({'method': 'lightSync.push', 'params': [state
], 'id': 0}))
48 except requests
.HTTPError
as e
:
49 print('Cannot set DMX color:', e
)
51 def sendstate(schnur
, state
):
53 requests
.post(CBEAM
, data
=json
.dumps({'method': 'barschnur', 'params': [schnur
, state
], 'id': 0}), verify
=CACERT
)
54 except requests
.HTTPError
as e
:
55 print('Cannot send event to c-beam:', e
)
58 sr
, sg
, sb
= False, False, False
60 if g
.schnurlinks
.state
:
62 sendstate('links', False)
67 sendstate('links', True)
69 if g
.schnurmitte
.state
:
71 sendstate('mitte', False)
76 sendstate('mitte', True)
78 if g
.schnurrechts
.state
:
80 sendstate('rechts', False)
85 sendstate('rechts', True)