Cleanup of GU and fix for flashes on MP soft reset

pull/537/head
ZodiusInfuser 2022-08-09 20:32:14 +01:00 zatwierdzone przez Phil Howard
rodzic 739ca71f69
commit b2e4e16fab
14 zmienionych plików z 74 dodań i 274 usunięć

Wyświetl plik

@ -32,7 +32,6 @@ int main() {
graphics.set_pen(0, 0, 0);
graphics.clear();
for(int y = 0; y < 12; y++) {
for(int x = 0; x < 53; x++) {
if(heat[x][y] > 0.5f) {
@ -63,7 +62,7 @@ int main() {
}
}
galactic_unicorn.update(graphics);
galactic_unicorn.update(&graphics);
// clear the bottom row and then add a new fire seed to it
for(int x = 0; x < 53; x++) {
@ -80,7 +79,7 @@ int main() {
heat[px + 1][12] = 1.0f;
heat[px - 1][12] = 1.0f;
}
sleep_ms(50);
}

Wyświetl plik

@ -185,14 +185,15 @@ gpio_set_function(28, GPIO_FUNC_SIO);
}
}*/
galactic_unicorn.set_pixel(x, y, 255, 255, 255);
graphics.set_pen(255, 255, 255);
graphics.pixel(Point(x, y));
galactic_unicorn.update(&graphics);
/*i++;
graphics.set_pen(0, 0, 0);
if(galactic_unicorn.is_pressed(galactic_unicorn.SWITCH_A)) {graphics.set_pen(255, 0, 0);}
graphics.clear();
if(galactic_unicorn.is_pressed(galactic_unicorn.SWITCH_BRIGHTNESS_DOWN)) {v = v == 0 ? 0 : v - 1;}

Wyświetl plik

@ -39,7 +39,6 @@ int main() {
graphics.set_pen(0, 0, 0);
graphics.clear();
for(int y = 0; y < 11; y++) {
for(int x = 0; x < 53; x++) {
if(age[x][y] < lifetime[x][y] * 0.3f) {
@ -60,8 +59,8 @@ int main() {
}
}
galactic_unicorn.update(graphics);
galactic_unicorn.update(&graphics);
sleep_ms(10);
}

Wyświetl plik

@ -72,7 +72,6 @@ int main() {
galactic_unicorn.init();
//galactic_unicorn.set_brightness(0.5f);
while(true) {
@ -113,7 +112,7 @@ int main() {
}
printf("%d\n", galactic_unicorn.light());
std::string text = "";
static bool was_a_pressed = false;
@ -127,37 +126,37 @@ int main() {
}
if(galactic_unicorn.is_pressed(GalacticUnicorn::SWITCH_A)) {
text = "Button A";
text = "Button A";
}
if(galactic_unicorn.is_pressed(GalacticUnicorn::SWITCH_B)) {
text = "Button B";
text = "Button B";
}
if(galactic_unicorn.is_pressed(GalacticUnicorn::SWITCH_C)) {
text = "Button C";
text = "Button C";
}
if(galactic_unicorn.is_pressed(GalacticUnicorn::SWITCH_D)) {
text = "Button D";
text = "Button D";
}
if(galactic_unicorn.is_pressed(GalacticUnicorn::SWITCH_VOLUME_UP)) {
text = "Louder!";
text = "Louder!";
}
if(galactic_unicorn.is_pressed(GalacticUnicorn::SWITCH_VOLUME_DOWN)) {
text = "quieter";
text = "quieter";
}
if(galactic_unicorn.is_pressed(GalacticUnicorn::SWITCH_BRIGHTNESS_UP)) {
text = "Brighter!";
text = "Brighter!";
}
if(galactic_unicorn.is_pressed(GalacticUnicorn::SWITCH_BRIGHTNESS_DOWN)) {
text = "Darker";
text = "Darker";
}
if(galactic_unicorn.is_pressed(GalacticUnicorn::SWITCH_SLEEP)) {
text = "Zzz... zzz...";
text = "Zzz... zzz...";
}
outline_text(text);
galactic_unicorn.update(graphics);
galactic_unicorn.update(&graphics);
sleep_ms(50);
}

Wyświetl plik

@ -63,7 +63,7 @@ int main() {
height = 55;
memset(heat, 0, sizeof(heat));
}
for(int y = 0; y < height; y++) {
for(int x = 0; x < width; x++) {
float value = get(x, y);
@ -78,13 +78,12 @@ int main() {
}else if(value > 0.22f) {
graphics.set_pen(20, 20, 20);
}
if(landscape) {
graphics.pixel(Point(x, y));
graphics.pixel(Point(x, y));
}else{
graphics.pixel(Point(y, x));
graphics.pixel(Point(y, x));
}
// update this pixel by averaging the below pixels
float average = (get(x, y) + get(x, y + 2) + get(x, y + 1) + get(x - 1, y + 1) + get(x + 1, y + 1)) / 5.0f;
@ -97,7 +96,7 @@ int main() {
}
}
galactic_unicorn.update(graphics);
galactic_unicorn.update(&graphics);
// clear the bottom row and then add a new fire seed to it
for(int x = 0; x < width; x++) {

Wyświetl plik

@ -66,7 +66,7 @@ int main() {
if(galactic_unicorn.is_pressed(galactic_unicorn.SWITCH_BRIGHTNESS_DOWN)) {
galactic_unicorn.adjust_brightness(-0.01);
}
uint start_ms = to_ms_since_boot(get_absolute_time());
// calculate the influence of each blob on the liquid based
@ -141,7 +141,7 @@ int main() {
printf("rendering took %dms\n", end_ms - start_ms);
galactic_unicorn.update(graphics);
galactic_unicorn.update(&graphics);
}
return 0;

Wyświetl plik

@ -88,7 +88,7 @@ int main() {
}else if(prompt == PROMPT_BBC_MICRO){
graphics.set_pen(0, 0, 0);
}
graphics.clear();
if(prompt == PROMPT_C64) {
@ -103,18 +103,18 @@ int main() {
for(size_t x = 0; x < image[y].length(); x++) {
// draw the prompt text
if(image[y][x] == 'O') {
graphics.pixel(Point(x, y + 1));
graphics.pixel(Point(x, y + 1));
}
// draw the caret blinking
if(image[y][x] == 'X' && (time_ms / 300) % 2) {
graphics.pixel(Point(x, y + 1));
graphics.pixel(Point(x, y + 1));
}
}
}
galactic_unicorn.update(graphics);
galactic_unicorn.update(&graphics);
sleep_ms(10);
}

Wyświetl plik

@ -86,8 +86,8 @@ int main() {
stars[i].a = i;
}
gpio_set_function(28, GPIO_FUNC_SIO);
gpio_set_dir(28, GPIO_OUT);
gpio_set_function(28, GPIO_FUNC_SIO);
gpio_set_dir(28, GPIO_OUT);
for(int i = 0; i < 10; i++) {
gpio_put(28, !gpio_get(28));
@ -105,7 +105,7 @@ gpio_set_function(28, GPIO_FUNC_SIO);
bool x_pressed = false;
bool y_pressed = false;
*/
graphics.set_font("bitmap8");
graphics.set_font("bitmap8");
@ -122,8 +122,8 @@ graphics.set_font("bitmap8");
while(true) {
if(animate) {
i += speed;
}
i += speed;
}
if(galactic_unicorn.is_pressed(galactic_unicorn.SWITCH_VOLUME_UP)) {
curve += 0.05;
@ -156,7 +156,6 @@ graphics.set_font("bitmap8");
animate = true;
}
if(galactic_unicorn.is_pressed(galactic_unicorn.SWITCH_C)) {
stripe_width += 0.05f;
stripe_width = stripe_width >= 10.0f ? 10.0f : stripe_width;
@ -178,19 +177,16 @@ graphics.set_font("bitmap8");
for(int x = 0; x < 53; x++) {
for(int y = 0; y < 11; y++) {
int v = ((sin((x + y) / stripe_width + (sin((y * 3.1415927f * 2.0f) / 11.0f) * curve) + i / 15.0f) + 1.5f) / 2.5f) * 255.0f;
uint8_t r = (hue_map[x][0] * v) / 256;
uint8_t g = (hue_map[x][1] * v) / 256;
uint8_t b = (hue_map[x][2] * v) / 256;
graphics.set_pen(r, g, b);
graphics.pixel(Point(x, y));
graphics.pixel(Point(x, y));
}
}
galactic_unicorn.update(graphics);
galactic_unicorn.update(&graphics);
printf("%d\n", galactic_unicorn.light());
sleep_ms(20);

Wyświetl plik

@ -41,7 +41,7 @@ int main() {
graphics.set_pen(0, 0, 0);
graphics.clear();
ok_color::HSL hsl{scroll / 100.0f, 1.0f, 0.5f};
ok_color::RGB rgb = ok_color::okhsl_to_srgb(hsl);
graphics.set_pen(rgb.r * 255, rgb.g * 255, rgb.b * 255);
@ -59,8 +59,8 @@ int main() {
}
}*/
galactic_unicorn.update(graphics);
galactic_unicorn.update(&graphics);
sleep_ms(10);
}

Wyświetl plik

@ -69,81 +69,26 @@ namespace pimoroni {
}
GalacticUnicorn::~GalacticUnicorn() {
// if(unicorn == this) {
// // stop and release the dma channel
// irq_set_enabled(DMA_IRQ_0, false);
// dma_channel_set_irq0_enabled(dma_channel, false);
// irq_set_enabled(pio_get_dreq(bitstream_pio, bitstream_sm, true), false);
// irq_remove_handler(DMA_IRQ_0, dma_complete);
// dma_channel_wait_for_finish_blocking(dma_channel);
// dma_channel_unclaim(dma_channel);
// // release the pio and sm
// pio_sm_unclaim(bitstream_pio, bitstream_sm);
// pio_remove_program(bitstream_pio, &galactic_unicorn_program, bitstream_sm_offset);
// //pio_sm_restart(bitstream_pio, bitstream_sm);
// unicorn = nullptr;
// }
if(unicorn == this) {
teardown();
/*pio_sm_set_enabled(bitstream_pio, bitstream_sm, false);
// Tear down the DMA channel.
// This is copied from: https://github.com/raspberrypi/pico-sdk/pull/744/commits/5e0e8004dd790f0155426e6689a66e08a83cd9fc
uint32_t irq0_save = dma_hw->inte0 & (1u << dma_channel);
hw_clear_bits(&dma_hw->inte0, irq0_save);
dma_hw->abort = 1u << dma_channel;
// To fence off on in-flight transfers, the BUSY bit should be polled
// rather than the ABORT bit, because the ABORT bit can clear prematurely.
while (dma_hw->ch[dma_channel].ctrl_trig & DMA_CH0_CTRL_TRIG_BUSY_BITS) tight_loop_contents();
// Clear the interrupt (if any) and restore the interrupt masks.
dma_hw->ints0 = 1u << dma_channel;
hw_set_bits(&dma_hw->inte0, irq0_save);
partial_teardown();
dma_channel_unclaim(dma_channel); // This works now the teardown behaves correctly
unicorn = nullptr;
pio_sm_unclaim(bitstream_pio, bitstream_sm);
pio_remove_program(bitstream_pio, &galactic_unicorn_program, bitstream_sm_offset);
irq_remove_handler(DMA_IRQ_0, dma_complete);*/
irq_remove_handler(DMA_IRQ_0, dma_complete);
}
}
void GalacticUnicorn::teardown() {
pio_sm_set_enabled(bitstream_pio, bitstream_sm, false);
// Tear down the DMA channel.
// This is copied from: https://github.com/raspberrypi/pico-sdk/pull/744/commits/5e0e8004dd790f0155426e6689a66e08a83cd9fc
uint32_t irq0_save = dma_hw->inte0 & (1u << dma_channel);
hw_clear_bits(&dma_hw->inte0, irq0_save);
dma_hw->abort = 1u << dma_channel;
// To fence off on in-flight transfers, the BUSY bit should be polled
// rather than the ABORT bit, because the ABORT bit can clear prematurely.
while (dma_hw->ch[dma_channel].ctrl_trig & DMA_CH0_CTRL_TRIG_BUSY_BITS) tight_loop_contents();
// Clear the interrupt (if any) and restore the interrupt masks.
dma_hw->ints0 = 1u << dma_channel;
hw_set_bits(&dma_hw->inte0, irq0_save);
dma_channel_unclaim(dma_channel); // This works now the teardown behaves correctly
unicorn = nullptr;
pio_sm_unclaim(bitstream_pio, bitstream_sm);
pio_remove_program(bitstream_pio, &galactic_unicorn_program, bitstream_sm_offset);
irq_remove_handler(DMA_IRQ_0, dma_complete);
}
void GalacticUnicorn::partial_teardown() {
pio_sm_set_enabled(bitstream_pio, bitstream_sm, false);
// Make sure the display is off and switch it to an invisible row, to be safe
const uint pins_to_set = 1 << COLUMN_BLANK | 0b1111 << ROW_BIT_0;
pio_sm_set_pins_with_mask(bitstream_pio, bitstream_sm, pins_to_set, pins_to_set);
// Tear down the DMA channel.
// This is copied from: https://github.com/raspberrypi/pico-sdk/pull/744/commits/5e0e8004dd790f0155426e6689a66e08a83cd9fc
uint32_t irq0_save = dma_hw->inte0 & (1u << dma_channel);
@ -158,13 +103,6 @@ namespace pimoroni {
// Clear the interrupt (if any) and restore the interrupt masks.
dma_hw->ints0 = 1u << dma_channel;
hw_set_bits(&dma_hw->inte0, irq0_save);
//dma_channel_unclaim(dma_channel); // This works now the teardown behaves correctly
//unicorn = nullptr;
//pio_sm_unclaim(bitstream_pio, bitstream_sm);
//pio_remove_program(bitstream_pio, &galactic_unicorn_program, bitstream_sm_offset);
//irq_remove_handler(DMA_IRQ_0, dma_complete);
}
uint16_t GalacticUnicorn::light() {
@ -179,10 +117,6 @@ namespace pimoroni {
partial_teardown();
}
// todo: shouldn't need to do this if things were cleaned up properly but without
// this any attempt to run a micropython script twice will fail
//static bool already_init = false;
// create 14-bit gamma luts
for(uint16_t v = 0; v < 256; v++) {
@ -228,14 +162,17 @@ namespace pimoroni {
adc_init();
adc_gpio_init(LIGHT_SENSOR);
pio_gpio_init(bitstream_pio, COLUMN_CLOCK);
pio_gpio_init(bitstream_pio, COLUMN_DATA);
pio_gpio_init(bitstream_pio, COLUMN_LATCH);
gpio_init(COLUMN_CLOCK); gpio_set_dir(COLUMN_CLOCK, GPIO_OUT); gpio_put(COLUMN_CLOCK, false);
gpio_init(COLUMN_DATA); gpio_set_dir(COLUMN_DATA, GPIO_OUT); gpio_put(COLUMN_DATA, false);
gpio_init(COLUMN_LATCH); gpio_set_dir(COLUMN_LATCH, GPIO_OUT); gpio_put(COLUMN_LATCH, false);
gpio_init(COLUMN_BLANK); gpio_set_dir(COLUMN_BLANK, GPIO_OUT); gpio_put(COLUMN_BLANK, true);
// initialise the row select, and set them to a non-visible row to avoid flashes during setup
gpio_init(ROW_BIT_0); gpio_set_dir(ROW_BIT_0, GPIO_OUT); gpio_put(ROW_BIT_0, true);
gpio_init(ROW_BIT_1); gpio_set_dir(ROW_BIT_1, GPIO_OUT); gpio_put(ROW_BIT_1, true);
gpio_init(ROW_BIT_2); gpio_set_dir(ROW_BIT_2, GPIO_OUT); gpio_put(ROW_BIT_2, true);
gpio_init(ROW_BIT_3); gpio_set_dir(ROW_BIT_3, GPIO_OUT); gpio_put(ROW_BIT_3, true);
sleep_ms(100);
// configure full output current in register 2
@ -276,6 +213,11 @@ namespace pimoroni {
}
gpio_put(COLUMN_LATCH, false);
// reapply the blank as the above seems to cause a slight glow.
// Note, this will produce a brief flash if a visible row is selected (which it shouldn't be)
gpio_put(COLUMN_BLANK, false);
sleep_us(10);
gpio_put(COLUMN_BLANK, true);
gpio_init(MUTE); gpio_set_dir(MUTE, GPIO_OUT); gpio_put(MUTE, true);
@ -293,26 +235,6 @@ namespace pimoroni {
gpio_init(SWITCH_VOLUME_UP); gpio_pull_up(SWITCH_VOLUME_UP);
gpio_init(SWITCH_VOLUME_DOWN); gpio_pull_up(SWITCH_VOLUME_DOWN);
// if(already_init) {
// // stop and release the dma channel
// irq_set_enabled(DMA_IRQ_0, false);
// dma_channel_abort(dma_channel);
// dma_channel_wait_for_finish_blocking(dma_channel);
// dma_channel_set_irq0_enabled(dma_channel, false);
// irq_set_enabled(pio_get_dreq(bitstream_pio, bitstream_sm, true), false);
// irq_remove_handler(DMA_IRQ_0, dma_complete);
// dma_channel_unclaim(dma_channel);
// // release the pio and sm
// pio_sm_unclaim(bitstream_pio, bitstream_sm);
// pio_clear_instruction_memory(bitstream_pio);
// pio_sm_restart(bitstream_pio, bitstream_sm);
// //return;
// }
// setup the pio if it has not previously been set up
bitstream_pio = pio0;
if(unicorn == nullptr) {
@ -330,7 +252,10 @@ namespace pimoroni {
pio_gpio_init(bitstream_pio, ROW_BIT_2);
pio_gpio_init(bitstream_pio, ROW_BIT_3);
// set all led driving pins as outputs
// set the blank and row pins to be high, then set all led driving pins as outputs.
// This order is important to avoid a momentary flash
const uint pins_to_set = 1 << COLUMN_BLANK | 0b1111 << ROW_BIT_0;
pio_sm_set_pins_with_mask(bitstream_pio, bitstream_sm, pins_to_set, pins_to_set);
pio_sm_set_consecutive_pindirs(bitstream_pio, bitstream_sm, COLUMN_CLOCK, 8, true);
pio_sm_config c = galactic_unicorn_program_get_default_config(bitstream_sm_offset);
@ -378,8 +303,6 @@ namespace pimoroni {
next_dma_sequence();
//already_init = true;
// TODO Add audio back in
// setup audio pio program
/*audio_pio = pio0;
@ -412,7 +335,7 @@ namespace pimoroni {
if(unicorn == this) {
for(uint8_t y = 0; y < HEIGHT; y++) {
for(uint8_t x = 0; x < WIDTH; x++) {
set_pixel(x, y, 0);
set_pixel(x, y, 0, 0, 0);
}
}
}
@ -465,10 +388,6 @@ namespace pimoroni {
}
}
void GalacticUnicorn::set_pixel(int x, int y, uint8_t v) {
set_pixel(x, y, v, v, v);
}
void GalacticUnicorn::set_brightness(float value) {
value = value < 0.0f ? 0.0f : value;
value = value > 1.0f ? 1.0f : value;
@ -497,7 +416,6 @@ namespace pimoroni {
this->set_volume(this->get_volume() + delta);
}
void GalacticUnicorn::update(PicoGraphics *graphics) {
if(unicorn == this) {
if(graphics->pen_type == PicoGraphics::PEN_RGB888) {
@ -533,42 +451,6 @@ namespace pimoroni {
}
}
void GalacticUnicorn::update(PicoGraphics_PenRGB565 &graphics) {
if(unicorn == this) {
uint16_t *p = (uint16_t *)graphics.frame_buffer;
for(size_t j = 0; j < 53 * 11; j++) {
int x = j % 53;
int y = j / 53;
uint16_t col = __builtin_bswap16(*p);
uint8_t r = (col & 0b1111100000000000) >> 8;
uint8_t g = (col & 0b0000011111100000) >> 3;
uint8_t b = (col & 0b0000000000011111) << 3;
p++;
set_pixel(x, y, r, g, b);
}
}
}
void GalacticUnicorn::update(PicoGraphics_PenRGB888 &graphics) {
if(unicorn == this) {
uint32_t *p = (uint32_t *)graphics.frame_buffer;
for(size_t j = 0; j < 53 * 11; j++) {
int x = j % 53;
int y = j / 53;
uint32_t col = *p;
uint8_t r = (col & 0xff0000) >> 16;
uint8_t g = (col & 0x00ff00) >> 8;
uint8_t b = (col & 0x0000ff) >> 0;
p++;
set_pixel(x, y, r, g, b);
}
}
}
bool GalacticUnicorn::is_pressed(uint8_t button) {
return !gpio_get(button);
}

Wyświetl plik

@ -68,10 +68,6 @@ namespace pimoroni {
static GalacticUnicorn* unicorn;
static void dma_complete();
private:
void teardown();
void partial_teardown();
public:
~GalacticUnicorn();
@ -81,8 +77,8 @@ namespace pimoroni {
void clear();
void update(PicoGraphics *graphics);
void update(PicoGraphics_PenRGB565 &graphics);
void update(PicoGraphics_PenRGB888 &graphics);
//void update(PicoGraphics_PenRGB565 &graphics);
//void update(PicoGraphics_PenRGB888 &graphics);
void set_brightness(float value);
float get_brightness();
@ -92,9 +88,10 @@ namespace pimoroni {
float get_volume();
void adjust_volume(float delta);
private:
void set_pixel(int x, int y, uint8_t r, uint8_t g, uint8_t b);
void set_pixel(int x, int y, uint8_t v);
//void set_pixel(int x, int y, uint8_t v);
public:
uint16_t light();
@ -104,6 +101,7 @@ namespace pimoroni {
private:
void next_dma_sequence();
void partial_teardown();
};
}

Wyświetl plik

@ -11,7 +11,6 @@ MP_DEFINE_CONST_FUN_OBJ_2(GalacticUnicorn_adjust_brightness_obj, GalacticUnicorn
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, 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);
@ -27,7 +26,6 @@ STATIC const mp_rom_map_elem_t GalacticUnicorn_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_set_volume), MP_ROM_PTR(&GalacticUnicorn_set_volume_obj) },
{ MP_ROM_QSTR(MP_QSTR_get_volume), MP_ROM_PTR(&GalacticUnicorn_get_volume_obj) },
{ MP_ROM_QSTR(MP_QSTR_adjust_volume), MP_ROM_PTR(&GalacticUnicorn_adjust_volume_obj) },
{ 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) },

Wyświetl plik

@ -19,7 +19,6 @@ 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 {
@ -68,26 +67,10 @@ mp_obj_t GalacticUnicorn_make_new(const mp_obj_type_t *type, size_t n_args, size
GalacticUnicorn *galactic = m_new_class(GalacticUnicorn);
galactic->init();
//if(!galactic->init()) {
//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);
}
@ -97,7 +80,6 @@ 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;
}
@ -152,61 +134,10 @@ extern mp_obj_t GalacticUnicorn_adjust_volume(mp_obj_t self_in, mp_obj_t 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) {
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;
}
extern mp_obj_t GalacticUnicorn_light(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->light());
}
extern mp_obj_t GalacticUnicorn_is_pressed(mp_obj_t self_in, mp_obj_t button) {

Wyświetl plik

@ -20,8 +20,6 @@ extern mp_obj_t GalacticUnicorn_set_volume(mp_obj_t self_in, mp_obj_t value);
extern mp_obj_t GalacticUnicorn_get_volume(mp_obj_t self_in);
extern mp_obj_t GalacticUnicorn_adjust_volume(mp_obj_t self_in, mp_obj_t delta);
extern mp_obj_t GalacticUnicorn_set_pixel(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
//extern mp_obj_t GalacticUnicorn_set_pixel(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
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);