Skip to content
Snippets Groups Projects
Commit ad00890d authored by q3k's avatar q3k
Browse files

python: fully migrate over to ctx

This removes some leftover Python code that still used the old display_*
calls for drawing instead of ctx.

We are now left only with display_update, which we will replace by the
new graphics stack soon.
parent c6060a15
No related branches found
No related tags found
No related merge requests found
...@@ -4,11 +4,13 @@ import cmath ...@@ -4,11 +4,13 @@ import cmath
import math import math
import time import time
ctx = hardware.get_ctx()
def init(): def init():
pass pass
def run(): def run():
hardware.display_fill(0) ctx.rgb(0, 0, 0).rectangle(-120, -120, 240, 240).fill()
time.sleep_ms(30) time.sleep_ms(30)
for i in range(10): for i in range(10):
size = (hardware.get_captouch(i) * 4) + 4 size = (hardware.get_captouch(i) * 4) + 4
...@@ -17,10 +19,10 @@ def run(): ...@@ -17,10 +19,10 @@ def run():
x += (hardware.captouch_get_petal_phi(i)/600)*1j x += (hardware.captouch_get_petal_phi(i)/600)*1j
rot = cmath.exp(2j * math.pi * i / 10) rot = cmath.exp(2j * math.pi * i / 10)
x = x * rot x = x * rot
col = 0b1111100000011111 col = (1.0, 0.0, 1.0)
if i%2: if i%2:
col = 0b0000011111111111 col = (0.0, 1.0, 1.0)
utils.draw_rect(int(x.imag+120-(size/2)),int(x.real+120-(size/2)),size,size,col) ctx.rgb(*col).rectangle(-int(x.imag-(size/2)), -int(x.real-(size/2)), size, size).fill()
hardware.display_update() hardware.display_update()
def foreground(): def foreground():
......
...@@ -10,17 +10,6 @@ def clear_all_leds(): ...@@ -10,17 +10,6 @@ def clear_all_leds():
set_led_rgb(i, 0, 0, 0) set_led_rgb(i, 0, 0, 0)
update_leds() update_leds()
def draw_text_big(text, x, y):
ypos = 120+int(len(text)) + int(y)
xpos = 120+int(len(text[0])) + int(x)
for l, line in enumerate(text):
for p, pixel in enumerate(line):
if(pixel == '#'):
display_draw_pixel(xpos - 2*p, ypos - 2*l, RED)
display_draw_pixel(xpos - 2*p, ypos - 2*l-1, BLUE)
display_draw_pixel(xpos - 2*p-1, ypos - 2*l, BLUE)
display_draw_pixel(xpos - 2*p-1, ypos - 2*l-1, RED)
def highlight_bottom_petal(num, RED, GREEN, BLUE): def highlight_bottom_petal(num, RED, GREEN, BLUE):
start = 4 + 8*num start = 4 + 8*num
for i in range(7): for i in range(7):
...@@ -34,11 +23,6 @@ def long_bottom_petal_captouch_blocking(num, ms): ...@@ -34,11 +23,6 @@ def long_bottom_petal_captouch_blocking(num, ms):
return True return True
return False return False
def draw_rect(x,y,w,h,col):
for j in range(w):
for k in range(h):
display_draw_pixel(x+j,y+k,col)
def draw_volume_slider(ctx, volume): def draw_volume_slider(ctx, volume):
length = 96 + ((volume - 20) * 1.6) length = 96 + ((volume - 20) * 1.6)
if length > 96: if length > 96:
......
...@@ -285,16 +285,6 @@ class Simulation: ...@@ -285,16 +285,6 @@ class Simulation:
_sim = Simulation() _sim = Simulation()
_deprecated_notified = set()
def _deprecated(f):
def wrapper(*args, **kwargs):
if f not in _deprecated_notified:
print(f'{f.__name__} is deprecated!')
_deprecated_notified.add(f)
return f(*args, **kwargs)
return wrapper
def init_done(): def init_done():
return True return True
...@@ -317,19 +307,6 @@ def get_ctx(): ...@@ -317,19 +307,6 @@ def get_ctx():
return _global_ctx return _global_ctx
@_deprecated
def display_fill(color):
"""
display_fill is deprecated as it doesn't work well with ctx's framebuffer
ownership / state diffing. Instead, callers should use plain ctx functions
to fill the screen.
"""
r = (color >> 11) & 0b11111
g = (color >> 5 ) & 0b111111
b = color & 0b11111
get_ctx().rgb(r << 2, g << 3, b <<2).rectangle(-120, -120, 240, 240).fill()
def display_update(): def display_update():
_sim.process_events() _sim.process_events()
_sim.render_display() _sim.render_display()
......
...@@ -37,29 +37,6 @@ STATIC mp_obj_t mp_display_update(void) { ...@@ -37,29 +37,6 @@ STATIC mp_obj_t mp_display_update(void) {
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_display_update_obj, mp_display_update); STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_display_update_obj, mp_display_update);
STATIC mp_obj_t mp_display_draw_pixel(size_t n_args, const mp_obj_t *args) {
uint16_t x = mp_obj_get_int(args[0]);
uint16_t y = mp_obj_get_int(args[1]);
uint16_t col = mp_obj_get_int(args[2]);
display_draw_pixel(x, y, col);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_display_draw_pixel_obj, 3, 4, mp_display_draw_pixel);
STATIC mp_obj_t mp_display_get_pixel(size_t n_args, const mp_obj_t *args) {
uint16_t x = mp_obj_get_int(args[0]);
uint16_t y = mp_obj_get_int(args[1]);
return mp_obj_new_int(display_get_pixel(x, y));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_display_get_pixel_obj, 2, 3, mp_display_get_pixel);
STATIC mp_obj_t mp_display_fill(size_t n_args, const mp_obj_t *args) {
uint16_t col = mp_obj_get_int(args[0]);
display_fill(col);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_display_fill_obj, 1, 2, mp_display_fill);
STATIC mp_obj_t mp_get_captouch(size_t n_args, const mp_obj_t *args) { STATIC mp_obj_t mp_get_captouch(size_t n_args, const mp_obj_t *args) {
uint16_t captouch = read_captouch(); uint16_t captouch = read_captouch();
uint16_t pad = mp_obj_get_int(args[0]); uint16_t pad = mp_obj_get_int(args[0]);
...@@ -199,13 +176,6 @@ STATIC mp_obj_t mp_get_ctx(size_t n_args, const mp_obj_t *args) { ...@@ -199,13 +176,6 @@ STATIC mp_obj_t mp_get_ctx(size_t n_args, const mp_obj_t *args) {
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_get_ctx_obj, 0, 0, mp_get_ctx); STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_get_ctx_obj, 0, 0, mp_get_ctx);
STATIC mp_obj_t mp_reset_ctx(size_t n_args, const mp_obj_t *args) {
display_ctx_init();
mp_ctx = mp_ctx_from_ctx(the_ctx);
return mp_ctx;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_reset_ctx_obj, 0, 0, mp_reset_ctx);
STATIC const mp_rom_map_elem_t mp_module_hardware_globals_table[] = { STATIC const mp_rom_map_elem_t mp_module_hardware_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_badge_audio) }, { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_badge_audio) },
{ MP_ROM_QSTR(MP_QSTR_init_done), MP_ROM_PTR(&mp_init_done_obj) }, { MP_ROM_QSTR(MP_QSTR_init_done), MP_ROM_PTR(&mp_init_done_obj) },
...@@ -226,12 +196,8 @@ STATIC const mp_rom_map_elem_t mp_module_hardware_globals_table[] = { ...@@ -226,12 +196,8 @@ STATIC const mp_rom_map_elem_t mp_module_hardware_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_set_led_hsv), MP_ROM_PTR(&mp_set_led_hsv_obj) }, { MP_ROM_QSTR(MP_QSTR_set_led_hsv), MP_ROM_PTR(&mp_set_led_hsv_obj) },
{ MP_ROM_QSTR(MP_QSTR_update_leds), MP_ROM_PTR(&mp_update_leds_obj) }, { MP_ROM_QSTR(MP_QSTR_update_leds), MP_ROM_PTR(&mp_update_leds_obj) },
{ MP_ROM_QSTR(MP_QSTR_display_update), MP_ROM_PTR(&mp_display_update_obj) }, { MP_ROM_QSTR(MP_QSTR_display_update), MP_ROM_PTR(&mp_display_update_obj) },
{ MP_ROM_QSTR(MP_QSTR_display_draw_pixel), MP_ROM_PTR(&mp_display_draw_pixel_obj) },
{ MP_ROM_QSTR(MP_QSTR_display_get_pixel), MP_ROM_PTR(&mp_display_get_pixel_obj) },
{ MP_ROM_QSTR(MP_QSTR_display_fill), MP_ROM_PTR(&mp_display_fill_obj) },
{ MP_ROM_QSTR(MP_QSTR_version), MP_ROM_PTR(&mp_version_obj) }, { MP_ROM_QSTR(MP_QSTR_version), MP_ROM_PTR(&mp_version_obj) },
{ MP_ROM_QSTR(MP_QSTR_get_ctx), MP_ROM_PTR(&mp_get_ctx_obj) }, { MP_ROM_QSTR(MP_QSTR_get_ctx), MP_ROM_PTR(&mp_get_ctx_obj) },
{ MP_ROM_QSTR(MP_QSTR_reset_ctx), MP_ROM_PTR(&mp_reset_ctx_obj) },
}; };
STATIC MP_DEFINE_CONST_DICT(mp_module_hardware_globals, mp_module_hardware_globals_table); STATIC MP_DEFINE_CONST_DICT(mp_module_hardware_globals, mp_module_hardware_globals_table);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment