Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#import aioble
#import bluetooth
import os
import sys
import time
from math import cos, pi
import ota
Expand All @@ -12,7 +13,11 @@
from app_components import Menu
from events.input import BUTTON_TYPES, Button, Buttons, ButtonUpEvent
from frontboards.twentyfour import BUTTONS
from machine import I2C, Timer
from machine import I2C
try:
from machine import Timer
except ImportError:
Timer = None
from system.eventbus import eventbus
from system.hexpansion.events import (HexpansionInsertionEvent,
HexpansionRemovalEvent)
Expand Down Expand Up @@ -151,6 +156,7 @@
#Misceallaneous Settings
_LOGGING = False
_ERASE_SLOT = 0 # Slot for user to set if they want to erase EEPROMs on HexDrives
_IS_SIMULATOR = sys.platform != "rp2" # True when running in the simulator, not on real badge hardware

#
_main_menu_items = ["Motor Moves", "Stepper Test", "Servo Test", "Settings", "About","Exit"]
Expand Down Expand Up @@ -321,7 +327,7 @@ def __init__(self):
#aioble.register_services(self.ble_service)

# We start with focus on launch, without an event emmited
self._gain_focus(RequestForegroundPushEvent(self))
asyncio.get_event_loop().create_task(self._gain_focus(RequestForegroundPushEvent(self)))


### ASYNC EVENT HANDLERS ###
Expand Down Expand Up @@ -444,6 +450,9 @@ def check_port_for_hexdrive(self, port: int) -> bool:
return False
except RuntimeError:
# not a valid header
if _IS_SIMULATOR:
# In the simulator there is no real EEPROM hardware, so skip the programming prompt
return False
if self._settings['logging'].v:
print(f"H:Found EEPROM on port {port}")
self.ports_with_blank_eeprom.add(port)
Expand Down Expand Up @@ -633,7 +642,7 @@ def erase_eeprom(self, port: int, addr: int) -> bool:

def find_hexdrive_app(self, port: int) -> app:
for an_app in scheduler.apps:
if type(an_app).__name__ is 'HexDriveApp':
if type(an_app).__name__ == 'HexDriveApp':
if hasattr(an_app, "config") and hasattr(an_app.config, "port") and an_app.config.port == port:
return an_app
return None
Expand Down Expand Up @@ -1923,7 +1932,7 @@ def __init__(self, container, hexdrive_app, step_size: int = 1, steps_per_rev: i
self._hexdrive_app = hexdrive_app
self._phase = 0
self._calibrated = False
self._timer = Timer(timer_id)
self._timer = Timer(timer_id) if Timer is not None else None
self._timer_is_running = False
self._timer_mode = 0
self._free_run_mode = 0 # direction of free run mode
Expand Down Expand Up @@ -2063,6 +2072,8 @@ def track_target(self):
self._update_timer((2//self._step_size)*abs(self._steps_per_sec)) # half steps per second

def _update_timer(self,freq):
if self._timer is None:
return
if self._timer_is_running and freq != self._freq:
try:
self._timer.deinit()
Expand Down