-
Notifications
You must be signed in to change notification settings - Fork 0
INA226 current consumption sensor support #89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
a3bfd33
add gps.mpy to files copied by download (commented out)
Robotmad 33f7938
improve hexdrive app - when deinitilaised set pins to input
Robotmad 3d7db66
knowledge of gps hexpansion app, removed unnecessary whitespace that …
Robotmad 4d98088
enable stronger type checkign and then fix up lots of things that the…
Robotmad e5498a0
Add full INA226 sensor support and motor-test current charting (#88)
Copilot 0ba9ffb
Comment out debug print for sensor test feature
Robotmad 5b87adb
Fix sensor manager closing logic in tests
Robotmad ec6d817
Check sensor type before turning off LED
Robotmad a88a359
Update gps.py
Robotmad 511df12
Update motor_moves.py
Robotmad e436ef7
Update app.py
Robotmad 28d7862
Fix GPS reset logic: active high means timer runs while reset=1, rele…
Copilot d3ad7c8
Update sensor_test.py
Robotmad cb11175
Revert _ROTATION_RATE_EMITTER_PINS to [2, 4] (LS_C & LS_D only)
Copilot 8136b16
Disable unused HexpansionTypes in app.py
Robotmad 90a75d8
Comment out hexgps_port in hexpansion_mgr.py
Robotmad 8f4c553
Comment out hexgps_port in app.py
Robotmad d7298f1
moved hexpansion EEPROM code to EEPROM sub-directory
lincoltd7 4c95a2c
Update README.md for WSL setup instructions and add WSL environment s…
lincoltd7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,4 +5,5 @@ BadgeBot.code-workspace | |
| .deploy_state/test_device_download_state.json | ||
| .editorconfig | ||
| .venv/ | ||
| .venv-wsl*/ | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,190 @@ | ||
| """ GPS App for Hexpansion """ | ||
| import app | ||
|
|
||
| from app_components.tokens import label_font_size, button_labels | ||
| from events.input import Buttons, BUTTON_TYPES, ButtonDownEvent | ||
| from system.eventbus import eventbus | ||
| from system.hexpansion.config import HexpansionConfig | ||
| from system.patterndisplay.events import PatternDisable, PatternEnable | ||
| from system.scheduler.events import RequestForegroundPopEvent, RequestForegroundPushEvent, RequestStopAppEvent | ||
| from tildagonos import tildagonos | ||
| from machine import UART, Pin | ||
|
|
||
| # Minimal length method names to make the mpy file as small as possible so it might fit in the 2k hexpansion EEPROM. | ||
| # Minimal functionality to get a GPS fix | ||
| # This version is NOT for the App Store | ||
|
|
||
| VERSION = 1 | ||
|
|
||
| # Hardware defintions: | ||
| TX_PIN = 1 # HS_G for TX | ||
| RX_PIN = 0 # HS_F for RX | ||
| RESET_PIN = 2 # HS_H for reset | ||
| PPS_PIN = 3 # HS_I for PPS | ||
|
|
||
| ###JUST FOR USE WITH MY PROTOTYPE BOARD | ||
| ENABLE_PIN = 0 # First LS pin used to enable the SMPSU | ||
| ###JUST FOR USE WITH MY PROTOTYPE BOARD | ||
|
|
||
| class GPSApp(app.App): # pylint: disable=no-member | ||
| """ App to get GPS data from a GPS module connected to the hexpansion and display it on the badge. """ | ||
| def __init__(self, config: HexpansionConfig | None = None): | ||
| super().__init__() | ||
| # If run from EEPROM on the hexpansion, the config will be passed in with the correct pin objects | ||
| self.config: HexpansionConfig | None = config | ||
| if config is None: | ||
| return | ||
| self.tx_pin = config.pin[TX_PIN] | ||
| self.rx_pin = config.pin[RX_PIN] | ||
| self.reset = config.pin[RESET_PIN] | ||
| self.pps = config.pin[PPS_PIN] | ||
|
|
||
| ###JUST FOR USE WITH MY PROTOTYPE BOARD | ||
| self.power_control = config.ls_pin[ENABLE_PIN] | ||
| self.power_control.init(mode=Pin.OUT) | ||
| self.power_control.value(1) | ||
| ###JUST FOR USE WITH MY PROTOTYPE BOARD | ||
|
|
||
| self.foreground = False | ||
| self.button_states = Buttons(self) | ||
| self.last_fix = None | ||
|
|
||
| # Event handlers for gaining and losing focus and for stopping the app | ||
| eventbus.on_async(RequestStopAppEvent, self.s, self) | ||
| eventbus.on_async(RequestForegroundPushEvent, self.r, self) | ||
| eventbus.on_async(RequestForegroundPopEvent, self.p, self) | ||
|
|
||
| self.uart = UART(1, baudrate=9600, tx=self.tx_pin, rx=self.rx_pin) | ||
| self.reset.init(mode=Pin.OUT) | ||
| self.pps.init(mode=Pin.IN) | ||
| self.reset.value(1) # set reset high here and release when 100ms has passed in foreground update. | ||
| self.ticks_since_start = 0 | ||
| self.ticks_since_last_fix = 0 | ||
|
|
||
|
|
||
| def deinit(self): | ||
| """ Deinitialise the app, releasing any resources (e.g. UART) """ | ||
| self.uart.deinit() | ||
| self.power_control.value(0) # Cut power to the GPS to save power when not in use | ||
|
|
||
|
|
||
| def get_version(self) -> int: | ||
| """ Get the version of the app - this is used to determine if an upgrade is required. """ | ||
| return VERSION | ||
|
|
||
|
|
||
| async def s(self, event: RequestStopAppEvent): | ||
| """ Handle the RequestStopAppEvent so that we can release resources """ | ||
| if event.app == self: | ||
| self.deinit() | ||
|
|
||
|
|
||
| async def r(self, event: RequestForegroundPushEvent): | ||
| """ Handle the RequestForegroundPushEvent to know when we gain focus """ | ||
| if event.app == self: | ||
| eventbus.emit(PatternDisable()) | ||
| eventbus.on(ButtonDownEvent, self.d, self) | ||
| self.foreground = True | ||
|
|
||
|
|
||
| async def p(self, event: RequestForegroundPopEvent): | ||
| """ Handle the RequestForegroundPopEvent to know when we lose focus """ | ||
| if event.app == self: | ||
| eventbus.emit(PatternEnable()) | ||
| eventbus.remove(ButtonDownEvent, self.d, self) | ||
|
|
||
|
|
||
| def d(self, event: ButtonDownEvent): | ||
| """ Handle button down events """ | ||
| if event.button == BUTTON_TYPES["CANCEL"]: | ||
| self.button_states.clear() | ||
| self.minimise() | ||
|
|
||
|
|
||
| def update(self, delta): | ||
| """ Update the app state - expire last_fix if it is too old """ | ||
| if self.reset.value(): | ||
| self.ticks_since_start += delta | ||
| if self.ticks_since_start > 100: | ||
| # Release reset after 100ms to allow the GPS to start up | ||
| self.reset.value(0) | ||
| if not self.foreground: | ||
| # This triggers the automatic foreground display | ||
| eventbus.emit(RequestForegroundPushEvent(self)) | ||
| self.foreground = True | ||
| if self.last_fix: | ||
| self.ticks_since_last_fix += delta | ||
| if self.ticks_since_last_fix > 10000: | ||
| # If it's been more than 10 seconds since the last fix, disccard it | ||
| self.last_fix = None | ||
|
|
||
|
|
||
| def background_update(self, _delta): | ||
| """ Update in the background - read from the UART and parse any GPS data """ | ||
| line = self.uart.readline() | ||
| if line: | ||
| try: | ||
| line = line.decode().strip() | ||
| result = n(line) | ||
| if result: | ||
| self.last_fix = result | ||
| self.ticks_since_last_fix = 0 | ||
| except (UnicodeError, ValueError, AttributeError): | ||
| pass | ||
|
|
||
|
|
||
| def draw(self, ctx): | ||
| """ Draw the app - display the last GPS fix or a searching message if no fix is available """ | ||
| ctx.rgb(0, 0.2, 0).rectangle(-120, -120, 240, 240).fill() | ||
| ctx.rgb(0, 1, 0) | ||
| ctx.font_size = label_font_size | ||
| ctx.text_align = ctx.LEFT | ||
| ctx.text_baseline = ctx.BOTTOM | ||
| if self.last_fix: | ||
| ctx.move_to(-100, -10).text("Lat: " + str(round(self.last_fix["lat"], 5))) | ||
| ctx.move_to(-100, 20).text("Lon: " + str(round(self.last_fix["lon"], 5))) | ||
| for i in range(1, 13): | ||
| tildagonos.leds[i] = (0,1,0) | ||
| tildagonos.leds.write() | ||
| else: | ||
| ctx.move_to(-100, 0).text("Searching...") | ||
| for i in range(1,13): | ||
| tildagonos.leds[i] = (0,0,0) | ||
| tildagonos.leds.write() | ||
|
|
||
| # show labels for buttons | ||
| button_labels(ctx, cancel_label="Exit") | ||
|
|
||
| def n(line: str) -> dict[str, float] | None: | ||
| """ Parse an NMEA RMC sentence and return a dictionary with the latitude and longitude if valid, or None if invalid. """ | ||
| parts = line.split(',') | ||
|
|
||
| if parts[0] not in ("$GNRMC", "$GPRMC"): | ||
| return None | ||
| elif parts[2] != "A": # A = valid, V = invalid | ||
| return None | ||
| else: | ||
| lat_raw = parts[3] | ||
| lat_dir = parts[4] | ||
| lon_raw = parts[5] | ||
| lon_dir = parts[6] | ||
|
|
||
| if not lat_raw or not lon_raw: | ||
| return None | ||
|
|
||
| # Convert to decimal degrees | ||
| lat = float(lat_raw[:2]) + float(lat_raw[2:]) / 60 | ||
| lon = float(lon_raw[:3]) + float(lon_raw[3:]) / 60 | ||
|
|
||
| if lat_dir == "S": | ||
| lat = -lat | ||
| if lon_dir == "W": | ||
| lon = -lon | ||
|
|
||
| return { | ||
| "lat": lat, | ||
| "lon": lon | ||
| } | ||
|
|
||
|
|
||
| __app_export__ = GPSApp #pylint: disable=invalid-name | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.