Skip to content

Commit

Permalink
[app] setting page
Browse files Browse the repository at this point in the history
  • Loading branch information
morris13579 committed May 18, 2023
1 parent c41d0f9 commit 6d46d8a
Show file tree
Hide file tree
Showing 41 changed files with 2,680 additions and 209 deletions.
1 change: 1 addition & 0 deletions 1.Firmware/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.pio
.vscode
src/secrets.h
4 changes: 4 additions & 0 deletions 1.Firmware/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ lib_deps =
moononournation/GFX Library for Arduino@1.2.1
askuric/Simple FOC@2.2.3
knolleary/PubSubClient@^2.8
https://github.com/bblanchon/ArduinoJson
https://github.com/me-no-dev/AsyncTCP
https://github.com/me-no-dev/ESPAsyncWebServer

1 change: 1 addition & 0 deletions 1.Firmware/src/app/Accounts/ACT_Def.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ typedef struct
{
Motor_Cmd_t cmd;
int motor_mode;
int init_position;
} Motor_Info_t;

/* SysConfig */
Expand Down
2 changes: 1 addition & 1 deletion 1.Firmware/src/app/Accounts/ACT_Motor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static int onEvent(Account* account, Account::EventParam_t* param)
{
case MOTOR_CMD_CHANGE_MODE:
/* code */
HAL::update_motor_mode(info->motor_mode);
HAL::update_motor_mode(info->motor_mode , info->init_position);
HAL::motor_shake(2, 2);
break;
case MOTOR_CMD_CHECKOUT_PAGE:
Expand Down
10 changes: 6 additions & 4 deletions 1.Firmware/src/app/Pages/AppFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "Playground/Playground.h"
#include "HASS/Hass.h"
#include "SurfaceDial/SurfaceDial.h"
#include "Setting/Setting.h"

// #include "Scene3D/Scene3D.h"

Expand All @@ -43,10 +44,11 @@ PageBase* AppFactory::CreatePage(const char* name)
{
APP_CLASS_MATCH(Template);
APP_CLASS_MATCH(Menu);
APP_CLASS_MATCH(Playground);
APP_CLASS_MATCH(SurfaceDial);
APP_CLASS_MATCH(Startup);
APP_CLASS_MATCH(Hass);
APP_CLASS_MATCH(Playground);
APP_CLASS_MATCH(SurfaceDial);
APP_CLASS_MATCH(Startup);
APP_CLASS_MATCH(Hass);
APP_CLASS_MATCH(Setting);
// APP_CLASS_MATCH(Scene3D);

return nullptr;
Expand Down
11 changes: 7 additions & 4 deletions 1.Firmware/src/app/Pages/HASS/Hass.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "Hass.h"
#include "hal/hal.h"
#include "config.h"
#include "hal/nvs.h"

using namespace Page;

Expand All @@ -21,8 +22,11 @@ void hass_hal_init(void)
int hass_hal_send(const char *device_name, int knob_value)
{
char topic_name[128];

snprintf(topic_name, sizeof(topic_name),"%s/HOME/%s", MQTT_HOST, device_name);
String password,host,username,topic;
uint16_t port;
get_mqtt_config(host,port,username,password,topic);
const char * mqtt_topic = topic.c_str();
snprintf(topic_name, sizeof(topic_name),"%s/HOME/%s", mqtt_topic, device_name);
if (knob_value < HASS_MAX && playload_str[knob_value] != NULL) {
printf("mqtt send: %s:%s\n", topic_name, playload_str[knob_value]);
return HAL::mqtt_publish(topic_name, playload_str[knob_value]);
Expand Down Expand Up @@ -144,8 +148,7 @@ void Hass::HassEventHandler(lv_event_t* event, lv_event_code_t code)
((HassView*)View)->UpdateFocusedDevice(lv_label_get_text(label));
}
}
if (code == LV_EVENT_SHORT_CLICKED)
{
if (code == LV_EVENT_SHORT_CLICKED) {
if (!lv_obj_has_state(obj, LV_STATE_EDITED)) {
if (label != NULL) {
printf("Control device: %s\n", lv_label_get_text(label));
Expand Down
200 changes: 100 additions & 100 deletions 1.Firmware/src/app/Pages/HASS/HassView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
using namespace Page;
#define ITEM_PAD 60
/*
* 默认视图显示: 圆点,原点所在位置 label_value
* 此函数根据需要增加或 hidden 对象
* 默认视图显示: 圆点,原点所在位置 label_value
* 此函数根据需要增加或 hidden 对象
*/
void HassView::SetPlaygroundMode(int16_t mode)
{
Expand All @@ -27,8 +27,8 @@ void HassView::SetCtrView(lv_obj_t* obj)

if (device->is_set_value) {
/*
* temporarily no display
* we can't get the status of the device
* temporarily no display
* we can't get the status of the device
*/
} if (!device->is_set_value && device->is_on_off) {
PlaygroundView::OnOffView();
Expand All @@ -38,21 +38,21 @@ void HassView::SetCtrView(lv_obj_t* obj)
lv_obj_set_style_bg_opa(obj, LV_OPA_COVER, 0);
}
/*
* Gets the name of the controlled device
* Gets the name of the controlled device
*/
char* HassView::GetEditedDeviceName(void)
{
std::map<lv_obj_t*, device_t *>::iterator iter;
iter = device_map.begin();
while(iter != device_map.end()) {
if (lv_obj_has_state(iter->first, LV_STATE_EDITED)) {
iter = device_map.begin();
while(iter != device_map.end()) {
if (lv_obj_has_state(iter->first, LV_STATE_EDITED)) {
lv_obj_t* label = lv_obj_get_child(iter->first, 1);
if (label != NULL) {
return lv_label_get_text(label);
}
}
iter++;
}
}
return NULL;
}

Expand All @@ -63,8 +63,8 @@ void HassView::ClearCtrView(lv_obj_t *obj)

if (device->is_set_value) {
/*
* temporarily no display
* we can't get the status of the device
* temporarily no display
* we can't get the status of the device
*/
} if (!device->is_set_value && device->is_on_off) {
PlaygroundView::DefaultView();
Expand Down Expand Up @@ -114,39 +114,39 @@ void HassView::UpdateView(HassInfo* info)
}

void HassView::device_item_create(
device_t* item,
device_t* item,
lv_obj_t* par,
const char* name,
const char* img_src,
bool is_on_off,
bool is_set_value)
{

lv_obj_t *cont = lv_obj_create(par);
// lv_obj_remove_style_all(cont);
// lv_obj_set_size(cont, 42, 62);
lv_obj_clear_flag(cont, LV_OBJ_FLAG_SCROLLABLE);
lv_obj_t *cont = lv_obj_create(par);
// lv_obj_remove_style_all(cont);
// lv_obj_set_size(cont, 42, 62);
lv_obj_clear_flag(cont, LV_OBJ_FLAG_SCROLLABLE);

lv_obj_set_flex_flow(cont, LV_FLEX_FLOW_COLUMN);
lv_obj_set_flex_flow(cont, LV_FLEX_FLOW_COLUMN);

lv_obj_t *img = lv_img_create(cont);
lv_img_set_src(img, Resource.GetImage(img_src));
// lv_obj_set_size(img, 42, 42);
lv_obj_set_style_img_recolor_opa(img, LV_OPA_COVER, 0);
lv_obj_set_style_img_recolor(img, lv_color_white(), 0);
lv_obj_t *img = lv_img_create(cont);
lv_img_set_src(img, Resource.GetImage(img_src));
// lv_obj_set_size(img, 42, 42);
lv_obj_set_style_img_recolor_opa(img, LV_OPA_COVER, 0);
lv_obj_set_style_img_recolor(img, lv_color_white(), 0);

item->l_dev_name = lv_label_create(cont);
lv_label_set_text_fmt(item->l_dev_name, "%s", name);
lv_obj_set_size(item->l_dev_name, 0, 0);
item->l_dev_name = lv_label_create(cont);
lv_label_set_text_fmt(item->l_dev_name, "%s", name);
lv_obj_set_size(item->l_dev_name, 0, 0);

lv_obj_add_style(cont, &style.focus, LV_STATE_FOCUSED);
lv_obj_add_style(cont, &style.cont, 0);
lv_obj_add_style(cont, &style.focus, LV_STATE_FOCUSED);
lv_obj_add_style(cont, &style.cont, 0);

lv_obj_add_style(cont, &style.edit, LV_STATE_EDITED);
item->cont = cont;
lv_obj_add_style(cont, &style.edit, LV_STATE_EDITED);
item->cont = cont;

lv_obj_set_flex_align(
lv_obj_set_flex_align(
cont,
LV_FLEX_ALIGN_CENTER,
LV_FLEX_ALIGN_CENTER,
Expand All @@ -156,7 +156,7 @@ void HassView::device_item_create(
item->is_on_off = is_on_off;
item->is_set_value = is_set_value;
device_map[cont] = item;
// lv_obj_add_event_cb(item->cont, on_event, LV_EVENT_ALL, NULL);
// lv_obj_add_event_cb(item->cont, on_event, LV_EVENT_ALL, NULL);
printf("create an item: %p\n", item);
}

Expand All @@ -165,7 +165,7 @@ void on_focus(lv_group_t* g)
lv_obj_t* cont = lv_group_get_focused(g);
lv_obj_t* cont_row = lv_obj_get_parent(cont);
lv_coord_t x = lv_obj_get_x(cont);
lv_coord_t width = lv_obj_get_width(cont);
lv_coord_t width = lv_obj_get_width(cont);
lv_obj_scroll_to_x(cont_row, x, LV_ANIM_ON);
}

Expand All @@ -184,28 +184,28 @@ void HassView::group_init(void)

void HassView::style_init(void)
{
lv_style_init(&style.cont);
lv_style_set_width(&style.cont, ITEM_PAD);
lv_style_set_height(&style.cont, ITEM_PAD+10);
lv_style_set_bg_color(&style.cont, lv_color_black());
lv_style_set_bg_opa(&style.cont, LV_OPA_TRANSP);
lv_style_set_text_font(&style.cont, Resource.GetFont("bahnschrift_17"));
lv_style_set_text_color(&style.cont, lv_color_white());
lv_style_init(&style.cont);
lv_style_set_width(&style.cont, ITEM_PAD);
lv_style_set_height(&style.cont, ITEM_PAD+10);
lv_style_set_bg_color(&style.cont, lv_color_black());
lv_style_set_bg_opa(&style.cont, LV_OPA_TRANSP);
lv_style_set_text_font(&style.cont, Resource.GetFont("bahnschrift_17"));
lv_style_set_text_color(&style.cont, lv_color_white());

lv_style_init(&style.focus);
lv_style_set_border_side(&style.focus, LV_BORDER_SIDE_FULL);
lv_style_set_border_width(&style.focus, 2);
lv_style_set_border_color(&style.focus, lv_color_hex(0x9130CC));
// lv_obj_set_flex_flow(&style.cont, LV_FLEX_FLOW_COLUMN);
lv_style_init(&style.focus);
lv_style_set_border_side(&style.focus, LV_BORDER_SIDE_FULL);
lv_style_set_border_width(&style.focus, 2);
lv_style_set_border_color(&style.focus, lv_color_hex(0x9130CC));
// lv_obj_set_flex_flow(&style.cont, LV_FLEX_FLOW_COLUMN);

lv_style_init(&style.edit);
lv_style_init(&style.edit);

// lv_style_img_recolor_opa(&style.edit, LV_OPA_COVER);
// lv_style_img_recolor(&style.edit, lv_color_hex(0xFF0633));
lv_style_set_bg_color(&style.edit, lv_color_hex(0x870AEA));
// lv_style_img_recolor_opa(&style.edit, LV_OPA_COVER);
// lv_style_img_recolor(&style.edit, lv_color_hex(0xFF0633));
lv_style_set_bg_color(&style.edit, lv_color_hex(0x870AEA));


// static const lv_style_prop_t style_prop[] =
// static const lv_style_prop_t style_prop[] =
// {
// LV_STYLE_WIDTH,
// LV_STYLE_PROP_INV
Expand All @@ -232,73 +232,73 @@ void HassView::Create(lv_obj_t* root)
PlaygroundView::Create(root);

lv_obj_t * cont_row = lv_obj_create(root);
lv_obj_remove_style_all(cont_row);
lv_obj_set_size(cont_row, ITEM_PAD * 3, 120);
lv_obj_align(cont_row, LV_ALIGN_CENTER, 0, 5);
lv_obj_set_flex_flow(cont_row, LV_FLEX_FLOW_ROW);
lv_obj_set_flex_align(
lv_obj_remove_style_all(cont_row);
lv_obj_set_size(cont_row, ITEM_PAD * 3, 120);
lv_obj_align(cont_row, LV_ALIGN_CENTER, 0, 5);
lv_obj_set_flex_flow(cont_row, LV_FLEX_FLOW_ROW);
lv_obj_set_flex_align(
cont_row,
LV_FLEX_ALIGN_START,
LV_FLEX_ALIGN_START,
LV_FLEX_ALIGN_CENTER
);
lv_obj_set_style_pad_column(cont_row, 10, 0);
lv_obj_set_style_pad_hor(cont_row, ITEM_PAD, 0);
lv_obj_set_style_pad_column(cont_row, 10, 0);
lv_obj_set_style_pad_hor(cont_row, ITEM_PAD, 0);

// lv_obj_remove_style(obj, style, LV_PART_SCROLLBAR)
style_init();
// lv_obj_remove_style(obj, style, LV_PART_SCROLLBAR)
style_init();

m_ui = (device_ui *)malloc(sizeof(device_ui) + DEVICE_NUM * sizeof(device_t));
m_ui = (device_ui *)malloc(sizeof(device_ui) + DEVICE_NUM * sizeof(device_t));
if (m_ui == NULL) {
printf("malloc m_ui failed\n");
return;
}

device_item_create(
&(m_ui->devices[0]),
cont_row,
"Light",
"home_bulb",
true,
true
);
device_item_create(
&(m_ui->devices[0]),
cont_row,
"Light",
"home_bulb",
true,
true
);

device_item_create(
&(m_ui->devices[1]),
cont_row,
"Fan",
"home_fan",
true,
false
);

device_item_create(
&(m_ui->devices[2]),
cont_row,
"Air Conditioning",
"home_air_cond",
false,
false
);

device_item_create(
&(m_ui->devices[1]),
cont_row,
"Fan",
"home_fan",
true,
false
);

device_item_create(
&(m_ui->devices[2]),
cont_row,
"Air Conditioning",
"home_air_cond",
false,
false
);

device_item_create(
&(m_ui->devices[3]),
cont_row,
"Wash Machine",
"home_wash_machine",
false,
false
);

m_ui->foucs_label = lv_label_create(root);
&(m_ui->devices[3]),
cont_row,
"Wash Machine",
"home_wash_machine",
false,
false
);

m_ui->foucs_label = lv_label_create(root);
lv_obj_add_style(m_ui->foucs_label, &style.label_name, 0);
lv_label_set_text_fmt(m_ui->foucs_label, "%s", "NONE");
lv_obj_align(m_ui->foucs_label, LV_ALIGN_CENTER, 0, ITEM_PAD+10);
lv_label_set_text_fmt(m_ui->foucs_label, "%s", "NONE");
lv_obj_align(m_ui->foucs_label, LV_ALIGN_CENTER, 0, ITEM_PAD+10);

// lv_obj_set_size(m_ui->foucs_label, 42, 20);
// lv_obj_center(m_ui->foucs_label);
// lv_obj_set_size(m_ui->foucs_label, 42, 20);
// lv_obj_center(m_ui->foucs_label);

group_init();
group_init();
}


Expand Down
Loading

0 comments on commit 6d46d8a

Please sign in to comment.