Skip to content
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

Badger 2040 display when connecting #30

Closed
exussum12 opened this issue Jun 29, 2023 · 8 comments
Closed

Badger 2040 display when connecting #30

exussum12 opened this issue Jun 29, 2023 · 8 comments

Comments

@exussum12
Copy link

exussum12 commented Jun 29, 2023

def status_handler(self, mode, status, ip):
print(mode, status, ip)
self.display.set_pen(15)
self.display.clear()
self.display.set_pen(0)
if status:
self.display.text("Connected!", 10, 10, 300, 0.5)
self.display.text(ip, 10, 30, 300, 0.5)
else:
self.display.text("Connecting...", 10, 10, 300, 0.5)
self.update()

The 2040w is hard coded to take over the display when connecting, Could this be an option to light the LED or similar user defined action.

Example use case
Showing latest information from a website could look like

while True:
    display.keepalive()
    variables = get_data()
    draw_page(variables)
    sleep_for(10)

After waking up from sleep, the wifi needs to be connected again, taking ~10 seconds, so every 10 minutes, for 10 seconds the badge doesnt display the intended content. A user defined option could be doing an update partial to the screen or lighting the LED.

@exussum12
Copy link
Author

https://github.com/pimoroni/badger2040/blob/main/badger_os/examples/news.py#L179

The example news app could (probably) take advantage of sleep if this was implemented

@salimhb
Copy link

salimhb commented Jun 29, 2023

I have a similar use case. I'm using wifimgr.py and modified it to work on badger. My approach Is to render the text in the top of the screen and then call display.partial_update(0, 0, WIDTH, 24).

I also use the LED as an indicator of activity:

while True:
    display.keepalive()
    display.led(128) # brighter LED
    render() # this does the data fetching and drawing
    display.led(6) # dimmed LED (on USB)
    badger2040.sleep_for(10) # on battery the LED goes completely off during sleep

@Gadgetoid
Copy link
Member

That status handler code is quite bad on two accounts- the print() is not always desirable either.

Normally this is solved by passing in a custom handler when constructing NetworkManager, but this choice has been lost via the badger lib. I'll raise a PR to fix it.

@exussum12
Copy link
Author

Perfect, I have done something similar to @salimhb for now (though still using the config file rather than adding wifi creds in again.

Would be happy to test anything!

@Gadgetoid
Copy link
Member

Okay, test build here - https://github.com/pimoroni/badger2040/actions/runs/5421334513

Now you can use:

display.connect(status_handler=None)

Or define your own status handler in user code:

def status_handler(mode, status, ip):
        print(mode, status, ip)

display.connect(status_handler=status_handler)

@salimhb
Copy link

salimhb commented Jun 30, 2023

Thanks @Gadgetoid, looks like a good solution 👍

@exussum12
Copy link
Author

Yeah works well for me, I have added a comment on the PR though as the method still causes unexpected behaviour.

Thanks for the super quick fix!

Gadgetoid added a commit that referenced this issue Jul 19, 2023
Badger 2040W: Custom WiFi status handler for #30
@exussum12
Copy link
Author

This was resolved by the PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants