working print to the terminal

This commit is contained in:
Filipriec
2025-11-13 21:44:40 +01:00
parent 10e11858f3
commit b3a228c3ac

View File

@@ -4,7 +4,9 @@
#define TARGET_TX_PIN USBTX #define TARGET_TX_PIN USBTX
#define TARGET_RX_PIN USBRX #define TARGET_RX_PIN USBRX
#define BAUD_RATE 115200 #define BAUD_RATE 1843200
// #define BAUD_RATE 460800
// #define BAUD_RATE 921600
static BufferedSerial serial_port(TARGET_TX_PIN, TARGET_RX_PIN, BAUD_RATE); static BufferedSerial serial_port(TARGET_TX_PIN, TARGET_RX_PIN, BAUD_RATE);
@@ -18,22 +20,48 @@ DigitalOut led(LED1);
#define BUFFER_SIZE 64 #define BUFFER_SIZE 64
static char rx_buffer[BUFFER_SIZE]; static char rx_buffer[BUFFER_SIZE];
// Draw shifting mask with optional centered text // Draw a moving “sky + ground” background with optional message
void draw_mask(uint32_t mask, int shift, const char *text = nullptr) void draw_mask(uint32_t mask, int shift, const char *text = nullptr)
{ {
const int width = 80; // terminal columns
const int height = 24; // terminal rows
const int horizon = 16; // sky ends here, ground below
printf("\033[2J\033[H"); // clear + home printf("\033[2J\033[H"); // clear + home
for (int byte = 3; byte >= 0; byte--) { // draw sky layer (moving clouds)
uint8_t b = ((mask >> (byte * 8)) & 0xFF); for (int y = 0; y < horizon; y++) {
// Circular shift for movement illusion for (int x = 0; x < width; x++) {
uint8_t rotated = (b << shift) | (b >> (8 - shift)); // Parallax: slower movement at top
for (int i = 7; i >= 0; i--) { int move = (shift / 2 + y) % width;
printf("%c", (rotated & (1 << i)) ? '#' : '.'); char c = ((x + move) % 11 == 0) ? '' : ' ';
printf("%c", c);
} }
printf("\r\n"); printf("\r\n");
} }
// Message under the mask // draw horizon line
for (int i = 0; i < width; i++) printf("-");
printf("\r\n");
// draw ground (grass / terrain)
for (int y = horizon + 1; y < height; y++) {
for (int x = 0; x < width; x++) {
int move = (shift * 2 + y) % width;
// simple wave pattern for terrain / hill
char c;
if (((x + move) % 7) == 0)
c = '^';
else if (((x + move) % 5) == 0)
c = '`';
else
c = ' ';
printf("%c", c);
}
printf("\r\n");
}
// optional text overlay at bottom
if (text && text[0] != '\0') { if (text && text[0] != '\0') {
printf("\r\n[RX] %s\r\n", text); printf("\r\n[RX] %s\r\n", text);
} }
@@ -77,7 +105,7 @@ int main(void)
// shift = (shift + 1) % 8; // shift = (shift + 1) % 8;
// } // }
if (anim_timer.elapsed_time() >= 100ms) { if (anim_timer.elapsed_time() >= 200ms) {
shift = (shift + 1) % 8; shift = (shift + 1) % 8;
anim_timer.reset(); anim_timer.reset();