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

MicroPython: Fix macOS bug, _logo for launcher. #30

Merged
merged 1 commit into from
Oct 20, 2021
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
3 changes: 2 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ builtins =
pen,
tick,
init,
reset,
_reset,
_logo,
play,
clip,
blend,
Expand Down
20 changes: 13 additions & 7 deletions micropython/examples/picosystem/launcher.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import os
import math
import time
import gc
backlight(0)

import os # noqa: E402
import math # noqa: E402
import time # noqa: E402
import gc # noqa: E402


last_note = 0
Expand All @@ -11,7 +13,7 @@


notes = [
(None, 100), ("G6", 10), ("E6", 30), ("A6", 10), ("G6", 30), (None, 100), ("B7", 1), ("C7", 1)
(None, 100), ("G6", 10), ("E6", 30), ("A6", 10), ("G6", 30), (None, 50), ("B7", 1), ("C7", 1)
]
intro = Voice()
intro.envelope(attack=50, decay=10, sustain=70, release=2000)
Expand Down Expand Up @@ -76,6 +78,9 @@ def update(tick):
selected %= filecount
target_angle = -get_item_angle(selected)

if tick <= 75:
backlight(tick)


def draw(tick):
global current_angle, intro_melody
Expand All @@ -86,9 +91,10 @@ def draw(tick):

if intro_melody:
pen(15, 15, 15)
_logo()
label = "".join(["", "Pi", "co", "Sys", "tem"][0:min(note_idx, 5)])
label_width = text_width(label)
text(label, int(60 - (label_width / 2)), 60)
text(label, int(60 - (label_width / 2)), 90)
return

pen(10, 10, 10)
Expand Down Expand Up @@ -134,5 +140,5 @@ def draw(tick):
del locals()[k]

gc.collect()
reset()
_reset()
__import__(__launch_file__)
1 change: 1 addition & 0 deletions micropython/modules/picosystem/picosystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const mp_obj_type_t PicosystemVoice_type = {
MP_DEFINE_CONST_FUN_OBJ_0(picosystem_init_obj, picosystem_init);
MP_DEFINE_CONST_FUN_OBJ_0(picosystem_reset_obj, picosystem_reset);
MP_DEFINE_CONST_FUN_OBJ_0(picosystem_tick_obj, picosystem_tick);
MP_DEFINE_CONST_FUN_OBJ_0(picosystem_logo_obj, picosystem_logo);

// stats.cpp

Expand Down
63 changes: 33 additions & 30 deletions micropython/modules/picosystem/picosystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ uint32_t last_ms = time();

uint32_t tick = 0;

static bool done_splash = false;
static bool done_audio_init = false;

mp_obj_t update_callback_obj = mp_const_none;
mp_obj_t draw_callback_obj = mp_const_none;
Expand Down Expand Up @@ -62,6 +62,23 @@ mp_obj_t picosystem_reset() {
return mp_const_none;
}

mp_obj_t picosystem_logo() {
const uint8_t *s = _picosystem_logo;

for(int y = 35; y < 85; y++) {
for(int x = 19; x < 101; x+=8) {
for(int bit = 0; bit < 8; bit++) {
if(*s & (0b10000000 >> bit)) {
pixel(x + bit, y);
}
}
s++;
}
}

return mp_const_none;
}

mp_obj_t picosystem_init() {

MP_STATE_PORT(picosystem_framebuffer) = m_new(color_t, 120 * 120);
Expand All @@ -78,41 +95,27 @@ mp_obj_t picosystem_init() {
_fsin_lut[i] = sin((_PI * 2.0f) * (float(i) / 256.0f));
}

if(!done_splash) { // Squash splash on soft-reset. It's painful!
if(!done_audio_init) {
_start_audio(); // HACK! we really should figure out *what* soft-reset rp2_pio_deinit and machine_pin_deinit is breaking

// Set the LED to green, just for gentle reassurance
led(0, 128, 0);

#ifndef NO_STARTUP_LOGO
// fade in logo by ramping up backlight
pen(0, 0, 0); clear();
pen(15, 15, 15); _logo();
for(int i = 0; i < 75; i++) {
backlight(i);
_wait_vsync();
_flip();
}

sleep(300); // ...and breathe out...

// fade out logo in 16 colour steps
for(int i = 15; i >= 0; i--) {
pen(0, 0, 0); clear();
pen(i, i, i); _logo();
_wait_vsync();
_flip();

sleep(20);
}
#endif
done_splash = true;
led(0, 64, 0);

done_audio_init = true;
}
backlight(75);

sleep(300);
// Keep the screen off...
backlight(0);
// Screen buffer is initialized clear; just flip it.
_flip();
// Wait for the DMA transfer to finish
while (_is_flipping());
// wait for the screen to update
_wait_vsync();
_wait_vsync();

pen(0, 0, 0); clear();
// Turn the screen on
backlight(75);

// call users init() function so they can perform any needed
// setup for world state etc
Expand Down
1 change: 1 addition & 0 deletions micropython/modules/picosystem/picosystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ extern const mp_obj_type_t PicosystemVoice_type;
extern mp_obj_t picosystem_init();
extern mp_obj_t picosystem_tick();
extern mp_obj_t picosystem_reset();
extern mp_obj_t picosystem_logo();

// stats.cpp
extern mp_obj_t picosystem_stats();
Expand Down