diff --git a/Dashboard/Dashboard.ino b/Dashboard/Dashboard.ino index 4ce8c64b98283c1be049c1f6665b292bbbfcf711..001440c573bb2c011278d90186fec02320fd804f 100644 --- a/Dashboard/Dashboard.ino +++ b/Dashboard/Dashboard.ino @@ -27,6 +27,8 @@ #include <MHZ19_uart.h> /********************************/ +#include "font.h" + #define LEDsPin 2 #define CO2RX A0 #define CO2TX A1 @@ -36,15 +38,18 @@ #define WIDTH 16 #define HEIGHT 9 #define numLeds (WIDTH * HEIGHT) +#define COLOR mHEX(0x9aa100) microLED<numLeds, LEDsPin, MLED_NO_CLOCK, LED_WS2812, ORDER_GRB, CLI_AVER/*, SAVE_MILLIS*/> matrix(WIDTH, HEIGHT, ZIGZAG, RIGHT_TOP, DIR_LEFT); +#include "textbox.h" +textbox tb; MHZ19_uart co2; void setup() { Serial.begin(9600); while (!Serial.available()) {} - //Serial.println("Hello"); + Serial.println("Hello"); matrix.setBrightness(100); matrix.clear(); matrix.show(); @@ -52,11 +57,16 @@ void setup() co2.begin(CO2TX, CO2RX); co2.setAutoCalibration(false); delay(500); + tb.setup("Hello", TB_STATIC, 0, 0, 16); + tb.render(); } void loop() { - matrix.clear(); + for (uint8_t i = 0; i < 9; i++) + { + matrix.set(matrix.getPixNumber(15, i), mHEX(0)); + } uint16_t CO2 = co2.getPPM(); Serial.print(CO2); Serial.print(" "); @@ -67,7 +77,7 @@ void loop() CO2 = map(CO2, 300, 1500, 0, 9); for (uint8_t i = 0; i < CO2; i++) { - matrix.set(matrix.getPixNumber(1, i), mHEX(0x9aa100)); + matrix.set(matrix.getPixNumber(15, i), mHEX(0x0aa100)); } //matrix.fill(mHEX(0x9aa100)); matrix.show(); diff --git a/Dashboard/font.h b/Dashboard/font.h new file mode 100644 index 0000000000000000000000000000000000000000..f7faa5778102cdcc924f7a1bdcf2b9bbc556c148 --- /dev/null +++ b/Dashboard/font.h @@ -0,0 +1,84 @@ +#pragma once + +#define cords(width, offset, bytes) offset + bytes * 7 + (width - 1) * 49 + +// Example char +// const uint8_t char[] PROGMEM = {cords(x, y, b), 0b11111110, 0b11110111, 0b01011101, 0b11101111, 0b11100000}; + +const uint8_t font_space[] PROGMEM = {cords(1, 6, 1), 0b00000000}; +const uint8_t font_notdef[] PROGMEM = {cords(5, 0, 5), 0b11111110, 0b11110111, 0b01011101, 0b11101111, 0b11100000}; +const uint8_t font_dot[] PROGMEM = {cords(2, 4, 1), 0b11011000}; +const uint8_t font_comma[] PROGMEM = {cords(2, 4, 1), 0b11011001}; +const uint8_t font_exclamation[] PROGMEM = {cords(1, 0, 1), 0b11110100}; +const uint8_t font_question[] PROGMEM = {cords(3, 0, 3), 0b01010100, 0b10100100, 0b00010000}; +// Numbers +const uint8_t font_num0[] PROGMEM = {cords(5, 0, 5), 0b01110100, 0b11101011, 0b01011010, 0b11100101, 0b11000000}; +const uint8_t font_num1[] PROGMEM = {cords(3, 0, 3), 0b01011001, 0b00100100, 0b10111000}; +const uint8_t font_num2[] PROGMEM = {cords(4, 0, 4), 0b01101001, 0b00010010, 0b01001000, 0b11110000}; +const uint8_t font_num3[] PROGMEM = {cords(4, 0, 4), 0b01101001, 0b00010110, 0b00011001, 0b01100000}; +const uint8_t font_num4[] PROGMEM = {cords(5, 0, 5), 0b00110010, 0b10010101, 0b00101111, 0b10001000, 0b01000000}; +const uint8_t font_num5[] PROGMEM = {cords(4, 0, 4), 0b11111000, 0b10001110, 0b00011001, 0b01100000}; +const uint8_t font_num6[] PROGMEM = {cords(4, 0, 4), 0b00110100, 0b10001110, 0b10011001, 0b01100000}; +const uint8_t font_num7[] PROGMEM = {cords(3, 0, 3), 0b11100100, 0b10010100, 0b10010000}; +const uint8_t font_num8[] PROGMEM = {cords(4, 0, 4), 0b01101001, 0b10010110, 0b10011001, 0b01100000}; +const uint8_t font_num9[] PROGMEM = {cords(4, 0, 4), 0b01101001, 0b10010111, 0b00010001, 0b01100000}; +// English +const uint8_t font_A[] PROGMEM = {cords(5, 0, 5), 0b01101101, 0b11000110, 0b00111111, 0b10001100, 0b01000000}; +const uint8_t font_B[] PROGMEM = {cords(5, 0, 5), 0b11100100, 0b10100101, 0b11101000, 0b11000111, 0b11000000}; +const uint8_t font_C[] PROGMEM = {cords(5, 0, 5), 0b01110100, 0b01100001, 0b00001000, 0b01000101, 0b11000000}; +const uint8_t font_D[] PROGMEM = {cords(5, 0, 5), 0b11100100, 0b10100011, 0b00011000, 0b11001011, 0b10000000}; +const uint8_t font_E[] PROGMEM = {cords(4, 0, 4), 0b11111000, 0b10001111, 0b10001000, 0b11110000}; +const uint8_t font_F[] PROGMEM = {cords(4, 0, 4), 0b11111000, 0b10001111, 0b10001000, 0b10000000}; +const uint8_t font_G[] PROGMEM = {cords(5, 0, 5), 0b01110100, 0b01100001, 0b00001001, 0b11000101, 0b11000000}; +const uint8_t font_H[] PROGMEM = {cords(4, 0, 4), 0b10011001, 0b10011111, 0b10011001, 0b10010000}; +const uint8_t font_I[] PROGMEM = {cords(1, 0, 1), 0b11111110}; +const uint8_t font_J[] PROGMEM = {cords(3, 0, 3), 0b00100100, 0b10010011, 0b01010000}; +const uint8_t font_K[] PROGMEM = {cords(4, 0, 4), 0b10011010, 0b10101100, 0b10101010, 0b10010000}; +const uint8_t font_L[] PROGMEM = {cords(4, 0, 4), 0b10001000, 0b10001000, 0b10001000, 0b11110000}; +const uint8_t font_M[] PROGMEM = {cords(5, 0, 5), 0b10001110, 0b11101011, 0b01011000, 0b11000110, 0b00100000}; +const uint8_t font_N[] PROGMEM = {cords(5, 0, 5), 0b10001110, 0b01101011, 0b01011010, 0b11001110, 0b00100000}; +const uint8_t font_O[] PROGMEM = {cords(4, 0, 4), 0b01101001, 0b10011001, 0b10011001, 0b01100000}; +const uint8_t font_P[] PROGMEM = {cords(4, 0, 4), 0b11101001, 0b10011110, 0b10001000, 0b10000000}; +const uint8_t font_Q[] PROGMEM = {cords(5, 0, 5), 0b01100100, 0b10100101, 0b00101001, 0b01011001, 0b10100000}; +const uint8_t font_R[] PROGMEM = {cords(4, 0, 4), 0b11101001, 0b10011110, 0b11001010, 0b10010000}; +const uint8_t font_S[] PROGMEM = {cords(4, 0, 4), 0b01101000, 0b10000110, 0b00010001, 0b01100000}; +const uint8_t font_T[] PROGMEM = {cords(5, 0, 5), 0b11111001, 0b00001000, 0b01000010, 0b00010000, 0b10000000}; +const uint8_t font_U[] PROGMEM = {cords(4, 0, 4), 0b10011001, 0b10011001, 0b10011001, 0b01100000}; +const uint8_t font_V[] PROGMEM = {cords(3, 0, 3), 0b10110110, 0b11011011, 0b01010000}; +const uint8_t font_W[] PROGMEM = {cords(5, 0, 5), 0b10001100, 0b01101011, 0b01011010, 0b11010101, 0b01000000}; +const uint8_t font_X[] PROGMEM = {cords(5, 0, 5), 0b10001010, 0b10010100, 0b01000101, 0b00101010, 0b00100000}; +const uint8_t font_Y[] PROGMEM = {cords(5, 0, 5), 0b10001010, 0b10010100, 0b01000010, 0b00010000, 0b10000000}; +const uint8_t font_Z[] PROGMEM = {cords(5, 0, 5), 0b11111000, 0b01000100, 0b01000100, 0b01000011, 0b11100000}; +const uint8_t font_a[] PROGMEM = {cords(5, 2, 3), 0b01100001, 0b01111001, 0b01100000}; +const uint8_t font_b[] PROGMEM = {cords(4, 0, 4), 0b10001000, 0b10001110, 0b10011001, 0b11100000}; +const uint8_t font_c[] PROGMEM = {cords(3, 2, 2), 0b01110010, 0b01000110}; +const uint8_t font_d[] PROGMEM = {cords(4, 0, 4), 0b00010001, 0b00010111, 0b10011001, 0b01110000}; +const uint8_t font_e[] PROGMEM = {cords(4, 2, 3), 0b01101001, 0b11101000, 0b01100000}; +const uint8_t font_f[] PROGMEM = {cords(4, 0, 4), 0b00100101, 0b01000100, 0b11100100, 0b01000000}; +const uint8_t font_g[] PROGMEM = {cords(4, 2, 3), 0b01111001, 0b01110001, 0b01100000}; +const uint8_t font_h[] PROGMEM = {cords(3, 0, 3), 0b10010010, 0b01101011, 0b01101000}; +const uint8_t font_i[] PROGMEM = {cords(1, 2, 1), 0b10111000}; +const uint8_t font_j[] PROGMEM = {cords(3, 2, 2), 0b00100000, 0b11010100}; +const uint8_t font_k[] PROGMEM = {cords(3, 0, 3), 0b10010010, 0b01011101, 0b01101000}; +const uint8_t font_l[] PROGMEM = {cords(2, 0, 2), 0b10101010, 0b10100100}; +const uint8_t font_m[] PROGMEM = {cords(5, 2, 4), 0b11110101, 0b01101011, 0b01011010, 0b10000000}; +const uint8_t font_n[] PROGMEM = {cords(4, 2, 3), 0b11101001, 0b10011001, 0b10010000}; +const uint8_t font_o[] PROGMEM = {cords(4, 2, 3), 0b01101001, 0b10011001, 0b01100000}; +const uint8_t font_p[] PROGMEM = {cords(4, 2, 3), 0b11101001, 0b11101000, 0b10000000}; +const uint8_t font_q[] PROGMEM = {cords(4, 2, 3), 0b01111001, 0b01110001, 0b00010000}; +const uint8_t font_r[] PROGMEM = {cords(4, 2, 3), 0b10101101, 0b10001000, 0b10000000}; +const uint8_t font_s[] PROGMEM = {cords(4, 2, 3), 0b01101000, 0b01100001, 0b01100000}; +const uint8_t font_t[] PROGMEM = {cords(4, 0, 4), 0b01000100, 0b11100100, 0b01000101, 0b00100000}; +const uint8_t font_u[] PROGMEM = {cords(4, 2, 3), 0b10011001, 0b10011001, 0b01110000}; +const uint8_t font_v[] PROGMEM = {cords(3, 2, 2), 0b10110110, 0b11010100}; +const uint8_t font_w[] PROGMEM = {cords(5, 2, 3), 0b10001100, 0b01101011, 0b01010101}; +const uint8_t font_x[] PROGMEM = {cords(3, 2, 2), 0b10110101, 0b01011010}; +const uint8_t font_y[] PROGMEM = {cords(3, 2, 2), 0b10110101, 0b10011100}; +const uint8_t font_z[] PROGMEM = {cords(3, 2, 2), 0b11100101, 0b01001110}; + +const uint8_t* const font[] PROGMEM = { font_space, font_notdef, font_dot, font_comma, font_exclamation, font_question, + font_num0, font_num1, font_num2, font_num3, font_num4, font_num5, font_num6, font_num7, font_num8, font_num9, + font_A, font_a, font_B, font_b, font_C, font_c, font_D, font_d, font_E, font_e, font_F, font_f, font_G, font_g, + font_H, font_h, font_I, font_i, font_J, font_j, font_K, font_k, font_L, font_l, font_M, font_m, font_N, font_n, + font_O, font_o, font_P, font_p, font_Q, font_q, font_R, font_r, font_S, font_s, font_T, font_t, font_U, font_u, + font_V, font_v, font_W, font_w, font_X, font_x, font_Y, font_y, font_Z, font_z}; \ No newline at end of file diff --git a/Dashboard/textbox.h b/Dashboard/textbox.h new file mode 100644 index 0000000000000000000000000000000000000000..c0384fe2766affd6813be08501e46ee39d66c840 --- /dev/null +++ b/Dashboard/textbox.h @@ -0,0 +1,155 @@ +#pragma once + +#define TB_DISABLED 0 +#define TB_STATIC 1 +#define TB_REPEAT 2 +#define TB_LOOP 3 +#define TB_LOOP_WITH_DELAY 4 +#define TB_BOUNCE 5 + +class textbox +{ +private: + /* data */ + uint8_t x; + uint8_t y; + uint8_t w; + uint8_t mode; + uint8_t speed; + uint16_t delay; + uint16_t offset; + char text[64]; + uint8_t letter[8]; + uint64_t lang; + void getLetter(char c); +public: + textbox(void); + void setup(char _text[], uint8_t _mode, uint8_t _x, uint8_t _y, uint8_t _w, uint8_t _speed = 0, uint16_t _delay = 0); + void render(void); + void disable(void); +}; + +textbox::textbox(void) +{ + x = 0; + y = 0; + w = 0; + mode = 0; + speed = 0; + delay = 0; + memset(text, NULL, 64 * sizeof(char)); + lang = 0; +} + +void textbox::setup(char _text[], uint8_t _mode, uint8_t _x, uint8_t _y, uint8_t _w, uint8_t _speed = 0, uint16_t _delay = 0) +{ + strcpy(text, _text); + mode = _mode; + x = _x; + y = _y; + w = _w; + offset = 0; + switch(mode) + { + case TB_LOOP: + delay = 0; + goto NO_DELAY; + case TB_REPEAT: + case TB_LOOP_WITH_DELAY: + case TB_BOUNCE: + delay = _delay; + NO_DELAY: + speed = _speed; + break; + case TB_DISABLED: + case TB_STATIC: + default: + speed = 0; + delay = 0; + break; + } + render(); +} + +void textbox::render(void) +{ + if(mode == TB_DISABLED) return; + uint8_t index = 0; + uint8_t position = 0; + while(position < 16) + { + getLetter(text[index]); + uint8_t y = letter[1]; + uint8_t x = 0; + uint8_t maxX = letter[0]; + for(uint8_t i = 0; i < letter[2]; i++) + { + for(int8_t j = 7; j >= 0; j--) + { + //char sprf[25]; + uint8_t state = bitRead(letter[i + 3], j); + //sprintf(sprf, "%d %d %d %d %d %d %d\n", index, letter[0], letter[1], letter[2], i, j, state); + //Serial.print(sprf); + matrix.set(matrix.getPixNumber(x + position, y), mHSVfast((index + 1) * 10, 255, 255)); + x++; + if(x >= maxX) + { + x = 0; y++; + } + if(y > 6) goto BREAKFORS; + } + } + BREAKFORS: + position += maxX; + index++; + } + +} + +void textbox::disable(void) +{ + setup("", TB_DISABLED, 0, 0, 0); +} + +void textbox::getLetter(char c) +{ + memset(letter, 0, 8 * sizeof(uint8_t)); + uint8_t index; + uint8_t ctoi = (uint8_t)c; + if(ctoi >= 65 && ctoi <= 90) index = 16 + 2 * (ctoi - 65); + else if(ctoi >= 97 && ctoi <= 122) index = 17 + 2 * (ctoi - 97); + else if(ctoi >= 48 && ctoi <= 57) index = ctoi - 42; + else switch(ctoi) + { + case 32: + index = 0; + break; + case 46: + index = 2; + break; + case 44: + index = 3; + break; + case 33: + index = 4; + break; + case 63: + index = 5; + break; + default: + index = 1; + break; + } + Serial.println(index); + uint8_t readed = pgm_read_byte(font[index][0]); + Serial.println(readed); + letter[0] = readed / 49 + 1; // width + letter[1] = readed % 7; // offset + letter[2] = readed / 7 % 7; // bytes + for(uint8_t i = 0; i < letter[2]; i++) + { + letter[i + 3] = pgm_read_byte(font[index][i + 1]); + Serial.println(letter[i + 3]); + } + Serial.println(); +} \ No newline at end of file