From da14ec870fe66bd7cbe8641b62755edd902ba731 Mon Sep 17 00:00:00 2001 From: Mike Bell Date: Wed, 9 Mar 2022 23:24:36 +0000 Subject: [PATCH 1/4] Fix image convert of black and white images --- examples/badger2040/image_converter/convert.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/examples/badger2040/image_converter/convert.py b/examples/badger2040/image_converter/convert.py index c1c7b447..6e793189 100755 --- a/examples/badger2040/image_converter/convert.py +++ b/examples/badger2040/image_converter/convert.py @@ -24,8 +24,11 @@ options = parser.parse_args() 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 From bbb995a062ead436375ec89bc44441a9567b29b8 Mon Sep 17 00:00:00 2001 From: Mike Bell Date: Wed, 9 Mar 2022 23:32:52 +0000 Subject: [PATCH 2/4] Reboot on button press when halted but still have power --- libraries/badger2040/badger2040.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libraries/badger2040/badger2040.cpp b/libraries/badger2040/badger2040.cpp index 252c4342..6edd2ce3 100644 --- a/libraries/badger2040/badger2040.cpp +++ b/libraries/badger2040/badger2040.cpp @@ -2,6 +2,7 @@ #include #include "hardware/pwm.h" +#include "hardware/watchdog.h" #include "badger2040.hpp" @@ -79,8 +80,10 @@ 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 + wait_for_press(); + watchdog_reboot(0, 0, 0); } uint8_t _dither_value(int32_t x, int32_t y, uint8_t p) { From fefa6f8880bfd412fb49701bea113895f83bbc65 Mon Sep 17 00:00:00 2001 From: Mike Bell Date: Wed, 9 Mar 2022 23:47:12 +0000 Subject: [PATCH 3/4] Change internal state of Badger2040 to protected --- libraries/badger2040/badger2040.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/badger2040/badger2040.hpp b/libraries/badger2040/badger2040.hpp index 93a9fabe..c640714c 100644 --- a/libraries/badger2040/badger2040.hpp +++ b/libraries/badger2040/badger2040.hpp @@ -9,7 +9,7 @@ namespace pimoroni { class Badger2040 { - private: + protected: UC8151 uc8151; const hershey_font_t *_font = &futural; uint8_t _pen = 0; @@ -96,4 +96,4 @@ namespace pimoroni { }; -} \ No newline at end of file +} From 6975610fdc1ce5cce20b8b29b33e70a873884380 Mon Sep 17 00:00:00 2001 From: Mike Bell Date: Wed, 9 Mar 2022 23:53:56 +0000 Subject: [PATCH 4/4] Don't use wait_for_press because that waits for the button to be released --- libraries/badger2040/badger2040.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libraries/badger2040/badger2040.cpp b/libraries/badger2040/badger2040.cpp index 6edd2ce3..0b65395b 100644 --- a/libraries/badger2040/badger2040.cpp +++ b/libraries/badger2040/badger2040.cpp @@ -82,7 +82,12 @@ namespace pimoroni { // 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 - wait_for_press(); + // 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); }