-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlights.py
More file actions
50 lines (39 loc) · 1.33 KB
/
lights.py
File metadata and controls
50 lines (39 loc) · 1.33 KB
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
43
44
45
46
47
48
49
50
import pigpio
import time
from logpy.LogPy import Logger
from ports import LIGHTS_DRIVER_PORT
from rov_comm import Client
PWM_lights = 27
ON_FULL = 600
OFF = 1400
class LightHandling:
def __init__(self):
self.pi = pigpio.pi()
self.logger = Logger(filename='light_handling', directory='logs/electro/')
if not self.pi.connected:
self.logger.log("pi not connected", logtype='error')
exit()
self.logger.log("setup")
self.setup()
def setup(self):
self.pi.set_PWM_frequency(PWM_lights, 400)
self.pi.set_PWM_range(PWM_lights, OFF) # 550 - OFF, 950 - ON_FULL
self.pi.set_PWM_dutycycle(PWM_lights, OFF)
def lights_set_brightness(self,x):
if x < 0: x = 0
if x > 100: x = 100
x=100-x
self.pi.set_PWM_dutycycle(PWM_lights, -8*x+1400)
self.logger.log("lights' brightness: " + str(x) + "%")
class Lights:
def __init__(self):
self.client_brightness = Client(LIGHTS_DRIVER_PORT)
self.light_handling = LightHandling()
def set_brightness(self):
command = self.client_brightness.get_data()
#print(command)
x = int(command['power'])
self.light_handling.lights_set_brightness(x)
if __name__ == "__main__":
LIGHTS = LightHandling()
LIGHTS.lights_set_brightness(0)