Skip to content

Commit

Permalink
Add support for visual indicator for provisioning status
Browse files Browse the repository at this point in the history
- more HW support

Jira-Id: SCDI-3

Signed-off-by: Mika Joenpera <[email protected]>
  • Loading branch information
joenpera committed Sep 25, 2023
1 parent 0f651b4 commit dae2f96
Showing 1 changed file with 76 additions and 27 deletions.
103 changes: 76 additions & 27 deletions modules/sc-mesh-secure-deployment/src/nats/src/hw_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,27 @@ def __init__(self):
except FileNotFoundError:
sys.exit(1)

def provisioning_led_control(self, state):
@staticmethod
def _write_to_file(path, file, value):
try:
with open(os.path.join(path, file), "w", encoding="utf-8") as engine:
engine.write(value)
except (FileNotFoundError, PermissionError):
pass

def _led_control_0(self, state) -> None:
"""
Control the provisioning LED.
:param state: start, active, stop, fail
:return: None
"""

path = "/sys/class/leds/mesh"
trigger_seq = "timer"
trigger_none = "none"
start_seq = 1000
active_seq = 100

trigger_used = ""
trigger_used = "none"
seq_used = 0

if state == "start":
Expand All @@ -46,33 +53,75 @@ def provisioning_led_control(self, state):
seq_used = 1
trigger_used = trigger_none

if self.comms_pcb_version == 1:
print("test")
elif self.comms_pcb_version in (0.5, 0):
try:
with open(os.path.join(path, "trigger"), "w", encoding="utf-8") as trigger_file:
trigger_file.write(trigger_used)
except (FileNotFoundError, PermissionError):
pass
# write to sys class led
self._write_to_file(path, "trigger", trigger_used)
self._write_to_file(path, "delay_off", str(seq_used))
self._write_to_file(path, "delay_on", str(seq_used))
self._write_to_file(path, "brightness", str(seq_used))

try:
with open(os.path.join(path, "delay_off"), "w", encoding="utf-8") as delay_off_file:
delay_off_file.write(str(seq_used))
except (FileNotFoundError, PermissionError):
pass
def _led_control_1(self, state) -> None:
"""
Control the provisioning LED.
:param state: start, active, stop, fail
:return: None
"""
path = "/sys/class/leds/rgb_leds:channel0/device"
led_matrix = "000000001"
code_used = "9d094000a001"

try:
with open(os.path.join(path, "delay_on"), "w", encoding="utf-8") as delay_on_file:
delay_on_file.write(str(seq_used))
except (FileNotFoundError, PermissionError):
pass
# LASM compiler:
# .segment program1 ; segment begins
# mux_sel 9 ; select led 9 blue
# loop1: set_pwm 2Fh
# wait 0.4
# wait 0.4
# wait 0.2
# set_pwm 00h
# wait 0.4
# wait 0.4
# wait 0.2
# branch 0,loop1
start_code = "9d09402f740074005a004000740074005a00a001"
# LASM compiler:
# .segment program1 ; segment begins
# mux_sel 9 ; select led 9 blue
# loop1: set_pwm 2Fh
# wait 0.1
# set_pwm 00h
# wait 0.1
# branch 0,loop1
active_code = "9d09402f4c0040004c00a001"

try:
with (open(os.path.join(path, "brightness"), "w", encoding="utf-8")
as brightness_file):
brightness_file.write(str(seq_used))
except (FileNotFoundError, PermissionError):
pass
if state == "start":
code_used = start_code
elif state == "active":
code_used = active_code
elif state == "stop":
# pwm 00
code_used = "9d094000a001"
elif state == "fail":
# pwm 2f
code_used = "9d09402fa001"

# write to led driver
self._write_to_file(path, "engine3_mode", "disabled")
self._write_to_file(path, "engine3_mode", "load")
self._write_to_file(path, "engine3_load", code_used)
self._write_to_file(path, "engine3_leds", led_matrix)
self._write_to_file(path, "engine3_mode", "run")


def provisioning_led_control(self, state):
"""
Control the provisioning LED.
:param state: start, active, stop, fail
:return: None
"""

if self.comms_pcb_version == 1:
self._led_control_1(state)
elif self.comms_pcb_version in (0.5, 0):
self._led_control_0(state)

if __name__ == "__main__":
led = LedControl()
Expand Down

0 comments on commit dae2f96

Please sign in to comment.