2021-06-22 16:01:00 +02:00
|
|
|
#if CONFIG_DISPLAY
|
2021-05-28 14:36:46 +02:00
|
|
|
#include <device.h>
|
|
|
|
#include <drivers/display.h>
|
|
|
|
#include <lvgl.h>
|
2021-06-02 17:22:38 +02:00
|
|
|
#endif
|
2021-05-28 14:36:46 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <zephyr.h>
|
|
|
|
|
2021-06-02 17:20:54 +02:00
|
|
|
#include "display.h"
|
|
|
|
|
2021-06-22 15:48:03 +02:00
|
|
|
K_THREAD_STACK_DEFINE(display_stack_area, 5000);
|
|
|
|
|
2021-06-22 16:01:00 +02:00
|
|
|
#if CONFIG_DISPLAY
|
2021-05-28 14:36:46 +02:00
|
|
|
const struct device* display_dev;
|
|
|
|
lv_obj_t* display_center_pane;
|
|
|
|
lv_obj_t* display_top_bar;
|
|
|
|
lv_obj_t* display_bot_bar;
|
|
|
|
lv_obj_t* display_contacts_label;
|
|
|
|
lv_obj_t* display_risk_contacts_label;
|
|
|
|
lv_obj_t* risk_contacts_button;
|
|
|
|
lv_obj_t* display_clock_label;
|
|
|
|
lv_obj_t* display_battery_label;
|
|
|
|
lv_obj_t* display_memory_label;
|
|
|
|
lv_obj_t* display_msg_label;
|
|
|
|
lv_style_t green_button_style;
|
|
|
|
lv_style_t yellow_button_style;
|
|
|
|
lv_style_t red_button_style;
|
2021-06-02 17:22:38 +02:00
|
|
|
#endif
|
2021-05-28 14:36:46 +02:00
|
|
|
|
2021-06-14 15:44:07 +02:00
|
|
|
|
2021-05-28 14:36:46 +02:00
|
|
|
int get_battery_percentage() {
|
2021-06-17 11:37:18 +02:00
|
|
|
// TODO: Implement
|
|
|
|
return 0;
|
2021-05-28 14:36:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int get_memory_percentage() {
|
2021-06-17 11:37:18 +02:00
|
|
|
// TODO: Implement
|
|
|
|
return 0;
|
2021-05-28 14:36:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int get_time() {
|
2021-06-17 11:37:18 +02:00
|
|
|
// TODO: Implement
|
|
|
|
return 0;
|
2021-05-28 14:36:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int get_contacts() {
|
2021-06-17 11:37:18 +02:00
|
|
|
// TODO: Implement
|
|
|
|
return 0;
|
2021-05-28 14:36:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int get_risk_contacts() {
|
2021-06-17 11:37:18 +02:00
|
|
|
// TODO: Implement
|
|
|
|
return 0;
|
2021-05-28 14:36:46 +02:00
|
|
|
}
|
|
|
|
|
2021-06-22 16:01:00 +02:00
|
|
|
#if CONFIG_DISPLAY
|
2021-06-22 15:51:34 +02:00
|
|
|
|
|
|
|
void display_thread(void* arg1, void* arg2, void* arg3) {
|
2021-06-22 15:54:08 +02:00
|
|
|
static uint32_t sleep_time;
|
2021-06-22 15:51:34 +02:00
|
|
|
while (1) {
|
2021-06-22 15:54:08 +02:00
|
|
|
sleep_time = lv_task_handler();
|
2021-06-22 15:51:34 +02:00
|
|
|
update_display();
|
2021-06-22 15:54:08 +02:00
|
|
|
k_msleep(sleep_time);
|
2021-06-22 15:51:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-28 14:36:46 +02:00
|
|
|
int init_styles() {
|
|
|
|
lv_style_init(&green_button_style);
|
|
|
|
lv_style_init(&yellow_button_style);
|
|
|
|
lv_style_init(&red_button_style);
|
|
|
|
|
2021-06-17 11:37:18 +02:00
|
|
|
// Properties for all styles
|
2021-05-28 14:36:46 +02:00
|
|
|
lv_style_set_bg_opa(&green_button_style, LV_STATE_DEFAULT, LV_OPA_COVER);
|
|
|
|
lv_style_set_pad_top(&green_button_style, LV_STATE_DEFAULT, 10);
|
|
|
|
lv_style_set_pad_bottom(&green_button_style, LV_STATE_DEFAULT, 10);
|
|
|
|
lv_style_set_pad_left(&green_button_style, LV_STATE_DEFAULT, 10);
|
|
|
|
lv_style_set_pad_right(&green_button_style, LV_STATE_DEFAULT, 10);
|
|
|
|
lv_style_set_border_width(&green_button_style, LV_STATE_DEFAULT, 1);
|
|
|
|
lv_style_set_radius(&green_button_style, LV_STATE_DEFAULT, 10);
|
|
|
|
|
|
|
|
lv_style_copy(&yellow_button_style, &green_button_style);
|
|
|
|
lv_style_copy(&red_button_style, &green_button_style);
|
|
|
|
|
2021-06-17 11:37:18 +02:00
|
|
|
// Set different colors
|
2021-05-28 14:36:46 +02:00
|
|
|
lv_style_set_bg_color(&green_button_style, LV_STATE_DEFAULT, LV_COLOR_GREEN);
|
|
|
|
lv_style_set_text_color(&green_button_style, LV_STATE_DEFAULT, LV_COLOR_WHITE);
|
|
|
|
lv_style_set_bg_color(&yellow_button_style, LV_STATE_DEFAULT, LV_COLOR_YELLOW);
|
|
|
|
lv_style_set_text_color(&yellow_button_style, LV_STATE_DEFAULT, LV_COLOR_BLACK);
|
|
|
|
lv_style_set_bg_color(&red_button_style, LV_STATE_DEFAULT, LV_COLOR_RED);
|
|
|
|
lv_style_set_text_color(&red_button_style, LV_STATE_DEFAULT, LV_COLOR_WHITE);
|
2021-06-22 15:51:34 +02:00
|
|
|
|
2021-05-28 14:36:46 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int update_display() {
|
2021-06-02 17:20:54 +02:00
|
|
|
display_set_contacts(get_contacts());
|
|
|
|
display_set_risk_contacts(get_risk_contacts());
|
2021-06-02 17:22:38 +02:00
|
|
|
display_set_time(get_time());
|
2021-06-02 17:20:54 +02:00
|
|
|
display_set_bat(get_battery_percentage());
|
|
|
|
display_set_mem(get_memory_percentage());
|
2021-05-28 14:36:46 +02:00
|
|
|
|
|
|
|
lv_task_handler();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int init_display() {
|
|
|
|
init_styles();
|
|
|
|
|
|
|
|
display_dev = device_get_binding(CONFIG_LVGL_DISPLAY_DEV_NAME);
|
|
|
|
|
|
|
|
if (display_dev == NULL) {
|
2021-06-02 17:22:38 +02:00
|
|
|
printk("device not found. Aborting test.");
|
2021-05-28 14:36:46 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
display_top_bar = lv_cont_create(lv_scr_act(), NULL);
|
|
|
|
lv_obj_set_width(display_top_bar, lv_obj_get_width(lv_scr_act()));
|
|
|
|
lv_cont_set_layout(display_top_bar, LV_LAYOUT_PRETTY_TOP);
|
|
|
|
|
|
|
|
display_bot_bar = lv_cont_create(lv_scr_act(), NULL);
|
|
|
|
lv_obj_set_width(display_bot_bar, lv_obj_get_width(lv_scr_act()));
|
|
|
|
lv_cont_set_layout(display_bot_bar, LV_LAYOUT_PRETTY_BOTTOM);
|
|
|
|
|
|
|
|
display_center_pane = lv_cont_create(lv_scr_act(), NULL);
|
|
|
|
lv_obj_align(display_center_pane, display_top_bar, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0);
|
|
|
|
lv_obj_set_width(display_center_pane, lv_obj_get_width(lv_scr_act()));
|
|
|
|
lv_obj_set_height(display_center_pane, lv_obj_get_height(lv_scr_act()) - lv_obj_get_height(display_top_bar) - lv_obj_get_height(display_bot_bar));
|
|
|
|
lv_cont_set_layout(display_center_pane, LV_LAYOUT_COLUMN_MID);
|
|
|
|
|
|
|
|
lv_obj_align(display_bot_bar, display_center_pane, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0);
|
|
|
|
|
|
|
|
display_contacts_label = lv_label_create(display_center_pane, NULL);
|
|
|
|
lv_obj_set_height_margin(display_contacts_label, 20);
|
|
|
|
lv_label_set_text(display_contacts_label, "");
|
|
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_LVGL_POINTER_KSCAN)) {
|
|
|
|
risk_contacts_button = lv_btn_create(display_center_pane, NULL);
|
|
|
|
lv_btn_set_fit(risk_contacts_button, LV_FIT_TIGHT);
|
|
|
|
display_risk_contacts_label = lv_label_create(risk_contacts_button, NULL);
|
|
|
|
} else {
|
|
|
|
display_risk_contacts_label = lv_label_create(display_center_pane, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
lv_obj_set_height_margin(display_risk_contacts_label, 20);
|
|
|
|
lv_label_set_text(display_risk_contacts_label, "");
|
|
|
|
|
|
|
|
display_memory_label = lv_label_create(display_top_bar, NULL);
|
|
|
|
lv_obj_set_width_margin(display_memory_label, 10);
|
|
|
|
lv_label_set_text(display_memory_label, "");
|
|
|
|
|
|
|
|
display_clock_label = lv_label_create(display_top_bar, NULL);
|
|
|
|
lv_obj_set_width_margin(display_clock_label, 10);
|
|
|
|
lv_label_set_text(display_clock_label, "");
|
|
|
|
|
|
|
|
display_battery_label = lv_label_create(display_top_bar, NULL);
|
|
|
|
lv_obj_set_width_margin(display_battery_label, 10);
|
|
|
|
lv_label_set_text(display_battery_label, "");
|
|
|
|
|
|
|
|
display_msg_label = lv_label_create(display_bot_bar, NULL);
|
|
|
|
lv_label_set_text(display_msg_label, "");
|
|
|
|
|
2021-06-22 15:48:03 +02:00
|
|
|
static struct k_thread display_thread_data;
|
|
|
|
k_thread_create(&display_thread_data, display_stack_area, K_THREAD_STACK_SIZEOF(display_stack_area), display_thread, NULL, NULL, NULL, 0, 0, K_NO_WAIT);
|
|
|
|
|
2021-05-28 14:36:46 +02:00
|
|
|
display_blanking_off(display_dev);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int display_set_message(char* msg) {
|
|
|
|
lv_label_set_text(display_msg_label, msg);
|
|
|
|
return 0;
|
2021-06-02 17:20:54 +02:00
|
|
|
}
|
|
|
|
|
2021-06-02 17:22:38 +02:00
|
|
|
int display_set_time(int time) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-06-02 17:20:54 +02:00
|
|
|
int display_set_bat(int bat) {
|
|
|
|
lv_label_set_text_fmt(display_battery_label, "Bat: %d%%", bat);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int display_set_mem(int mem) {
|
|
|
|
lv_label_set_text_fmt(display_memory_label, "Mem: %d%%", mem);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int display_set_contacts(int contacts) {
|
2021-06-22 15:48:03 +02:00
|
|
|
lv_label_set_text_fmt(display_contacts_label, "Number of contacts: %d,\nfrom which", contacts);
|
2021-06-02 17:20:54 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int display_set_risk_contacts(int risk_contacts) {
|
2021-06-17 14:51:28 +02:00
|
|
|
lv_label_set_text_fmt(display_risk_contacts_label, "%d are risk contacts.", risk_contacts);
|
2021-06-02 17:20:54 +02:00
|
|
|
|
|
|
|
if (risk_contacts == 0) {
|
|
|
|
// Set Button green
|
|
|
|
lv_obj_reset_style_list(risk_contacts_button, LV_OBJ_PART_MAIN);
|
|
|
|
lv_obj_add_style(risk_contacts_button, LV_BTN_PART_MAIN, &green_button_style);
|
|
|
|
} else if (risk_contacts < 5) {
|
|
|
|
// Set Button yellow
|
|
|
|
lv_obj_reset_style_list(risk_contacts_button, LV_OBJ_PART_MAIN);
|
|
|
|
lv_obj_add_style(risk_contacts_button, LV_BTN_PART_MAIN, &yellow_button_style);
|
|
|
|
} else {
|
|
|
|
// Set Button red
|
|
|
|
lv_obj_reset_style_list(risk_contacts_button, LV_OBJ_PART_MAIN);
|
|
|
|
lv_obj_add_style(risk_contacts_button, LV_BTN_PART_MAIN, &red_button_style);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2021-06-17 14:51:28 +02:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
2021-06-22 15:51:34 +02:00
|
|
|
void display_thread(void* arg1, void* arg2, void* arg3) {
|
|
|
|
// Do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
int init_styles() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int update_display() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int init_display() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-06-17 14:51:28 +02:00
|
|
|
int display_set_message(char* msg) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int display_set_time(int time) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int display_set_bat(int bat) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int display_set_mem(int mem) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int display_set_contacts(int contacts) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int display_set_risk_contacts(int risk_contacts) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|