mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-01-11 15:29:28 -05:00
Dynamic usb buffer fill for screenframeshort (#1935)
* fully fill usb serial buffer * Update usb_serial_shell.cpp * Added a comment, to trigger wf
This commit is contained in:
parent
3bf689f339
commit
9e9dd3a521
@ -211,6 +211,7 @@ static void cmd_screenframe(BaseSequentialStream* chp, int argc, char* argv[]) {
|
|||||||
chprintf(chp, "ok\r\n");
|
chprintf(chp, "ok\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// calculates the 1 byte rgb value, and add 32 to it, so it can be a printable character.
|
||||||
static char getChrFromRgb(uint8_t r, uint8_t g, uint8_t b) {
|
static char getChrFromRgb(uint8_t r, uint8_t g, uint8_t b) {
|
||||||
uint8_t chR = r >> 6; // 3bit
|
uint8_t chR = r >> 6; // 3bit
|
||||||
uint8_t chG = g >> 6; // 3bit
|
uint8_t chG = g >> 6; // 3bit
|
||||||
@ -220,26 +221,36 @@ static char getChrFromRgb(uint8_t r, uint8_t g, uint8_t b) {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// keep track of a buffer, and sends only if full. not only line by line
|
||||||
|
static void screenbuffer_helper_add(BaseSequentialStream* chp, char* buffer, size_t& wp, char ch) {
|
||||||
|
buffer[wp++] = ch;
|
||||||
|
if (wp > USBSERIAL_BUFFERS_SIZE - 1) {
|
||||||
|
fillOBuffer(&((SerialUSBDriver*)chp)->oqueue, (const uint8_t*)buffer, USBSERIAL_BUFFERS_SIZE);
|
||||||
|
wp = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// sends only 1 byte (printable only) per pixel, so around 96 colors
|
// sends only 1 byte (printable only) per pixel, so around 96 colors
|
||||||
static void cmd_screenframeshort(BaseSequentialStream* chp, int argc, char* argv[]) {
|
static void cmd_screenframeshort(BaseSequentialStream* chp, int argc, char* argv[]) {
|
||||||
(void)argc;
|
(void)argc;
|
||||||
(void)argv;
|
(void)argv;
|
||||||
|
|
||||||
auto evtd = getEventDispatcherInstance();
|
auto evtd = getEventDispatcherInstance();
|
||||||
evtd->enter_shell_working_mode();
|
evtd->enter_shell_working_mode();
|
||||||
|
char buffer[USBSERIAL_BUFFERS_SIZE];
|
||||||
|
size_t wp = 0;
|
||||||
for (int y = 0; y < ui::screen_height; y++) {
|
for (int y = 0; y < ui::screen_height; y++) {
|
||||||
std::array<ui::ColorRGB888, ui::screen_width> row;
|
std::array<ui::ColorRGB888, ui::screen_width> row;
|
||||||
portapack::display.read_pixels({0, y, ui::screen_width, 1}, row);
|
portapack::display.read_pixels({0, y, ui::screen_width, 1}, row);
|
||||||
char buffer[242];
|
|
||||||
for (int i = 0; i < 240; ++i) {
|
for (int i = 0; i < 240; ++i) {
|
||||||
buffer[i] = getChrFromRgb(row[i].r, row[i].g, row[i].b);
|
screenbuffer_helper_add(chp, buffer, wp, getChrFromRgb(row[i].r, row[i].g, row[i].b));
|
||||||
}
|
}
|
||||||
buffer[240] = '\r';
|
screenbuffer_helper_add(chp, buffer, wp, '\r');
|
||||||
buffer[241] = '\n';
|
screenbuffer_helper_add(chp, buffer, wp, '\n');
|
||||||
fillOBuffer(&((SerialUSBDriver*)chp)->oqueue, (const uint8_t*)buffer, 242);
|
}
|
||||||
|
if (wp > 0) {
|
||||||
|
// send remaining
|
||||||
|
fillOBuffer(&((SerialUSBDriver*)chp)->oqueue, (const uint8_t*)buffer, wp);
|
||||||
}
|
}
|
||||||
|
|
||||||
evtd->exit_shell_working_mode();
|
evtd->exit_shell_working_mode();
|
||||||
chprintf(chp, "\r\nok\r\n");
|
chprintf(chp, "\r\nok\r\n");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user