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

Make USB powered and battery powered Badger2040 work the same #285

Merged
merged 4 commits into from
Mar 10, 2022
Merged
Show file tree
Hide file tree
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
7 changes: 5 additions & 2 deletions examples/badger2040/image_converter/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@
def convert_image(img):
if options.resize:
img = img.resize((296, 128)) # resize
enhancer = ImageEnhance.Contrast(img)
img = enhancer.enhance(2.0)
try:
enhancer = ImageEnhance.Contrast(img)
img = enhancer.enhance(2.0)
except ValueError:
pass
img = img.convert("1") # convert to black and white
return img

Expand Down
12 changes: 10 additions & 2 deletions libraries/badger2040/badger2040.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <math.h>

#include "hardware/pwm.h"
#include "hardware/watchdog.h"

#include "badger2040.hpp"

Expand Down Expand Up @@ -79,8 +80,15 @@ namespace pimoroni {
void Badger2040::halt() {
gpio_put(ENABLE_3V3, 0);

// don't allow any more code to execute while power rail drops
while(true) {}
// If running on USB we will not actually power down, so emulate the behaviour
// of battery powered badge by listening for a button press and then resetting
// Note: Don't use wait_for_press as that waits for the button to be release and
// we want the reboot to complete before the button is released.
update_button_states();
while(_button_states == 0) {
update_button_states();
}
watchdog_reboot(0, 0, 0);
}

uint8_t _dither_value(int32_t x, int32_t y, uint8_t p) {
Expand Down
4 changes: 2 additions & 2 deletions libraries/badger2040/badger2040.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace pimoroni {

class Badger2040 {
private:
protected:
UC8151 uc8151;
const hershey_font_t *_font = &futural;
uint8_t _pen = 0;
Expand Down Expand Up @@ -96,4 +96,4 @@ namespace pimoroni {

};

}
}