@@ 95,14 95,15 @@ buffered_transceiver_t uart_rx;
#define MAX_CMD_LENGTH 65
-#define AUTO_TOGGLE_CYCLES 1000000
#define MAX_IMAGES 10
#define COLS 8
#define ROWS 8
+uint32_t auto_toggle_cycles = 1000000;
uint8_t images_count = 4;
uint8_t current_image = 0;
+uint8_t replacing_image_index = 4;
uint8_t images[MAX_IMAGES][8] = {
{0b11111111, 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b11111111},
{ 0b00000100, 0b00001110, 0b11110001, 0b10000101, 0b10000001, 0b10110001, 0b10110001, 0b11111111 },
@@ 113,6 114,7 @@ uint8_t images[MAX_IMAGES][8] = {
uint32_t cycle = 0;
bool auto_toggle = false;
bool toggle_next = false;
+bool toggle_prev = false;
bool animation = false;
@@ 138,6 140,13 @@ void handle_command(char* cmd, uint16_t len) {
buffered_transceiver_transmit(&uart_rx, "Switching to next image.\r\n", 0);
}
break;
+ case 'p': // next
+ if (len == 1) {
+ handled = true;
+ toggle_prev = true;
+ buffered_transceiver_transmit(&uart_rx, "Switching to previous image.\r\n", 0);
+ }
+ break;
case 'N': // auto toggle
if (len == 1) {
handled = true;
@@ 163,10 172,50 @@ void handle_command(char* cmd, uint16_t len) {
}
break;
case 'u': // upload
- // upload
- // TODO
+ if (len != ROWS * COLS + 1) {
+ break;
+ }
+
+ // null row
+ for (uint8_t row = 0; row < ROWS; row++) {
+ images[replacing_image_index][row] = 0;
+ }
+
+ // write data
+ for (uint16_t i = 0; i < ROWS * COLS; i++) {
+ uint8_t row = i >> 3;
+ uint8_t col = i & 7;
+ images[replacing_image_index][row] |= (cmd[1 + i] == 'X' ? 1 : 0) << col;
+ }
+
+ if (images_count < MAX_IMAGES) {
+ images_count++;
+ buffered_transceiver_transmit(&uart_rx, "Added image.\r\n", 0);
+ } else {
+ buffered_transceiver_transmit(&uart_rx, "Replaced image.\r\n", 0);
+ }
+ replacing_image_index++;
+ replacing_image_index %= MAX_IMAGES;
+ handled = true;
+
+ break;
+ case 's': // speed decrease
+ if (len == 1) {
+ handled = true;
+ auto_toggle_cycles += 100000;
+ buffered_transceiver_transmit(&uart_rx, "Auto toggle speed decreased.\r\n", 0);
+ }
+ break;
+ case 'S': // speed increase
+ if (len == 1) {
+ handled = true;
+ if (auto_toggle_cycles > 100000) {
+ auto_toggle_cycles -= 100000;
+ }
+ buffered_transceiver_transmit(&uart_rx, "Auto toggle speed increased.\r\n", 0);
+ }
break;
- case 's': // number of slots is...
+ case 'l': // number of slots is...
if (len == 1) {
handled = true;
@@ 194,12 243,12 @@ void handle_command(char* cmd, uint16_t len) {
case 'h':
buffered_transceiver_transmit(&uart_rx, "Help:\r\n", 0);
buffered_transceiver_transmit(&uart_rx, " h - show this help messages\r\n", 0);
- buffered_transceiver_transmit(&uart_rx, " s - print used slots\r\n", 0);
+ buffered_transceiver_transmit(&uart_rx, " l - print used slots\r\n", 0);
buffered_transceiver_transmit(&uart_rx, " a - toggle animating\r\n", 0);
- buffered_transceiver_transmit(&uart_rx, " n - next image\r\n", 0);
+ buffered_transceiver_transmit(&uart_rx, " n, p - next, prev image\r\n", 0);
+ buffered_transceiver_transmit(&uart_rx, " s, S - decrease, increase toggle speed\r\n", 0);
buffered_transceiver_transmit(&uart_rx, " N - automatically switch images\r\n", 0);
- buffered_transceiver_transmit(&uart_rx, " I - increase intensity\r\n", 0);
- buffered_transceiver_transmit(&uart_rx, " i - decrease intensity\r\n", 0);
+ buffered_transceiver_transmit(&uart_rx, " I, i - increase, decrease intensity\r\n", 0);
buffered_transceiver_transmit(&uart_rx, " uIMG - upload new image, IMG has \"X\" for 1s and \"-\" for 0s. It should be 64 chars long\r\n", 0);
handled = true;
break;
@@ 244,13 293,17 @@ char* receive_command(uint16_t* length)
return NULL;
}
-void next_image()
+void next_image(int8_t offset)
{
if (matrix.state != MATRIX_STABLE) {
return;
}
- current_image++;
+ current_image += offset;
+ if (current_image > images_count) {
+ current_image = images_count - 1;
+ }
+
current_image %= images_count;
matrix_set_buffer(&matrix, MATRIX_SLOT_OTHER, &images[current_image][0]);
@@ 272,12 325,15 @@ void app_loop()
pin_reset(&led);
}
- if (auto_toggle && cycle >= AUTO_TOGGLE_CYCLES) {
- next_image();
+ if (auto_toggle && cycle >= auto_toggle_cycles) {
+ next_image(1);
cycle = 0;
} else if (toggle_next) {
- next_image();
+ next_image(1);
toggle_next = false;
+ } else if (toggle_prev) {
+ next_image(-1);
+ toggle_prev = false;
}
uint16_t command_len;
@@ 305,7 361,7 @@ void main()
pin_t pin_tx;
#define UART_RX_BUFFER_SIZE 64
- #define UART_TX_BUFFER_SIZE 300
+ #define UART_TX_BUFFER_SIZE 312
static queue_t uart_rx_queue, uart_tx_queue;
static uint16_t uart_rx_buffer[UART_RX_BUFFER_SIZE], uart_tx_buffer[UART_TX_BUFFER_SIZE];