Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[app] setting page #12

Merged
merged 1 commit into from
May 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
26 changes: 17 additions & 9 deletions 1.Firmware/src/app/Pages/Menu/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ void Menu::onViewLoad()
AttachEvent(View.ui.switches.icon, onPlaygroundEvent);
AttachEvent(View.ui.hass.icon, onHassEvent);
AttachEvent(View.ui.system.icon, onSystemEvent);
AttachEvent(View.ui.setting.icon, onSettingEvent);
// AttachEvent(View.ui.imu.icon);
// AttachEvent(View.ui.battery.icon);
// AttachEvent(View.ui.storage.icon);
Expand Down Expand Up @@ -104,35 +105,43 @@ void Menu::onPlaygroundEvent(lv_event_t* event)
lv_event_code_t code = lv_event_get_code(event);
auto* instance = (Menu*)lv_obj_get_user_data(obj);

if (code == LV_EVENT_PRESSED)
{
if (code == LV_EVENT_PRESSED) {
// instance->Model.ChangeMotorMode(MOTOR_FINE_DETENTS);
instance->Manager->Push("Pages/Playground");
}
}


void Menu::onSystemEvent(lv_event_t* event)
{
lv_obj_t* obj = lv_event_get_target(event);
lv_event_code_t code = lv_event_get_code(event);
auto* instance = (Menu*)lv_obj_get_user_data(obj);

if (code == LV_EVENT_PRESSED)
{
if (code == LV_EVENT_PRESSED) {
Serial.printf("Power off...\n");
HAL::power_off();
}
}

void Menu::onSettingEvent(lv_event_t* event)
{
lv_obj_t* obj = lv_event_get_target(event);
lv_event_code_t code = lv_event_get_code(event);
auto* instance = (Menu*)lv_obj_get_user_data(obj);
if (code == LV_EVENT_PRESSED) {
printf("Menu: onSystemEvent LV_EVENT_PRESSED\n");
instance->Manager->Push("Pages/Setting");
}
}


void Menu::onSuperDialEvent(lv_event_t* event)
{
lv_obj_t* obj = lv_event_get_target(event);
lv_event_code_t code = lv_event_get_code(event);
auto* instance = (Menu*)lv_obj_get_user_data(obj);

if (code == LV_EVENT_PRESSED)
{
if (code == LV_EVENT_PRESSED) {
// instance->Model.ChangeMotorMode(MOTOR_FINE_DETENTS);
// int16_t mode = APP_MODE_SUPER_DIAL;
// Stash_t stash;
Expand All @@ -149,8 +158,7 @@ void Menu::onHassEvent(lv_event_t* event)
lv_event_code_t code = lv_event_get_code(event);
auto* instance = (Menu*)lv_obj_get_user_data(obj);

if (code == LV_EVENT_SHORT_CLICKED)
{
if (code == LV_EVENT_SHORT_CLICKED) {
printf("Menu: onHassEvent LV_EVENT_PRESSED\n");
instance->Manager->Push("Pages/Hass");
}
Expand Down
1 change: 1 addition & 0 deletions 1.Firmware/src/app/Pages/Menu/Menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class Menu : public PageBase
static void onSuperDialEvent(lv_event_t* event);
static void onSystemEvent(lv_event_t* event);
static void onHassEvent(lv_event_t* event);
static void onSettingEvent(lv_event_t* event);
private:
MenuView View;
MenuModel Model;
Expand Down
15 changes: 13 additions & 2 deletions 1.Firmware/src/app/Pages/Menu/MenuView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ void MenuView::Create(lv_obj_t* root)
"Return-to-center\n"
"Fine values\n"
"Coarse values\n"


);
Item_Create(
&ui.hass,
Expand All @@ -62,6 +60,7 @@ void MenuView::Create(lv_obj_t* root)
"Fan \n"
"Monitor Bar"
);
// /* Item Setting */
// /* Item System */
Item_Create(
&ui.system,
Expand All @@ -76,6 +75,17 @@ void MenuView::Create(lv_obj_t* root)
"Compiler\n\n"
"Build\n"
);
Item_Create(
&ui.setting,
root,
"Setting",
"setting",

"WiFi Setting\n"
"LCD BK Setting\n"
"LCD BK Timout Setting\n"
);




Expand Down Expand Up @@ -117,6 +127,7 @@ void MenuView::Group_Init()
lv_group_add_obj(ui.group, ui.switches.icon);
lv_group_add_obj(ui.group, ui.hass.icon);
lv_group_add_obj(ui.group, ui.system.icon);
lv_group_add_obj(ui.group, ui.setting.icon);
// lv_group_add_obj(ui.group, ui.battery.icon);
// lv_group_add_obj(ui.group, ui.storage.icon);

Expand Down
1 change: 1 addition & 0 deletions 1.Firmware/src/app/Pages/Menu/MenuView.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class MenuView
item_t switches;
item_t system;
item_t hass; // home assistant
item_t setting;
item_t battery;
item_t storage;
lv_group_t* group;
Expand Down
8 changes: 5 additions & 3 deletions 1.Firmware/src/app/Pages/Playground/Playground.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ app_mode_config_t app_config[] = {
[APP_MODE_HOME_ASSISTANT] = {
.motor_mode = MOTOR_UNBOUND_COARSE_DETENTS,
},
[APP_MODE_SETTING] = {
.motor_mode = MOTOR_UNBOUND_COARSE_DETENTS,
},
};

int16_t app = 0;
Expand Down Expand Up @@ -63,7 +66,6 @@ void Playground::onViewLoad()

Model->Init();
View->Create(root);


// lv_label_set_text(View->ui.labelTitle, Name);

Expand Down Expand Up @@ -175,8 +177,8 @@ void Playground::onEvent(lv_event_t* event)
switch (app) {
case PLAYGROUND_MODE_NO_EFFECTS:
case PLAYGROUND_MODE_FINE_DETENTS:
case PLAYGROUND_MODE_BOUND:
case PLAYGROUND_MODE_ON_OFF:
case PLAYGROUND_MODE_BOUND:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里确实是我的问题,混用了 tab 和空格缩进。 vscode 没正常替换 tab 为空格。应该是当时在另一台机器上开发的时候导致的。

case PLAYGROUND_MODE_ON_OFF:
instance->PlayEventHandler(event, code);
break;
default:
Expand Down
72 changes: 50 additions & 22 deletions 1.Firmware/src/app/Pages/Playground/PlaygroundModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@
#include "app/Accounts/Account_Master.h"
#include "hal/motor.h"
#include "hal/hal.h"
#include "hal/nvs.h"
#include "Playground.h"
using namespace Page;

int32_t MAX_VALUE = 100;
int32_t MIN_VALUE = 0;

bool is_outbound = false;
int32_t arc_offset = 0; // 超出界限时显示的 arch 长度
SuperDialMotion konb_direction = SUPER_DIAL_NULL;
int32_t knob_value = 50;
int now_pos = 0;
int last_pos = 0;

int PlaygroundModel::MAX_VALUE = 100;
int PlaygroundModel::MIN_VALUE = 0;
int PlaygroundModel::knob_value = 50;

void PlaygroundModel::GetKnobStatus(PlaygroundInfo *info)
{
Expand All @@ -28,25 +29,23 @@ void PlaygroundModel::SetPlaygroundMode(int16_t mode)
{
app = mode;
knob_value = 0;
switch (app)
{
switch (app) {
case PLAYGROUND_MODE_NO_EFFECTS:
break;
case PLAYGROUND_MODE_FINE_DETENTS:
// This mode is default
break;
case PLAYGROUND_MODE_BOUND:
MAX_VALUE = 12;
case PLAYGROUND_MODE_FINE_DETENTS:
// This mode is default
break;
case PLAYGROUND_MODE_BOUND:
MAX_VALUE = 12;
MIN_VALUE = 0;

break;
case PLAYGROUND_MODE_ON_OFF:
MAX_VALUE = 1;
MAX_VALUE = 1;
MIN_VALUE = 0;
break;
default:
break;
}
default:
break;
}

}

Expand All @@ -57,12 +56,41 @@ void PlaygroundModel::ChangeMotorMode(int mode)
AccountSystem::Motor_Info_t info;
info.cmd = AccountSystem::MOTOR_CMD_CHANGE_MODE;
info.motor_mode = mode;
info.init_position = 0;
// 第一个参数是通知发布者,即本 Account 应该 subscribe 第一个参数指向的 Account
account->Notify("Motor", &info, sizeof(info));
}

void PlaygroundModel::ChangeMotorModeWithInitPosition(int mode, int init_position)
{
knob_value = init_position;
printf("MenuModel: Change Motor Mode [%d] with init position [%d] \n", mode , init_position);
AccountSystem::Motor_Info_t info;
info.cmd = AccountSystem::MOTOR_CMD_CHANGE_MODE;
info.motor_mode = mode;
info.init_position = init_position;
// 第一个参数是通知发布者,即本 Account 应该 subscribe 第一个参数指向的 Account
account->Notify("Motor", &info, sizeof(info));
}

void PlaygroundModel::SetLcdBkBrightness(int value)
{
static int last_value = -1;
if(last_value != value){
last_value = value;
printf("PlaygroundModel: Change LCD Bightness [%d]\n", value) ;
HAL::set_lcd_brightness( value );
}
}


int onEvent(Account* account, Account::EventParam_t* param)
{
if (param->size != sizeof(AccountSystem::Motor_Info_t))
{
return Account::ERROR_SIZE_MISMATCH;
}

MotorStatusInfo *info = (MotorStatusInfo*) (param->data_p);

now_pos = info->position;
Expand All @@ -77,19 +105,19 @@ int onEvent(Account* account, Account::EventParam_t* param)
// now_pos, last_pos, knob_value, info->angle_offset);
if (now_pos > last_pos)
{
knob_value++;
PlaygroundModel::knob_value++;
konb_direction = SUPER_DIAL_RIGHT;
if (knob_value > MAX_VALUE) {
knob_value = MAX_VALUE;
if (PlaygroundModel::knob_value > PlaygroundModel::MAX_VALUE) {
PlaygroundModel::knob_value = PlaygroundModel::MAX_VALUE;
}
last_pos = now_pos;
}
else if (now_pos < last_pos)
{
knob_value--;
PlaygroundModel::knob_value--;
konb_direction = SUPER_DIAL_LEFT;
if (knob_value < MIN_VALUE) {
knob_value = MIN_VALUE;
if (PlaygroundModel::knob_value < PlaygroundModel::MIN_VALUE) {
PlaygroundModel::knob_value = PlaygroundModel::MIN_VALUE;
}
last_pos = now_pos;
}
Expand Down
13 changes: 9 additions & 4 deletions 1.Firmware/src/app/Pages/Playground/PlaygroundModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

typedef struct
{
int32_t xkonb_value;
int32_t motor_pos;
int32_t angle_offset;
SuperDialMotion konb_direction;
int32_t xkonb_value;
int32_t motor_pos;
int32_t angle_offset;
SuperDialMotion konb_direction;
} PlaygroundInfo;
namespace Page
{
Expand All @@ -22,7 +22,12 @@ class PlaygroundModel
void Deinit();
virtual void GetKnobStatus(PlaygroundInfo *info);
void ChangeMotorMode(int mode);
void ChangeMotorModeWithInitPosition(int mode, int init_position);
void SetPlaygroundMode(int16_t mode);
void SetLcdBkBrightness(int value);
static int32_t MAX_VALUE;
static int32_t MIN_VALUE;
static int32_t knob_value;
private:
Account* account;
};
Expand Down
Loading