-
Notifications
You must be signed in to change notification settings - Fork 7
/
pwmserver
executable file
·44 lines (32 loc) · 1.06 KB
/
pwmserver
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/python
import vxi11server
import wiringpi
import logging
import re
OUTPIN = 18 # GPIO numbering
logger = logging.getLogger('pwmserver')
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
logger.addHandler(ch)
pwm_is_running = False
def on_receive(message):
logger.info("received string: %s", message)
start_pwm = re.findall(':SOUR.*:PWM ([0-9]+) ([0-9]+)', message)
global pwm_is_running
if start_pwm != []:
if pwm_is_running == False:
pwm_power = int(start_pwm[0][0])
pwm_range = int(start_pwm[0][1])
wiringpi.wiringPiSetupGpio()
wiringpi.softPwmCreate(OUTPIN,pwm_power,pwm_range)
pwm_is_running = True
else:
logger.warn("pwm already running")
set_power = re.findall(':SOUR.*:POWER ([0-9]+)', message)
if set_power != []:
pwm_power = int(set_power[0])
logger.debug("set power to %s", pwm_power)
wiringpi.softPwmWrite(OUTPIN,pwm_power)
vxi11server.on_receive = on_receive
vxi11server.listen()