Galactic Unicorn: More MicroPython bringup.
This commit is contained in:
parent
a25699c73d
commit
7fd175abc5
|
@ -0,0 +1,50 @@
|
|||
import time
|
||||
from galactic import GalacticUnicorn
|
||||
|
||||
gu = GalacticUnicorn()
|
||||
|
||||
def gradient(r, g, b):
|
||||
for y in range(0, 11):
|
||||
for x in range(0, 53):
|
||||
# graphics.set_pen((r * x) / 52, (g * x) / 52, (b * x) / 52);
|
||||
gu.set_pixel(x, y, x)
|
||||
|
||||
|
||||
def grid(ms, x, y) {
|
||||
v = (x + y + (ms / 1000)) % 2
|
||||
if v == 0:
|
||||
gu.set_pixel(x, y, 255)
|
||||
else:
|
||||
gu.set_pixel(x, y, 0)
|
||||
}
|
||||
|
||||
void shader_fill(int ms, shader_func_t f) {
|
||||
for(int y = 0; y < 12; y++) {
|
||||
for(int x = 0; x < 53; x++) {
|
||||
f(ms, x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void outline_text(std::string text) {
|
||||
uint ms = to_ms_since_boot(get_absolute_time());
|
||||
|
||||
graphics.set_font("bitmap8");
|
||||
uint8_t v = (sin(ms / 100.0f) + 1.0f) * 127.0f;
|
||||
uint w = graphics.measure_text(text, 1);
|
||||
|
||||
int x = 53 / 2 - w / 2 + 1, y = 2;
|
||||
|
||||
graphics.set_pen(0, 0, 0);
|
||||
graphics.text(text, Point(x - 1, y - 1), -1, 1);
|
||||
graphics.text(text, Point(x , y - 1), -1, 1);
|
||||
graphics.text(text, Point(x + 1, y - 1), -1, 1);
|
||||
graphics.text(text, Point(x - 1, y ), -1, 1);
|
||||
graphics.text(text, Point(x + 1, y ), -1, 1);
|
||||
graphics.text(text, Point(x - 1, y + 1), -1, 1);
|
||||
graphics.text(text, Point(x , y + 1), -1, 1);
|
||||
graphics.text(text, Point(x + 1, y + 1), -1, 1);
|
||||
|
||||
graphics.set_pen(v, v, v);
|
||||
graphics.text(text, Point(x, y), -1, 1);
|
||||
}
|
|
@ -0,0 +1,134 @@
|
|||
import time
|
||||
import random
|
||||
from picographics import PicoGraphics, DISPLAY_GALACTIC_UNICORN
|
||||
from galactic import GalacticUnicorn
|
||||
from ulab import numpy as np
|
||||
|
||||
graphics = PicoGraphics(DISPLAY_GALACTIC_UNICORN)
|
||||
gu = GalacticUnicorn()
|
||||
|
||||
width = 53
|
||||
height = 15
|
||||
|
||||
heat = [0.0] * 1000
|
||||
#heat = np.full((width + 5, height + 5), 0.0)
|
||||
|
||||
@micropython.native
|
||||
def set(x, y, v):
|
||||
global heat
|
||||
heat[x + y * width] = v
|
||||
#heat[x, y] = v
|
||||
|
||||
@micropython.native
|
||||
def get(x, y):
|
||||
global heat
|
||||
x = x if x >= 0 else 0
|
||||
x = x if x < width else width - 1
|
||||
#try:
|
||||
#return heat[x, y]
|
||||
return heat[x + y * width]
|
||||
#except IndexError:
|
||||
# pass
|
||||
|
||||
@micropython.native
|
||||
def select_colour(x, y):
|
||||
#value = heat[x, y]
|
||||
value = heat[x + y * width]
|
||||
if value > 0.5:
|
||||
return 255, 255, 180
|
||||
elif value > 0.4:
|
||||
return 220, 160, 0
|
||||
elif value > 0.3:
|
||||
return 180, 30, 0
|
||||
elif value > 0.22:
|
||||
return 20, 20, 20
|
||||
else:
|
||||
return 0, 0, 0
|
||||
|
||||
|
||||
@micropython.native
|
||||
def calc_average(x, y):
|
||||
#if x > 0:
|
||||
# return (heat[x, y] + heat[x, y + 2] + heat[x, y + 1] + heat[x - 1, y + 1] + heat[x + 1, y + 1]) / 5.0
|
||||
return (heat[x + (y * width)] + heat[x + ((y + 2) * width)] + heat[x + ((y + 1) * width)] + heat[(x - 1 if x >= 0 else 0) + ((y + 1) * width)] + heat[(x + 1) + ((y + 1) * width)]) / 5.0
|
||||
#else:
|
||||
#return (heat[x, y] + heat[x, y + 2] + heat[x, y + 1] + heat[x - 0, y + 1] + heat[x + 1, y + 1]) / 5.0
|
||||
#return (heat[x + (y * width)] + heat[x + ((y + 2) * width)] + heat[x + ((y + 1) * width)] + heat[(x) + ((y + 1) * width)] + heat[(x + 1) + ((y + 1) * width)]) / 5.0
|
||||
|
||||
|
||||
gu.set_brightness(0.3)
|
||||
|
||||
# heat[x-1:x+2, y:y+3]
|
||||
#weights = np.array([[0.0, 0.0, 0.0],
|
||||
#[0.0, 0.0, 0.0],
|
||||
#[0.0, 0.0, 0.0]])
|
||||
|
||||
landscape = True
|
||||
|
||||
while True:
|
||||
start = time.ticks_ms()
|
||||
if gu.is_pressed(21):
|
||||
gu.adjust_brightness(+0.01)
|
||||
if gu.is_pressed(26):
|
||||
gu.adjust_brightness(-0.01)
|
||||
|
||||
if gu.is_pressed(0):
|
||||
landscape = True
|
||||
width = 53
|
||||
height = 15
|
||||
for i in range(0, len(heat)):
|
||||
heat[i] = 0.0
|
||||
|
||||
if gu.is_pressed(1):
|
||||
landscape = False
|
||||
width = 11
|
||||
height = 55
|
||||
for i in range(0, len(heat)):
|
||||
heat[i] = 0.0
|
||||
|
||||
#for y, row in enumerate(heat):
|
||||
#for x, val in enumerate(row):
|
||||
# print(x, y, row, val)
|
||||
|
||||
for y in range(0, height):
|
||||
for x in range(0, width):
|
||||
r, g, b = select_colour(x, y)
|
||||
|
||||
if landscape:
|
||||
gu.set_pixel(x, y, r, g, b)
|
||||
#graphics.pixel(x, y)
|
||||
else:
|
||||
gu.set_pixel(y, x, r, g, b)
|
||||
#graphics.pixel(y, x)
|
||||
|
||||
# update this pixel by averaging the below pixels
|
||||
#average = (get(x, y) + get(x, y + 2) + get(x, y + 1) + get(x - 1, y + 1) + get(x + 1, y + 1)) / 5.0
|
||||
average = calc_average(x, y)
|
||||
|
||||
# damping factor to ensure flame tapers out towards the top of the displays
|
||||
average *= 0.95 if landscape else 0.99
|
||||
|
||||
# update the heat map with our newly averaged value
|
||||
set(x, y, average)
|
||||
|
||||
#gu.update(graphics)
|
||||
|
||||
# clear the bottom row and then add a new fire seed to it
|
||||
for x in range(0, width):
|
||||
set(x, height - 1, 0.0)
|
||||
|
||||
# add a new random heat source
|
||||
source_count = 5 if landscape else 1
|
||||
|
||||
for c in range(0, source_count):
|
||||
px = random.randint(0, width - 4) + 2
|
||||
set(px , height - 2, 1.0)
|
||||
set(px + 1, height - 2, 1.0)
|
||||
set(px - 1, height - 2, 1.0)
|
||||
set(px , height - 1, 1.0)
|
||||
set(px + 1, height - 1, 1.0)
|
||||
set(px - 1, height - 1, 1.0)
|
||||
|
||||
end = time.ticks_ms()
|
||||
print("Time:", end - start)
|
||||
#time.sleep(0.02)
|
|
@ -3,23 +3,23 @@
|
|||
|
||||
/***** Methods *****/
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(GalacticUnicorn___del___obj, GalacticUnicorn___del__);
|
||||
/*MP_DEFINE_CONST_FUN_OBJ_1(GalacticUnicorn_clear_obj, GalacticUnicorn_clear);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(GalacticUnicorn_update_obj, 1, GalacticUnicorn_update);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(GalacticUnicorn_clear_obj, GalacticUnicorn_clear);
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(GalacticUnicorn_update_obj, GalacticUnicorn_update);
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(GalacticUnicorn_set_brightness_obj, GalacticUnicorn_set_brightness);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(GalacticUnicorn_get_brightness_obj, GalacticUnicorn_get_brightness);
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(GalacticUnicorn_adjust_brightness_obj, GalacticUnicorn_adjust_brightness);
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(GalacticUnicorn_set_volume_obj, GalacticUnicorn_set_volume);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(GalacticUnicorn_get_volume_obj, GalacticUnicorn_get_volume);
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(GalacticUnicorn_adjust_volume_obj, GalacticUnicorn_adjust_volume);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(GalacticUnicorn_set_pixel_obj, 1, GalacticUnicorn_set_pixel);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(GalacticUnicorn_set_pixel_obj, 4, GalacticUnicorn_set_pixel);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(GalacticUnicorn_light_obj, GalacticUnicorn_light);
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(GalacticUnicorn_is_pressed_obj, GalacticUnicorn_is_pressed);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(GalacticUnicorn_play_sample_obj, 1, GalacticUnicorn_play_sample);*/
|
||||
//MP_DEFINE_CONST_FUN_OBJ_KW(GalacticUnicorn_play_sample_obj, 1, GalacticUnicorn_play_sample);
|
||||
|
||||
/***** Binding of Methods *****/
|
||||
STATIC const mp_rom_map_elem_t GalacticUnicorn_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&GalacticUnicorn___del___obj) },
|
||||
/*{ MP_ROM_QSTR(MP_QSTR_clear), MP_ROM_PTR(&GalacticUnicorn_clear_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_clear), MP_ROM_PTR(&GalacticUnicorn_clear_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&GalacticUnicorn_update_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_set_brightness), MP_ROM_PTR(&GalacticUnicorn_set_brightness_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_get_brightness), MP_ROM_PTR(&GalacticUnicorn_get_brightness_obj) },
|
||||
|
@ -30,7 +30,7 @@ STATIC const mp_rom_map_elem_t GalacticUnicorn_locals_dict_table[] = {
|
|||
{ MP_ROM_QSTR(MP_QSTR_set_pixel), MP_ROM_PTR(&GalacticUnicorn_set_pixel_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_light), MP_ROM_PTR(&GalacticUnicorn_light_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_is_pressed), MP_ROM_PTR(&GalacticUnicorn_is_pressed_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_play_sample), MP_ROM_PTR(&GalacticUnicorn_play_sample_obj) },*/
|
||||
//{ MP_ROM_QSTR(MP_QSTR_play_sample), MP_ROM_PTR(&GalacticUnicorn_play_sample_obj) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_WIDTH), MP_ROM_INT(53) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_HEIGHT), MP_ROM_INT(11) },
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "libraries/galactic_unicorn/galactic_unicorn.hpp"
|
||||
#include "libraries/pico_graphics/pico_graphics.hpp"
|
||||
#include "micropython/modules/util.hpp"
|
||||
#include <cstdio>
|
||||
#include <cfloat>
|
||||
|
@ -17,8 +18,15 @@ extern "C" {
|
|||
typedef struct _GalacticUnicorn_obj_t {
|
||||
mp_obj_base_t base;
|
||||
GalacticUnicorn* galactic;
|
||||
//PicoGraphics_PenRGB888* graphics;
|
||||
} _GalacticUnicorn_obj_t;
|
||||
|
||||
typedef struct _ModPicoGraphics_obj_t {
|
||||
mp_obj_base_t base;
|
||||
PicoGraphics *graphics;
|
||||
DisplayDriver *display;
|
||||
void *buffer;
|
||||
} ModPicoGraphics_obj_t;
|
||||
|
||||
/***** Print *****/
|
||||
void GalacticUnicorn_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
|
@ -60,10 +68,22 @@ mp_obj_t GalacticUnicorn_make_new(const mp_obj_type_t *type, size_t n_args, size
|
|||
//m_del_class(GalacticUnicorn, galactic);
|
||||
//mp_raise_msg(&mp_type_RuntimeError, "unable to allocate the hardware resources needed to initialise this GalacticUnicorn. Try running `import gc` followed by `gc.collect()` before creating it");
|
||||
//}
|
||||
//PicoGraphics_PenRGB888 *graphics = m_new_class(PicoGraphics_PenRGB888, 53, 11, m_new(uint8_t, PicoGraphics_PenRGB888::buffer_size(53, 11)));
|
||||
|
||||
/*for(int y = 0; y < 11; y++) {
|
||||
for(int x = 0; x < 53; x++) {
|
||||
// graphics.set_pen((r * x) / 52, (g * x) / 52, (b * x) / 52);
|
||||
graphics->set_pen(x, x, x);
|
||||
graphics->pixel(Point(x, y));
|
||||
}
|
||||
}*/
|
||||
|
||||
//galactic->update(*graphics);
|
||||
|
||||
self = m_new_obj_with_finaliser(_GalacticUnicorn_obj_t);
|
||||
self->base.type = &GalacticUnicorn_type;
|
||||
self->galactic = galactic;
|
||||
//self->graphics = graphics;
|
||||
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
@ -73,54 +93,110 @@ mp_obj_t GalacticUnicorn_make_new(const mp_obj_type_t *type, size_t n_args, size
|
|||
mp_obj_t GalacticUnicorn___del__(mp_obj_t self_in) {
|
||||
_GalacticUnicorn_obj_t *self = MP_OBJ_TO_PTR2(self_in, _GalacticUnicorn_obj_t);
|
||||
m_del_class(GalacticUnicorn, self->galactic);
|
||||
//m_del_class(PicoGraphics_PenRGB888, self->graphics);
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
|
||||
/***** Methods *****/
|
||||
extern mp_obj_t GalacticUnicorn_clear(mp_obj_t self_in) {
|
||||
//_GalacticUnicorn_obj_t *self = MP_OBJ_TO_PTR2(self_in, _GalacticUnicorn_obj_t);
|
||||
//self->galactic->clear();
|
||||
_GalacticUnicorn_obj_t *self = MP_OBJ_TO_PTR2(self_in, _GalacticUnicorn_obj_t);
|
||||
self->galactic->clear();
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
extern mp_obj_t GalacticUnicorn_update(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
//_GalacticUnicorn_obj_t *self = MP_OBJ_TO_PTR2(self_in, _GalacticUnicorn_obj_t);
|
||||
extern mp_obj_t GalacticUnicorn_update(mp_obj_t self_in, mp_obj_t graphics_in) {
|
||||
_GalacticUnicorn_obj_t *self = MP_OBJ_TO_PTR2(self_in, _GalacticUnicorn_obj_t);
|
||||
ModPicoGraphics_obj_t *picographics = MP_OBJ_TO_PTR2(self_in, ModPicoGraphics_obj_t);
|
||||
|
||||
self->galactic->update(*((PicoGraphics_PenRGB888 *)picographics->graphics));
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
extern mp_obj_t GalacticUnicorn_set_brightness(mp_obj_t self_in, mp_obj_t value) {
|
||||
//_GalacticUnicorn_obj_t *self = MP_OBJ_TO_PTR2(self_in, _GalacticUnicorn_obj_t);
|
||||
_GalacticUnicorn_obj_t *self = MP_OBJ_TO_PTR2(self_in, _GalacticUnicorn_obj_t);
|
||||
self->galactic->set_brightness(mp_obj_get_float(value));
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
extern mp_obj_t GalacticUnicorn_get_brightness(mp_obj_t self_in) {
|
||||
//_GalacticUnicorn_obj_t *self = MP_OBJ_TO_PTR2(self_in, _GalacticUnicorn_obj_t);
|
||||
return mp_const_none;
|
||||
_GalacticUnicorn_obj_t *self = MP_OBJ_TO_PTR2(self_in, _GalacticUnicorn_obj_t);
|
||||
return mp_obj_new_float(self->galactic->get_brightness());
|
||||
}
|
||||
|
||||
extern mp_obj_t GalacticUnicorn_adjust_brightness(mp_obj_t self_in, mp_obj_t delta) {
|
||||
//_GalacticUnicorn_obj_t *self = MP_OBJ_TO_PTR2(self_in, _GalacticUnicorn_obj_t);
|
||||
_GalacticUnicorn_obj_t *self = MP_OBJ_TO_PTR2(self_in, _GalacticUnicorn_obj_t);
|
||||
self->galactic->adjust_brightness(mp_obj_get_float(delta));
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
extern mp_obj_t GalacticUnicorn_set_volume(mp_obj_t self_in, mp_obj_t value) {
|
||||
//_GalacticUnicorn_obj_t *self = MP_OBJ_TO_PTR2(self_in, _GalacticUnicorn_obj_t);
|
||||
_GalacticUnicorn_obj_t *self = MP_OBJ_TO_PTR2(self_in, _GalacticUnicorn_obj_t);
|
||||
self->galactic->set_volume(mp_obj_get_float(value));
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
extern mp_obj_t GalacticUnicorn_get_volume(mp_obj_t self_in) {
|
||||
//_GalacticUnicorn_obj_t *self = MP_OBJ_TO_PTR2(self_in, _GalacticUnicorn_obj_t);
|
||||
return mp_const_none;
|
||||
_GalacticUnicorn_obj_t *self = MP_OBJ_TO_PTR2(self_in, _GalacticUnicorn_obj_t);
|
||||
return mp_obj_new_float(self->galactic->get_volume());
|
||||
}
|
||||
|
||||
extern mp_obj_t GalacticUnicorn_adjust_volume(mp_obj_t self_in, mp_obj_t delta) {
|
||||
//_GalacticUnicorn_obj_t *self = MP_OBJ_TO_PTR2(self_in, _GalacticUnicorn_obj_t);
|
||||
_GalacticUnicorn_obj_t *self = MP_OBJ_TO_PTR2(self_in, _GalacticUnicorn_obj_t);
|
||||
self->galactic->adjust_volume(mp_obj_get_float(delta));
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
extern mp_obj_t GalacticUnicorn_set_pixel(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
//_GalacticUnicorn_obj_t *self = MP_OBJ_TO_PTR2(self_in, _GalacticUnicorn_obj_t);
|
||||
if(n_args <= 4) {
|
||||
enum { ARG_self, ARG_x, ARG_y, ARG_v };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
{ MP_QSTR_x, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_y, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_v, MP_ARG_REQUIRED | MP_ARG_INT }
|
||||
};
|
||||
|
||||
// Parse args.
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
int x = args[ARG_x].u_int;
|
||||
int y = args[ARG_y].u_int;
|
||||
int v = args[ARG_v].u_int;
|
||||
|
||||
_GalacticUnicorn_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _GalacticUnicorn_obj_t);
|
||||
//self->graphics->set_pen(v, v, v);
|
||||
//self->graphics->set_pixel(Point(x, y));
|
||||
self->galactic->set_pixel(x, y, v);
|
||||
}
|
||||
else {
|
||||
enum { ARG_self, ARG_x, ARG_y, ARG_r, ARG_g, ARG_b };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
{ MP_QSTR_x, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_y, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_r, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_g, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ MP_QSTR_b, MP_ARG_REQUIRED | MP_ARG_INT }
|
||||
};
|
||||
|
||||
// Parse args.
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
int x = args[ARG_x].u_int;
|
||||
int y = args[ARG_y].u_int;
|
||||
int r = args[ARG_r].u_int;
|
||||
int g = args[ARG_g].u_int;
|
||||
int b = args[ARG_b].u_int;
|
||||
|
||||
_GalacticUnicorn_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, _GalacticUnicorn_obj_t);
|
||||
//self->graphics->set_pen(r, g, b);
|
||||
//self->graphics->set_pixel(Point(x, y));
|
||||
self->galactic->set_pixel(x, y, r, g, b);
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
|
@ -130,8 +206,8 @@ extern mp_obj_t GalacticUnicorn_light(mp_obj_t self_in) {
|
|||
}
|
||||
|
||||
extern mp_obj_t GalacticUnicorn_is_pressed(mp_obj_t self_in, mp_obj_t button) {
|
||||
//_GalacticUnicorn_obj_t *self = MP_OBJ_TO_PTR2(self_in, _GalacticUnicorn_obj_t);
|
||||
return mp_const_none;
|
||||
_GalacticUnicorn_obj_t *self = MP_OBJ_TO_PTR2(self_in, _GalacticUnicorn_obj_t);
|
||||
return mp_obj_new_bool(self->galactic->is_pressed((uint8_t)mp_obj_get_int(button)));
|
||||
}
|
||||
|
||||
extern mp_obj_t GalacticUnicorn_play_sample(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
|
|
|
@ -10,8 +10,7 @@ extern mp_obj_t GalacticUnicorn_make_new(const mp_obj_type_t *type, size_t n_arg
|
|||
extern mp_obj_t GalacticUnicorn___del__(mp_obj_t self_in);
|
||||
extern mp_obj_t GalacticUnicorn_clear(mp_obj_t self_in);
|
||||
|
||||
extern mp_obj_t GalacticUnicorn_update(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
|
||||
//extern mp_obj_t GalacticUnicorn_update(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
|
||||
extern mp_obj_t GalacticUnicorn_update(mp_obj_t self_in, mp_obj_t graphics_in);
|
||||
|
||||
extern mp_obj_t GalacticUnicorn_set_brightness(mp_obj_t self_in, mp_obj_t value);
|
||||
extern mp_obj_t GalacticUnicorn_get_brightness(mp_obj_t self_in);
|
||||
|
|
|
@ -6,6 +6,7 @@ target_sources(usermod_${MOD_NAME} INTERFACE
|
|||
${CMAKE_CURRENT_LIST_DIR}/${MOD_NAME}.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/${MOD_NAME}.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/../../../libraries/galactic_unicorn/galactic_unicorn.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/../../../libraries/pico_graphics/pico_graphics_pen_rgb888.cpp
|
||||
)
|
||||
pico_generate_pio_header(usermod_${MOD_NAME} ${CMAKE_CURRENT_LIST_DIR}/../../../libraries/galactic_unicorn/galactic_unicorn.pio)
|
||||
pico_generate_pio_header(usermod_${MOD_NAME} ${CMAKE_CURRENT_LIST_DIR}/../../../libraries/galactic_unicorn/audio_i2s.pio)
|
||||
|
@ -16,7 +17,7 @@ target_include_directories(usermod_${MOD_NAME} INTERFACE
|
|||
)
|
||||
|
||||
target_compile_definitions(usermod_${MOD_NAME} INTERFACE
|
||||
MODULE_GALATIC_ENABLED=1
|
||||
MODULE_GALACTIC_ENABLED=1
|
||||
)
|
||||
|
||||
target_link_libraries(usermod INTERFACE usermod_${MOD_NAME})
|
|
@ -125,12 +125,14 @@ STATIC const mp_map_elem_t picographics_globals_table[] = {
|
|||
{ MP_ROM_QSTR(MP_QSTR_DISPLAY_INKY_PACK), MP_ROM_INT(DISPLAY_INKY_PACK) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_DISPLAY_INKY_FRAME), MP_ROM_INT(DISPLAY_INKY_FRAME) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_DISPLAY_INKY_FRAME_4), MP_ROM_INT(DISPLAY_INKY_FRAME_4) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_DISPLAY_GALACTIC_UNICORN), MP_ROM_INT(DISPLAY_GALACTIC_UNICORN) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_PEN_1BIT), MP_ROM_INT(PEN_1BIT) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_PEN_P4), MP_ROM_INT(PEN_P4) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_PEN_P8), MP_ROM_INT(PEN_P8) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_PEN_RGB332), MP_ROM_INT(PEN_RGB332) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_PEN_RGB565), MP_ROM_INT(PEN_RGB565) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_PEN_RGB888), MP_ROM_INT(PEN_RGB888) },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(mp_module_picographics_globals, picographics_globals_table);
|
||||
|
||||
|
|
|
@ -112,6 +112,14 @@ bool get_display_settings(PicoGraphicsDisplay display, int &width, int &height,
|
|||
if(rotate == -1) rotate = (int)Rotation::ROTATE_0;
|
||||
if(pen_type == -1) pen_type = PEN_P4;
|
||||
break;
|
||||
case DISPLAY_GALACTIC_UNICORN:
|
||||
width = 53;
|
||||
height = 11;
|
||||
bus_type = BUS_PIO;
|
||||
// Portrait to match labelling
|
||||
if(rotate == -1) rotate = (int)Rotation::ROTATE_0;
|
||||
if(pen_type == -1) pen_type = PEN_RGB888;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
@ -132,6 +140,8 @@ size_t get_required_buffer_size(PicoGraphicsPenType pen_type, uint width, uint h
|
|||
return PicoGraphics_PenRGB332::buffer_size(width, height);
|
||||
case PEN_RGB565:
|
||||
return PicoGraphics_PenRGB565::buffer_size(width, height);
|
||||
case PEN_RGB888:
|
||||
return PicoGraphics_PenRGB888::buffer_size(width, height);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
@ -223,7 +233,10 @@ mp_obj_t ModPicoGraphics_make_new(const mp_obj_type_t *type, size_t n_args, size
|
|||
} else if (display == DISPLAY_INKY_PACK) {
|
||||
self->display = m_new_class(UC8151, width, height, (Rotation)rotate, spi_bus);
|
||||
|
||||
} else {
|
||||
} else if (display == DISPLAY_GALACTIC_UNICORN) {
|
||||
self->display = m_new_class(DisplayDriver, width, height, (Rotation)rotate);
|
||||
}
|
||||
else {
|
||||
self->display = m_new_class(ST7789, width, height, (Rotation)rotate, round, spi_bus);
|
||||
}
|
||||
|
||||
|
@ -267,6 +280,9 @@ mp_obj_t ModPicoGraphics_make_new(const mp_obj_type_t *type, size_t n_args, size
|
|||
case PEN_RGB565:
|
||||
self->graphics = m_new_class(PicoGraphics_PenRGB565, self->display->width, self->display->height, self->buffer);
|
||||
break;
|
||||
case PEN_RGB888:
|
||||
self->graphics = m_new_class(PicoGraphics_PenRGB888, self->display->width, self->display->height, self->buffer);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -13,7 +13,8 @@ enum PicoGraphicsDisplay {
|
|||
DISPLAY_I2C_OLED_128X128,
|
||||
DISPLAY_INKY_PACK,
|
||||
DISPLAY_INKY_FRAME,
|
||||
DISPLAY_INKY_FRAME_4
|
||||
DISPLAY_INKY_FRAME_4,
|
||||
DISPLAY_GALACTIC_UNICORN
|
||||
};
|
||||
|
||||
enum PicoGraphicsPenType {
|
||||
|
@ -23,13 +24,15 @@ enum PicoGraphicsPenType {
|
|||
PEN_P4,
|
||||
PEN_P8,
|
||||
PEN_RGB332,
|
||||
PEN_RGB565
|
||||
PEN_RGB565,
|
||||
PEN_RGB888
|
||||
};
|
||||
|
||||
enum PicoGraphicsBusType {
|
||||
BUS_I2C,
|
||||
BUS_SPI,
|
||||
BUS_PARALLEL
|
||||
BUS_PARALLEL,
|
||||
BUS_PIO
|
||||
};
|
||||
|
||||
// Type
|
||||
|
|
Loading…
Reference in New Issue