#include "driver/gpio.h"
#include "driver/uart.h"
#include "iot_button.h"
+#include "esp_log.h"
#include "Goldelox_const4D.h"
#include "goldeloxSerial.h"
#include "task_button.h"
#include "pins.h"
+static const char* TAG = "task_lcd";
const uart_port_t uart_num = UART_NUM_1;
int g_time = 0;
gl_display_t *error_disp = NULL;
+/* list of all apps as function pointers */
+struct app_t applist[NUM_APPS] = {
+ {
+ .fn = &lcd_clock_loop,
+ .icon.width = 0,
+ .icon.height = 0,
+ .icon.data = NULL,
+ .name = "Clock"
+ },
+ {
+ .fn = &lcd_boot_flash_app,
+ .icon.width = 0,
+ .icon.height = 0,
+ .icon.data = NULL,
+ .name = "SWOS Flash"
+ }
+};
+
+/* ================================================================= */
+/* functions definitons */
void lcd_clock_draw_face(gl_display_t *);
void lcd_clock_draw_hand(gl_display_t *, uint16_t, uint16_t, uint8_t, gl_word_t);
gl_word_t txt_strw(gl_display_t *, char *);
+int write_tx(const void*, size_t);
+int read_rx(void *, size_t, uint32_t);
+int flush_rx();
+int flush_tx(uint32_t);
+void faster_baud();
+void slower_baud();
+void lcd_homepage_draw_base(gl_display_t *, uint8_t, uint8_t, uint8_t);
-
+/* ================================================================= */
int write_tx(const void *data, size_t sz) {
return uart_write_bytes(uart_num, data, sz);
/* change baud rate */
gl_setbaudWait(&disp, BAUD_600000, &faster_baud);
- lcd_boot_flash(&disp);
+ lcd_boot_flash(&disp, 1);
//lcd_clock_loop(&disp);
lcd_homepage_loop(&disp);
}
-void lcd_boot_flash(gl_display_t *disp) {
+void lcd_boot_flash(gl_display_t *disp, uint8_t ret) {
gl_gfx_BGcolour(disp, WHITE);
gl_gfx_Cls(disp);
gl_putstr(disp, (uint8_t *) "Anish &");
gl_txt_MoveCursor(disp, 11, 10);
gl_putstr(disp, (uint8_t *) "Advaith");
- ESP_ERROR_CHECK(gpio_set_level(PIN_VIBRATOR, 1));
- vTaskDelay(pdMS_TO_TICKS(500));
- ESP_ERROR_CHECK(gpio_set_level(PIN_VIBRATOR, 0));
- vTaskDelay(pdMS_TO_TICKS(1500));
+
+ if (ret) {
+ ESP_ERROR_CHECK(gpio_set_level(PIN_VIBRATOR, 1));
+ vTaskDelay(pdMS_TO_TICKS(500));
+ ESP_ERROR_CHECK(gpio_set_level(PIN_VIBRATOR, 0));
+ vTaskDelay(pdMS_TO_TICKS(1500));
+ return;
+ }
+
+
+ while(1) {
+ struct gt_btn_msg_t *btnmsg;
+ while (xQueueReceive(gt_btnq, (void *) &btnmsg, portMAX_DELAY)
+ == pdPASS) {
+ if (btnmsg->btn == GT_BTN_WHITE && btnmsg->evt
+ == BUTTON_SINGLE_CLICK) {
+ return;
+ } else if (btnmsg->btn == GT_BTN_RED && btnmsg->evt
+ == BUTTON_DOUBLE_CLICK) {
+ ESP_LOGI(TAG, "Writing diego swears lol");
+ gl_txt_BGcolour(disp, WHITE);
+ gl_txt_FGcolour(disp, GREEN);
+ gl_txt_MoveCursor(disp, 0, 0);
+ gl_putstr(disp, (uint8_t *)
+ "Diego Swears: 2");
+ }
+ }
+ }
+}
+
+
+void lcd_boot_flash_app(gl_display_t *disp) {
+ lcd_boot_flash(disp, 0);
}
}
-void lcd_homepage_loop(gl_display_t *disp) {
- uint8_t num_rows = 3;
- uint8_t num_cols = 3;
- uint8_t num_padd = APPSCR_PAD;
- lcd_clock_loop(disp);
-
+void lcd_homepage_draw_face(gl_display_t *disp, uint8_t num_rows,
+ uint8_t num_cols, uint8_t num_padd) {
gl_gfx_BGcolour(disp, BLACK);
gl_gfx_Cls(disp);
for (uint8_t i = 0; i < num_rows; ++i) {
for (uint8_t j = 0; j < num_cols; ++j) {
- /*
- printf("adding %d, %d [%d|%d|%d|%d]\n",
- i + 1, j + 1,
- APPSCR_TOPCALCW(i + 1), APPSCR_TOPCALCH(j + 1),
- APPSCR_TOPCALCW(i + 1) + APPSCR_PADCALCW(0),
- APPSCR_TOPCALCH(j + 1) + APPSCR_PADCALCH(0));
- gl_gfx_RectangleFilled(disp,
- APPSCR_TOPCALCW(i + 1), APPSCR_TOPCALCH(j + 1),
- APPSCR_TOPCALCW(i + 1) + APPSCR_PADCALCW(0),
- APPSCR_TOPCALCH(j + 1) + APPSCR_PADCALCH(0),
- WHITE);
- */
gl_gfx_RectangleFilled(disp,
APPSCR_TOPCALCVW(num_cols, num_padd, j + 1),
APPSCR_TOPCALCVH(num_rows, num_padd, i + 1),
WHITE);
}
}
- while(1)
- vTaskDelay(pdMS_TO_TICKS(1000));
+}
+
+
+void lcd_homepage_draw_color(gl_display_t *disp, uint8_t num_rows,
+ uint8_t num_cols, uint8_t num_padd, uint8_t old_r, uint8_t old_c,
+ uint8_t new_r, uint8_t new_c) {
+ gl_gfx_RectangleFilled(disp,
+ APPSCR_TOPCALCVW(num_cols, num_padd, old_c + 1),
+ APPSCR_TOPCALCVH(num_rows, num_padd, old_r + 1),
+ APPSCR_TOPCALCVW(num_cols, num_padd, old_c + 1)
+ + APPSCR_PADCALCVW(num_cols, num_padd),
+ APPSCR_TOPCALCVH(num_rows, num_padd, old_r + 1)
+ + APPSCR_PADCALCVH(num_rows, num_padd),
+ WHITE);
+ gl_gfx_RectangleFilled(disp,
+ APPSCR_TOPCALCVW(num_cols, num_padd, new_c + 1),
+ APPSCR_TOPCALCVH(num_rows, num_padd, new_r + 1),
+ APPSCR_TOPCALCVW(num_cols, num_padd, new_c + 1)
+ + APPSCR_PADCALCVW(num_cols, num_padd),
+ APPSCR_TOPCALCVH(num_rows, num_padd, new_r + 1)
+ + APPSCR_PADCALCVH(num_rows, num_padd),
+ GREEN);
+}
+
+
+void lcd_homepage_loop(gl_display_t *disp) {
+ uint8_t num_rows = 3;
+ uint8_t num_cols = 3;
+ uint8_t num_padd = APPSCR_PAD;
+ uint8_t curr_idx = num_rows * num_cols - 1;
+ lcd_clock_loop(disp);
+ lcd_homepage_draw_face(disp, num_rows, num_cols, num_padd);
+
+ while(1) {
+ struct gt_btn_msg_t *btnmsg;
+ while (xQueueReceive(gt_btnq, (void *) &btnmsg, portMAX_DELAY)
+ == pdPASS) {
+ uint16_t chw;
+ char *txt;
+ uint8_t old_idx = curr_idx;
+ if (btnmsg->btn == GT_BTN_YELLOW
+ && btnmsg->evt == BUTTON_SINGLE_CLICK) {
+ applist[curr_idx].fn(disp);
+ lcd_homepage_draw_face(disp, num_rows, num_cols, num_padd);
+ continue;
+ } else if (btnmsg->btn == GT_BTN_BLUE) {
+ if (btnmsg->evt == BUTTON_SINGLE_CLICK) {
+ curr_idx = (curr_idx + 1) % (NUM_APPS);
+ } else if (btnmsg->evt == BUTTON_DOUBLE_CLICK) {
+ curr_idx = (curr_idx + num_rows) % (NUM_APPS);
+ }
+ } else if (btnmsg->btn == GT_BTN_GREEN) {
+ if (btnmsg->evt == BUTTON_SINGLE_CLICK) {
+ curr_idx = (curr_idx + NUM_APPS - 1)
+ % (NUM_APPS);
+ } else if (btnmsg->evt == BUTTON_DOUBLE_CLICK) {
+ curr_idx = (curr_idx + NUM_APPS - num_rows)
+ % (NUM_APPS);
+ }
+ }
+ lcd_homepage_draw_color(disp, num_rows, num_cols, num_padd,
+ old_idx / num_rows, old_idx % num_rows,
+ curr_idx / num_rows, curr_idx % num_rows);
+ /* draw app name */
+ txt = applist[curr_idx].name;
+ gl_gfx_RectangleFilled(disp, 0, LCD_HHEIGHT, LCD_WIDTH, LCD_HEIGHT,
+ BLACK);
+ chw = txt_strw(disp, txt);
+ gl_gfx_MoveTo(disp, LCD_WIDTH / 2 - chw / 2, LCD_HHEIGHT
+ + APPSCR_PAD);
+ gl_txt_BGcolour(disp, BLACK);
+ gl_txt_FGcolour(disp, WHITE);
+ gl_putstr(disp, (uint8_t *) txt);
+ }
+ }
}