Skip to content

Commit de9464c

Browse files
committed
Tweaked light control for KS1
1 parent d78c6ff commit de9464c

File tree

1 file changed

+36
-19
lines changed
  • files/4-apps/home/rinkhals/apps/40-moonraker

1 file changed

+36
-19
lines changed

files/4-apps/home/rinkhals/apps/40-moonraker/kobra.py

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
class Kobra:
1717
# Environment
1818
KOBRA_MODEL_ID = None
19+
KOBRA_MODEL_CODE = None
1920
KOBRA_DEVICE_ID = None
2021
MQTT_USERNAME = None
2122
MQTT_PASSWORD = None
@@ -41,6 +42,7 @@ def __init__(self, config):
4142
environment = subprocess.check_output(['sh', '-c', command])
4243
environment = json.loads(environment.decode('utf-8').strip())
4344
self.KOBRA_MODEL_ID = environment['KOBRA_MODEL_ID']
45+
self.KOBRA_MODEL_CODE = environment['KOBRA_MODEL_CODE']
4446
self.KOBRA_DEVICE_ID = environment['KOBRA_DEVICE_ID']
4547
except:
4648
pass
@@ -70,25 +72,40 @@ def __init__(self, config):
7072
self.get_remote_mode()
7173

7274
async def component_init(self):
73-
# Add camera and head lights power devices
74-
config = self.server.config.read_supplemental_dict({
75-
'power camera_light': {
76-
'type': 'shell',
77-
'power_on_command': "v4l2-ctl -d /dev/video10 -c gain=1 2>/dev/null || printf '{\"method\":\"Led/SetCameraLed\",\"params\":{\"enable\":1},\"id\":37}\x03' | socat -t0 -,ignoreeof UNIX-CONNECT:/tmp/unix_uds1,escape=0x03",
78-
'power_off_command': "v4l2-ctl -d /dev/video10 -c gain=0 2>/dev/null || printf '{\"method\":\"Led/SetCameraLed\",\"params\":{\"enable\":0},\"id\":37}\x03' | socat -t0 -,ignoreeof UNIX-CONNECT:/tmp/unix_uds1,escape=0x03",
79-
'get_state_command': "v4l2-ctl -d /dev/video10 -C gain | awk '{print $2}'",
80-
'default_state': 'on'
81-
},
82-
'power head_light': {
83-
'type': 'shell',
84-
'power_on_command': "printf '{\"method\":\"led/set_led\",\"params\":{\"S\":1},\"id\":37}\x03' | socat -t0 -,ignoreeof UNIX-CONNECT:/tmp/unix_uds1,escape=0x03",
85-
'power_off_command': "printf '{\"method\":\"led/set_led\",\"params\":{\"S\":0},\"id\":37}\x03' | socat -t0 -,ignoreeof UNIX-CONNECT:/tmp/unix_uds1,escape=0x03",
86-
'default_state': 'on'
87-
}
88-
})
89-
90-
await self.power.add_device('camera_light', ShellPowerDevice(config.getsection('power camera_light')))
91-
await self.power.add_device('head_light', ShellPowerDevice(config.getsection('power head_light')))
75+
76+
if self.KOBRA_MODEL_CODE == 'K3':
77+
# Add camera and head lights power devices
78+
config = self.server.config.read_supplemental_dict({
79+
'power camera_light': {
80+
'type': 'shell',
81+
'power_on_command': "v4l2-ctl -d /dev/video10 -c gain=1 2>/dev/null || printf '{\"method\":\"Led/SetCameraLed\",\"params\":{\"enable\":1},\"id\":37}\x03' | socat -t0 -,ignoreeof UNIX-CONNECT:/tmp/unix_uds1,escape=0x03",
82+
'power_off_command': "v4l2-ctl -d /dev/video10 -c gain=0 2>/dev/null || printf '{\"method\":\"Led/SetCameraLed\",\"params\":{\"enable\":0},\"id\":37}\x03' | socat -t0 -,ignoreeof UNIX-CONNECT:/tmp/unix_uds1,escape=0x03",
83+
'get_state_command': "v4l2-ctl -d /dev/video10 -C gain | awk '{print $2}'",
84+
'default_state': 'on'
85+
},
86+
'power head_light': {
87+
'type': 'shell',
88+
'power_on_command': "printf '{\"method\":\"led/set_led\",\"params\":{\"S\":1},\"id\":37}\x03' | socat -t0 -,ignoreeof UNIX-CONNECT:/tmp/unix_uds1,escape=0x03",
89+
'power_off_command': "printf '{\"method\":\"led/set_led\",\"params\":{\"S\":0},\"id\":37}\x03' | socat -t0 -,ignoreeof UNIX-CONNECT:/tmp/unix_uds1,escape=0x03",
90+
'default_state': 'on'
91+
}
92+
})
93+
94+
await self.power.add_device('camera_light', ShellPowerDevice(config.getsection('power camera_light')))
95+
await self.power.add_device('head_light', ShellPowerDevice(config.getsection('power head_light')))
96+
97+
elif self.KOBRA_MODEL_CODE == 'KS1':
98+
# Add camera and head lights power devices
99+
config = self.server.config.read_supplemental_dict({
100+
'power chamber_light': {
101+
'type': 'shell',
102+
'power_on_command': "printf '{\"method\":\"led/set_led\",\"params\":{\"S\":1},\"id\":37}\x03' | socat -t0 -,ignoreeof UNIX-CONNECT:/tmp/unix_uds1,escape=0x03",
103+
'power_off_command': "printf '{\"method\":\"led/set_led\",\"params\":{\"S\":0},\"id\":37}\x03' | socat -t0 -,ignoreeof UNIX-CONNECT:/tmp/unix_uds1,escape=0x03",
104+
'default_state': 'on'
105+
}
106+
})
107+
108+
await self.power.add_device('chamber_light', ShellPowerDevice(config.getsection('power chamber_light')))
92109

93110

94111
def is_goklipper_running(self):

0 commit comments

Comments
 (0)