Skip to content

Commit

Permalink
Changed app_menu to use new reworked "menu app". Broke something in t…
Browse files Browse the repository at this point in the history
…he process...
  • Loading branch information
carlhampuswall committed Jan 19, 2024
1 parent a5dbd88 commit 74cc6be
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 60 deletions.
16 changes: 12 additions & 4 deletions firmware/src/apps/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,26 @@ enum app_types
menu_type = 1,
apps_type = 2
};

typedef uint8_t id;
class App
{

public:
// ID for app

const app_types type = apps_type;

const unsigned char *small_icon;
const unsigned char *big_icon;
const char *friendly_name;

App(TFT_eSprite *spr_)
{
this->spr_ = spr_;
}
virtual ~App() {}
virtual TFT_eSprite *render();

virtual EntityStateUpdate updateStateFromKnob(PB_SmartKnobState state);
virtual void updateStateFromSystem(AppState state);

Expand All @@ -50,9 +60,7 @@ class App
return std::make_pair(menu_type, 0);
}

const unsigned char *small_icon;
const unsigned char *big_icon;
const char *friendly_name;
virtual TFT_eSprite *render();

protected:
/** Full-size sprite used as a framebuffer */
Expand Down
12 changes: 6 additions & 6 deletions firmware/src/apps/app_menu.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "app_menu.h"

MenuApp::MenuApp(TFT_eSprite *spr_) : App(spr_)
MenuApp::MenuApp(TFT_eSprite *spr_) : Menu(spr_)
{
sprintf(room, "%s", "Office");

Expand Down Expand Up @@ -101,7 +101,7 @@ void MenuApp::add_item(uint8_t id, MenuItem item)
void MenuApp::render_menu_screen()
{
lock();
uint32_t color_active = current_item->color;
uint32_t color_active = current_item->screen_name.color;
uint32_t color_inactive = spr_->color565(150, 150, 150);
uint32_t label_color = color_inactive;
uint32_t background = spr_->color565(0, 0, 0);
Expand All @@ -126,17 +126,17 @@ void MenuApp::render_menu_screen()
spr_->setFreeFont(&Roboto_Thin_Bold_24);
spr_->drawString(room, center_h, label_vertical_offset + room_lable_h / 2 - 1, 1);

spr_->drawBitmap(center_h - icon_size_active / 2, center_v - icon_size_active / 2, current_item->big_icon, icon_size_active, icon_size_active, color_active, background);
spr_->drawBitmap(center_h - icon_size_active / 2, center_v - icon_size_active / 2, current_item->big_icon.icon, icon_size_active, icon_size_active, color_active, background);

// left one
spr_->drawBitmap(center_h - icon_size_active / 2 - 20 - icon_size_inactive, center_v - icon_size_inactive / 2, prev_item->small_icon, icon_size_inactive, icon_size_inactive, color_inactive, background);
spr_->drawBitmap(center_h - icon_size_active / 2 - 20 - icon_size_inactive, center_v - icon_size_inactive / 2, prev_item->small_icon.icon, icon_size_inactive, icon_size_inactive, color_inactive, background);

// right one
spr_->drawBitmap(center_h + icon_size_active / 2 + 20, center_v - icon_size_inactive / 2, next_item->small_icon, icon_size_inactive, icon_size_inactive, color_inactive, background);
spr_->drawBitmap(center_h + icon_size_active / 2 + 20, center_v - icon_size_inactive / 2, next_item->small_icon.icon, icon_size_inactive, icon_size_inactive, color_inactive, background);

spr_->setTextColor(color_active);
spr_->setFreeFont(&Roboto_Thin_24);
spr_->drawString(current_item->screen_name, center_h, center_v + icon_size_active / 2 + 30, 1);
spr_->drawString(current_item->screen_name.text, center_h, center_v + icon_size_active / 2 + 30, 1);
unlock();
};

Expand Down
13 changes: 2 additions & 11 deletions firmware/src/apps/app_menu.h
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
#pragma once
#include "app.h"
#include "menu.h"
#include "font/roboto_thin_bold_24.h"

#include <map>

const uint8_t SCREEN_NAME_LENGTH = 20;
const uint8_t MEX_MENU_ITEMS = 12;

struct MenuItem
{
const char *screen_name;
uint16_t app_id;
uint32_t color;
const unsigned char *small_icon;
const unsigned char *big_icon;
};

class MenuApp : public App
class MenuApp : public Menu
{
public:
MenuApp(TFT_eSprite *spr_);
Expand Down
111 changes: 75 additions & 36 deletions firmware/src/apps/apps.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
#include "apps.h"
#include "menu.h"
#include "onboarding.h"
#include "app_menu.h"
#include "onboarding_menu.h"
#include "settings.h"

#include <typeinfo>
Expand Down Expand Up @@ -122,7 +122,7 @@ void Apps::createOnboarding()

onboarding_app->add_item(
0,
OnboardingItem{
MenuItem{
1,
TextItem{
"SMART KNOB",
Expand All @@ -143,12 +143,11 @@ void Apps::createOnboarding()
IconItem{
nullptr,
spr_->color565(255, 255, 255),
},
});
}});

onboarding_app->add_item(
1,
OnboardingItem{
MenuItem{
2,
TextItem{
"HOME ASSISTANT",
Expand All @@ -169,12 +168,11 @@ void Apps::createOnboarding()
IconItem{
home_assistant_80,
spr_->color565(17, 189, 242),
},
});
}});

