kopia lustrzana https://github.com/pimoroni/pimoroni-pico
Implement scroll_text()
rodzic
d5e9dd001e
commit
eb1b1b238e
|
@ -114,6 +114,14 @@ for j in range(256*6):
|
|||
|
||||
N.B. the first 32 characters are white space...
|
||||
|
||||
### scroll_text
|
||||
|
||||
Scroll a string across the picoscroll, starting off the right hand side, to the left, with a given delay in ms.
|
||||
|
||||
```python
|
||||
picoscroll.scroll_text("Hello, world!", 8, 100)
|
||||
```
|
||||
|
||||
### show_bitmap_1d
|
||||
|
||||
Show a view of a bitmap stored as the 7 least significant bits of
|
||||
|
|
|
@ -22,6 +22,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(picoscroll_update_obj, picoscroll_update);
|
|||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(picoscroll_set_pixel_obj, picoscroll_set_pixel);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(picoscroll_set_pixels_obj, picoscroll_set_pixels);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(picoscroll_show_text_obj, picoscroll_show_text);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(picoscroll_scroll_text_obj, picoscroll_scroll_text);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(picoscroll_show_bitmap_1d_obj, picoscroll_show_bitmap_1d);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(picoscroll_clear_obj, picoscroll_clear);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(picoscroll_is_pressed_obj, picoscroll_is_pressed);
|
||||
|
@ -36,6 +37,7 @@ STATIC const mp_map_elem_t picoscroll_globals_table[] = {
|
|||
{ MP_ROM_QSTR(MP_QSTR_set_pixel), MP_ROM_PTR(&picoscroll_set_pixel_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_set_pixels), MP_ROM_PTR(&picoscroll_set_pixels_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_show_text), MP_ROM_PTR(&picoscroll_show_text_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_scroll_text), MP_ROM_PTR(&picoscroll_scroll_text_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_show_bitmap_1d), MP_ROM_PTR(&picoscroll_show_bitmap_1d_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_clear), MP_ROM_PTR(&picoscroll_clear_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_is_pressed), MP_ROM_PTR(&picoscroll_is_pressed_obj) },
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "hardware/spi.h"
|
||||
#include "hardware/sync.h"
|
||||
#include "pico/binary_info.h"
|
||||
#include "pico/stdlib.h"
|
||||
|
||||
#include "../../../libraries/pico_scroll/pico_scroll.hpp"
|
||||
|
||||
|
@ -60,6 +61,53 @@ mp_obj_t picoscroll_set_pixel(mp_obj_t x_obj, mp_obj_t y_obj, mp_obj_t v_obj) {
|
|||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t picoscroll_scroll_text(mp_obj_t text_obj, mp_obj_t brightness_obj,
|
||||
mp_obj_t delay_ms_obj) {
|
||||
if (scroll != nullptr) {
|
||||
mp_buffer_info_t bufinfo;
|
||||
unsigned char *buffer;
|
||||
int text_len, bfr_len;
|
||||
|
||||
mp_get_buffer_raise(text_obj, &bufinfo, MP_BUFFER_READ);
|
||||
unsigned char *values = (unsigned char *)bufinfo.buf;
|
||||
int brightness = mp_obj_get_int(brightness_obj);
|
||||
int delay_ms = mp_obj_get_int(delay_ms_obj);
|
||||
|
||||
text_len = bufinfo.len;
|
||||
bfr_len = 6 * text_len;
|
||||
|
||||
int width = PicoScroll::WIDTH;
|
||||
int height = PicoScroll::HEIGHT;
|
||||
|
||||
buffer = (unsigned char *)m_malloc(sizeof(unsigned char) * bfr_len);
|
||||
render(values, text_len, buffer, bfr_len);
|
||||
|
||||
for (int offset = -width; offset < bfr_len; offset++) {
|
||||
scroll->clear();
|
||||
|
||||
for (int x = 0; x < width; x++) {
|
||||
int k = offset + x;
|
||||
if ((k >= 0) && (k < bfr_len)) {
|
||||
unsigned char col = buffer[k];
|
||||
for (int y = 0; y < height; y++) {
|
||||
int val = brightness * ((col >> y) & 1);
|
||||
scroll->set_pixel(x, y, val);
|
||||
}
|
||||
}
|
||||
}
|
||||
scroll->update();
|
||||
sleep_ms(delay_ms);
|
||||
}
|
||||
m_free(buffer);
|
||||
} else {
|
||||
mp_raise_msg(&mp_type_RuntimeError, NOT_INITIALISED_MSG);
|
||||
}
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
// TODO refactor this to not need a buffer - should be able to render
|
||||
// view into static 17 bytes
|
||||
mp_obj_t picoscroll_show_text(mp_obj_t text_obj, mp_obj_t brightness_obj,
|
||||
mp_obj_t offset_obj) {
|
||||
if (scroll != nullptr) {
|
||||
|
|
|
@ -9,6 +9,7 @@ extern mp_obj_t picoscroll_update();
|
|||
extern mp_obj_t picoscroll_set_pixel(mp_obj_t x_obj, mp_obj_t y_obj, mp_obj_t v_obj);
|
||||
extern mp_obj_t picoscroll_set_pixels(mp_obj_t image_obj);
|
||||
extern mp_obj_t picoscroll_show_text(mp_obj_t text_obj, mp_obj_t brightness, mp_obj_t offset);
|
||||
extern mp_obj_t picoscroll_scroll_text(mp_obj_t text_obj, mp_obj_t brightness, mp_obj_t delay);
|
||||
extern mp_obj_t picoscroll_show_bitmap_1d(mp_obj_t bitmap_obj, mp_obj_t brightness, mp_obj_t offset);
|
||||
extern mp_obj_t picoscroll_clear();
|
||||
extern mp_obj_t picoscroll_is_pressed(mp_obj_t button_obj);
|
||||
|
|
Ładowanie…
Reference in New Issue