Skip to content

Commit

Permalink
Refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
robin7331 committed Jul 6, 2023
1 parent 3657d84 commit 4101d88
Show file tree
Hide file tree
Showing 16 changed files with 458 additions and 419 deletions.
15 changes: 12 additions & 3 deletions src/communication_manager.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import version
import select
import sys
from pixel_pump import PowerMode
from enums.power_mode import PowerMode
import machine
import sys

Expand Down Expand Up @@ -33,11 +33,16 @@ def parse(self, line):
print("Unknown command '" + command + "'")

def parse_version_cmd(self, arguments):
if not self.check_has_argument(arguments, 0):
return

arguments = arguments[0]
if arguments == "info":
print(version.tag + "," + version.branch + "," + version.commit_hash + "," + version.timestamp)

def parse_reset_cmd(self, arguments):
if not self.check_has_argument(arguments, 0):
return
arguments = arguments[0]
if arguments == "soft":
sys.exit()
Expand All @@ -47,6 +52,8 @@ def parse_reset_cmd(self, arguments):


def parse_settings_cmd(self, arguments):
if not self.check_has_argument(arguments, 0):
return
cmd = arguments[0]
if cmd == "dump":
print(self.settings_manager.read_all_settings())
Expand Down Expand Up @@ -172,10 +179,12 @@ def parse_settings_cmd(self, arguments):


def check_has_argument(self, arguments, index):
if len(arguments) < index:
try:
arguments[index]
return True
except IndexError:
print("Missing argument")
return False
return True

def check_valid_float_argument(self, arguments, index):
if len(arguments) < index:
Expand Down
2 changes: 2 additions & 0 deletions src/enums/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .power_mode import PowerMode
from .colors import Colors
4 changes: 4 additions & 0 deletions src/enums/brightness.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Brightness:
DIMMER = 0.12
DEFAULT = 0.19
BRIGHTER = 0.32
6 changes: 6 additions & 0 deletions src/enums/colors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Colors:
NONE = (0, 0, 0)
BLUE = (90, 183, 232)
RED = (242, 31, 31)
GREEN = (63, 242, 31)
WHITE = (255, 255, 255)
4 changes: 4 additions & 0 deletions src/enums/power_mode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class PowerMode:
LOW = 0
HIGH = 1
MAX = 2
7 changes: 3 additions & 4 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import machine
from machine import Pin, PWM, mem32
from machine import Pin, PWM, mem32, Timer
from ui_renderer import UIRenderer
from machine import Timer
from io_event_source import IOEventSource, IOEvent
from button import Button
from valve import Valve
from pixel_pump import PixelPump, PowerMode
from pixel_pump import PixelPump
from enums.power_mode import PowerMode
from boot_sequence import run_boot_sequence
from motor import Motor
import utime
import keyboard
from machine import UART, Pin
from communication_manager import CommunicationManager

# Register Base Addresses
Expand Down
Loading

0 comments on commit 4101d88

Please sign in to comment.