onboarding_app->add_item(
2,
OnboardingItem{
MenuItem{
3,
TextItem{
"WIFI",
Expand All @@ -195,11 +193,10 @@ void Apps::createOnboarding()
IconItem{
wifi_conn_80,
spr_->color565(255, 255, 255),
},
});
}});
onboarding_app->add_item(
3,
OnboardingItem{
MenuItem{
4,
TextItem{
"DEMO MODE",
Expand All @@ -220,11 +217,10 @@ void Apps::createOnboarding()
IconItem{
nullptr,
spr_->color565(255, 255, 255),
},
});
}});
onboarding_app->add_item(
4,
OnboardingItem{
MenuItem{
5,
TextItem{
"FIRMWARE 0.1b",
Expand All @@ -245,9 +241,7 @@ void Apps::createOnboarding()
IconItem{
nullptr,
spr_->color565(255, 255, 255),
},

});
}});

add(menu_type, 0, onboarding_app);

Expand All @@ -266,20 +260,35 @@ void Apps::createOnboarding()
menu_app->add_item(
0,
MenuItem{
"SETTINGS",
4,
spr_->color565(0, 255, 200),
settings_40,
settings_80,
});
TextItem{
"SETTINGS",
spr_->color565(0, 255, 200),
},
TextItem{
"",
spr_->color565(255, 255, 255),
},
TextItem{
"",
spr_->color565(255, 255, 255),
},
IconItem{
settings_80,
spr_->color565(255, 255, 255),
},
IconItem{
settings_40,
spr_->color565(0, 255, 200),
}});

std::string apps_config = "[{\"app_slug\":\"stopwatch\",\"app_id\":\"stopwatch.office\",\"friendly_name\":\"Stopwatch\",\"area\":\"office\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"light_switch\",\"app_id\":\"light.ceiling\",\"friendly_name\":\"Ceiling\",\"area\":\"Kitchen\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"light_dimmer\",\"app_id\":\"light.workbench\",\"friendly_name\":\"Workbench\",\"area\":\"Kitchen\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"thermostat\",\"app_id\":\"climate.office\",\"friendly_name\":\"Climate\",\"area\":\"Office\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"3d_printer\",\"app_id\":\"3d_printer.office\",\"friendly_name\":\"3D Printer\",\"area\":\"Office\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"blinds\",\"app_id\":\"blinds.office\",\"friendly_name\":\"Shades\",\"area\":\"Office\",\"menu_color\":\"#ffffff\"},{\"app_slug\":\"music\",\"app_id\":\"music.office\",\"friendly_name\":\"Music\",\"area\":\"Office\",\"menu_color\":\"#ffffff\"}]";

cJSON *json_root = cJSON_Parse(apps_config.c_str());
cJSON *json_app = NULL;

uint16_t app_position = 5;
uint16_t menu_position = 1;
uint8_t app_position = 5;
uint8_t menu_position = 1;

cJSON_ArrayForEach(json_app, json_root)
{
Expand All @@ -292,12 +301,27 @@ void Apps::createOnboarding()
menu_app->add_item(
menu_position,
MenuItem{
app->friendly_name,
app_position,
spr_->color565(0, 255, 200),
app->small_icon,
app->big_icon,
});
TextItem{
app->friendly_name,
spr_->color565(0, 255, 200),
},
TextItem{
"",
spr_->color565(255, 255, 255),
},
TextItem{
"",
spr_->color565(255, 255, 255),
},
IconItem{
app->big_icon,
spr_->color565(0, 255, 200),
},
IconItem{
app->small_icon,
spr_->color565(255, 255, 255),
}});

app_position++;
menu_position++;
Expand All @@ -315,7 +339,7 @@ void Apps::updateMenu()

std::map<uint8_t, std::shared_ptr<App>>::iterator it;

uint16_t position = 0;
uint8_t position = 0;

for (it = apps[apps_type].begin(); it != apps[apps_type].end(); it++)
{
Expand All @@ -324,12 +348,27 @@ void Apps::updateMenu()
menu_app->add_item(
position,
MenuItem{
it->second->friendly_name,
position + 1, //! FIXES BUG WITH SYNC MIGHT CREATE MORE??
spr_->color565(0, 255, 200),
it->second->small_icon,
it->second->big_icon,
});
TextItem{
it->second->friendly_name,
spr_->color565(0, 255, 200),
},
TextItem{
"",
spr_->color565(255, 255, 255),
},
TextItem{
"",
spr_->color565(255, 255, 255),
},
IconItem{
it->second->big_icon,
0,
},
IconItem{
it->second->small_icon,
0,
}});

position++;
}
Expand Down
4 changes: 2 additions & 2 deletions firmware/src/apps/apps.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
#include "stopwatch.h"

// include all "menu" apps
#include "menu.h"
#include "onboarding.h"
#include "app_menu.h"
#include "onboarding_menu.h"

// include all "setup" apps
#include "onboarding/hass_setup.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "onboarding.h"
#include "onboarding_menu.h"

OnboardingApp::OnboardingApp(TFT_eSprite *spr_) : Menu(spr_)
{
Expand Down
File renamed without changes.

0 comments on commit 74cc6be

Please sign in to comment.