-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
531 additions
and
455 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,204 @@ | ||
#include "esphome/components/homeThing/HomeThingMenuNowPlayingHeader.h" | ||
|
||
namespace esphome { | ||
namespace homething_menu_now_playing { | ||
|
||
std::string HomeThingMenuNowPlayingHeader::get_header_title() { | ||
switch (*app_menu_index_) { | ||
case 0: { | ||
if (media_player_group_ == nullptr) { | ||
return "Now Playing"; | ||
} | ||
if (media_player_group_->active_player_ == nullptr) { | ||
return "Loading..."; | ||
} | ||
return media_player_group_->active_player_->get_name(); | ||
break; | ||
} | ||
case 1: | ||
return "Sources"; | ||
break; | ||
case 2: | ||
return "Media Players"; | ||
break; | ||
default: | ||
break; | ||
} | ||
return "xx2"; | ||
} | ||
|
||
int HomeThingMenuNowPlayingHeader::draw_header_details( | ||
int xPos, int yPos, display::DisplayBuffer* display_buffer, | ||
homething_menu_base::HomeThingMenuDisplayState* display_state, | ||
homething_menu_base::HomeThingMenuTextHelpers* text_helpers) { | ||
switch (*app_menu_index_) { | ||
case 0: | ||
break; | ||
default: | ||
return 0; | ||
} | ||
xPos = xPos - drawPlayPauseIcon(xPos, yPos, display_buffer, display_state, | ||
text_helpers); | ||
xPos = xPos - | ||
drawRepeat(xPos, yPos, display_buffer, display_state, text_helpers); | ||
xPos = xPos - | ||
drawShuffle(xPos, yPos, display_buffer, display_state, text_helpers); | ||
return xPos; | ||
} | ||
|
||
int HomeThingMenuNowPlayingHeader::drawPlayPauseIcon( | ||
int oldXPos, int yPos, display::DisplayBuffer* display_buffer, | ||
homething_menu_base::HomeThingMenuDisplayState* display_state, | ||
homething_menu_base::HomeThingMenuTextHelpers* text_helpers) { | ||
int iconWidth = | ||
display_state->get_icon_size() + (display_state->get_margin_size() / 2); | ||
int xPos = oldXPos - iconWidth + (display_state->get_margin_size() / 2); | ||
auto active_player = media_player_group_->active_player_; | ||
if (active_player == NULL) { | ||
return 0; | ||
} | ||
auto menuTitle = homething_menu_base::headerMediaPlayerTitle(active_player); | ||
switch (active_player->playerState) { | ||
case homeassistant_media_player::RemotePlayerState:: | ||
PlayingRemotePlayerState: { | ||
display_buffer->printf( | ||
xPos, yPos, display_state->get_font_material_small(), | ||
menuTitle.mediaSourceIconColor( | ||
display_state->get_color_palette()->get_accent_primary()), | ||
menuTitle.mediaSourceIcon().c_str()); | ||
break; | ||
} | ||
case homeassistant_media_player::RemotePlayerState::PausedRemotePlayerState: | ||
display_buffer->printf( | ||
xPos, yPos, display_state->get_font_material_small(), | ||
display_state->get_color_palette()->get_accent_primary(), ""); | ||
break; | ||
case homeassistant_media_player::RemotePlayerState:: | ||
StoppedRemotePlayerState: | ||
display_buffer->printf( | ||
xPos, yPos, display_state->get_font_material_small(), | ||
display_state->get_color_palette()->get_accent_primary(), ""); | ||
break; | ||
case homeassistant_media_player::RemotePlayerState:: | ||
PowerOffRemotePlayerState: | ||
display_buffer->printf( | ||
xPos, yPos, display_state->get_font_material_small(), | ||
display_state->get_color_palette()->get_accent_primary(), ""); | ||
break; | ||
default: | ||
return 0; | ||
} | ||
return iconWidth; | ||
} | ||
|
||
int HomeThingMenuNowPlayingHeader::drawShuffle( | ||
int oldXPos, int yPos, display::DisplayBuffer* display_buffer, | ||
homething_menu_base::HomeThingMenuDisplayState* display_state, | ||
homething_menu_base::HomeThingMenuTextHelpers* text_helpers) { | ||
if (!media_player_group_ || media_player_group_->active_player_ == NULL || | ||
display_state->get_draw_shuffle() == | ||
homething_menu_base::DisplayIconEnabledState::OFF) { | ||
ESP_LOGI(TAG, "drawShuffle return 0"); | ||
return 0; | ||
} | ||
auto active_player = media_player_group_->active_player_; | ||
if (active_player->get_player_type() == | ||
homeassistant_media_player::RemotePlayerType::TVRemotePlayerType || | ||
!active_player->supports(homeassistant_media_player:: | ||
MediaPlayerSupportedFeature::SHUFFLE_SET)) { | ||
ESP_LOGI(TAG, "drawShuffle return 0 not set"); | ||
return 0; | ||
} | ||
if (active_player->playerState != | ||
homeassistant_media_player::RemotePlayerState::StoppedRemotePlayerState) { | ||
int iconWidth = | ||
display_state->get_icon_size() + (display_state->get_margin_size() / 2); | ||
int xPos = oldXPos - iconWidth + (display_state->get_margin_size() / 2); | ||
if (media_player_group_->mediaShuffling()) { | ||
display_buffer->printf( | ||
xPos, yPos, display_state->get_font_material_small(), | ||
display_state->get_color_palette()->get_accent_primary(), ""); | ||
} else if (display_state->get_draw_shuffle() == | ||
homething_menu_base::DisplayIconEnabledState::ALWAYS) { | ||
display_buffer->printf( | ||
xPos, yPos, display_state->get_font_material_small(), | ||
display_state->get_color_palette()->get_accent_primary(), ""); | ||
} else { | ||
ESP_LOGI(TAG, "drawShuffle uhh %d", display_state->get_draw_shuffle()); | ||
return 0; | ||
} | ||
return iconWidth; | ||
} | ||
ESP_LOGI(TAG, "drawShuffle fail"); | ||
return 0; | ||
} | ||
|
||
int HomeThingMenuNowPlayingHeader::drawRepeat( | ||
int oldXPos, int yPos, display::DisplayBuffer* display_buffer, | ||
homething_menu_base::HomeThingMenuDisplayState* display_state, | ||
homething_menu_base::HomeThingMenuTextHelpers* text_helpers) { | ||
if (display_state->get_draw_repeat() == | ||
homething_menu_base::DisplayIconEnabledState::OFF || | ||
!media_player_group_ || media_player_group_->active_player_ == NULL) { | ||
return 0; | ||
} | ||
auto active_player = media_player_group_->active_player_; | ||
if (active_player->get_player_type() == | ||
homeassistant_media_player::RemotePlayerType::TVRemotePlayerType || | ||
!active_player->supports(homeassistant_media_player:: | ||
MediaPlayerSupportedFeature::REPEAT_SET) || | ||
active_player->playerState == | ||
homeassistant_media_player::RemotePlayerState:: | ||
StoppedRemotePlayerState) { | ||
return 0; | ||
} | ||
int iconWidth = | ||
display_state->get_icon_size() + (display_state->get_margin_size() / 2); | ||
int xPos = oldXPos - iconWidth + (display_state->get_margin_size() / 2); | ||
switch (media_player_group_->get_repeat_mode()) { | ||
case homeassistant_media_player::MediaPlayerRepeatMode::ALL: | ||
display_buffer->printf( | ||
xPos, yPos, display_state->get_font_material_small(), | ||
display_state->get_color_palette()->get_accent_primary(), ""); | ||
break; | ||
case homeassistant_media_player::MediaPlayerRepeatMode::ONE: | ||
display_buffer->printf( | ||
xPos, yPos, display_state->get_font_material_small(), | ||
display_state->get_color_palette()->get_accent_primary(), ""); | ||
break; | ||
case homeassistant_media_player::MediaPlayerRepeatMode::OFF: | ||
if (display_state->get_draw_repeat() != | ||
homething_menu_base::DisplayIconEnabledState::ALWAYS) { | ||
return 0; | ||
} | ||
display_buffer->printf( | ||
xPos, yPos, display_state->get_font_material_small(), | ||
display_state->get_color_palette()->get_accent_primary(), ""); | ||
break; | ||
default: | ||
return 0; | ||
} | ||
return iconWidth; | ||
} | ||
|
||
int HomeThingMenuNowPlayingHeader::drawHeaderVolumeLevel( | ||
int oldXPos, int yPos, display::DisplayBuffer* display_buffer, | ||
homething_menu_base::HomeThingMenuDisplayState* display_state, | ||
homething_menu_base::HomeThingMenuTextHelpers* text_helpers) { | ||
if (media_player_group_ == nullptr || | ||
media_player_group_->active_player_ == nullptr) { | ||
return 0; | ||
} | ||
if (!display_state->get_draw_volume_level()) { | ||
return 0; | ||
} | ||
int xPos = oldXPos - display_state->get_margin_size() / 2; | ||
display_buffer->printf( | ||
xPos, yPos, display_state->get_font_small(), | ||
text_helpers->primaryTextColor(display_state->get_dark_mode()), | ||
display::TextAlign::TOP_RIGHT, "%.0f%%", | ||
media_player_group_->getVolumeLevel()); | ||
return 24; | ||
} | ||
} // namespace homething_menu_now_playing | ||
} // namespace esphome |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#pragma once | ||
|
||
#include "esphome/components/homeThing/homeThingMenuDisplayState.h" | ||
#include "esphome/components/homeThing/homeThingMenuHeader.h" | ||
#include "esphome/components/homeThing/homeThingMenuScreen.h" | ||
#include "esphome/components/homeThing/homeThingMenuTextHelpers.h" | ||
#include "esphome/components/homeassistant_media_player/HomeAssistantMediaPlayerGroup.h" | ||
|
||
namespace esphome { | ||
namespace homething_menu_now_playing { | ||
|
||
class HomeThingMenuNowPlayingHeader | ||
: public homething_menu_base::HomeThingMenuHeaderSource { | ||
public: | ||
HomeThingMenuNowPlayingHeader( | ||
homeassistant_media_player::HomeAssistantMediaPlayerGroup* | ||
media_player_group, | ||
int* app_menu_index) | ||
: media_player_group_(media_player_group), | ||
app_menu_index_(app_menu_index) {} | ||
// header | ||
std::string get_header_title(); | ||
|
||
int draw_header_details( | ||
int xPos, int yPos, display::DisplayBuffer* display_buffer, | ||
homething_menu_base::HomeThingMenuDisplayState* display_state, | ||
homething_menu_base::HomeThingMenuTextHelpers* text_helpers); | ||
|
||
protected: | ||
homeassistant_media_player::HomeAssistantMediaPlayerGroup* | ||
media_player_group_{nullptr}; | ||
|
||
private: | ||
int drawPlayPauseIcon( | ||
int oldXPos, int yPos, display::DisplayBuffer* display_buffer, | ||
homething_menu_base::HomeThingMenuDisplayState* display_state, | ||
homething_menu_base::HomeThingMenuTextHelpers* text_helpers); | ||
int drawShuffle(int oldXPos, int yPos, display::DisplayBuffer* display_buffer, | ||
homething_menu_base::HomeThingMenuDisplayState* display_state, | ||
homething_menu_base::HomeThingMenuTextHelpers* text_helpers); | ||
int drawRepeat(int oldXPos, int yPos, display::DisplayBuffer* display_buffer, | ||
homething_menu_base::HomeThingMenuDisplayState* display_state, | ||
homething_menu_base::HomeThingMenuTextHelpers* text_helpers); | ||
int drawHeaderVolumeLevel( | ||
int oldXPos, int yPos, display::DisplayBuffer* display_buffer, | ||
homething_menu_base::HomeThingMenuDisplayState* display_state, | ||
homething_menu_base::HomeThingMenuTextHelpers* text_helpers); | ||
const char* const TAG = "homething.nowplaying.control.header"; | ||
int* app_menu_index_; | ||
}; | ||
} // namespace homething_menu_now_playing | ||
} // namespace esphome |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#pragma once | ||
|
||
#include "esphome/components/homeThing/homeThingMenuHeader.h" | ||
#include "esphome/components/homeThing/homeThingMenuTitle.h" | ||
#include "esphome/components/homeassistant_media_player/HomeAssistantMediaPlayerGroup.h" | ||
|
||
#include "esphome/components/homeThing/homeThingMenuDisplayState.h" | ||
#include "esphome/components/homeThing/homeThingMenuScreen.h" | ||
#include "esphome/components/homeThing/homeThingMenuTextHelpers.h" | ||
|
||
namespace esphome { | ||
namespace homething_menu_app { | ||
|
||
enum NavigationCoordination { | ||
NavigationCoordinationNone, | ||
NavigationCoordinationPop, | ||
NavigationCoordinationRoot, | ||
NavigationCoordinationUpdate, | ||
NavigationCoordinationReturn | ||
}; | ||
|
||
class HomeThingMenuApp : public homething_menu_base::HomeThingMenuHeaderSource { | ||
public: | ||
// menu titles | ||
virtual void rootMenuTitles( | ||
std::vector<homething_menu_base::MenuTitleBase*>* menu_titles) {} | ||
virtual void app_menu_titles( | ||
std::vector<homething_menu_base::MenuTitleBase*>* menu_titles) {} | ||
|
||
// menu screens | ||
virtual NavigationCoordination app_menu_select(int index) { | ||
return NavigationCoordination::NavigationCoordinationNone; | ||
} | ||
virtual bool should_draw_app() { return false; } | ||
virtual void draw_app( | ||
int menuIndex, | ||
const std::vector<homething_menu_base::MenuTitleBase*>* active_menu); | ||
virtual void idleTick(int idleTime, int display_timeout) {} | ||
virtual int root_menu_size() { return 0; } | ||
virtual void reset_menu() {} | ||
virtual void set_app_menu_index(int app_menu_index) {} | ||
|
||
// buttons | ||
virtual void rotaryScrollClockwise(int rotary) {} | ||
virtual void rotaryScrollCounterClockwise(int rotary) {} | ||
virtual NavigationCoordination buttonPressUp() { | ||
return NavigationCoordination::NavigationCoordinationNone; | ||
} | ||
virtual NavigationCoordination buttonPressDown() { | ||
return NavigationCoordination::NavigationCoordinationNone; | ||
} | ||
virtual NavigationCoordination buttonPressLeft() { | ||
return NavigationCoordination::NavigationCoordinationNone; | ||
} | ||
virtual NavigationCoordination buttonPressRight() { | ||
return NavigationCoordination::NavigationCoordinationNone; | ||
} | ||
virtual NavigationCoordination buttonPressSelect(int menuIndex) { | ||
return NavigationCoordination::NavigationCoordinationNone; | ||
} | ||
virtual NavigationCoordination buttonPressSelectHold() { | ||
return NavigationCoordination::NavigationCoordinationNone; | ||
} | ||
virtual NavigationCoordination buttonPressScreenLeft() { | ||
return NavigationCoordination::NavigationCoordinationNone; | ||
} | ||
virtual NavigationCoordination buttonReleaseScreenLeft() { | ||
return NavigationCoordination::NavigationCoordinationNone; | ||
} | ||
virtual NavigationCoordination buttonPressScreenRight() { | ||
return NavigationCoordination::NavigationCoordinationNone; | ||
} | ||
|
||
// header | ||
virtual homething_menu_base::HomeThingMenuHeaderSource* get_header_source() { | ||
return header_source_; | ||
} | ||
|
||
protected: | ||
homething_menu_base::HomeThingMenuHeaderSource* header_source_{nullptr}; | ||
|
||
private: | ||
const char* const TAG = "homething.menu.app"; | ||
}; | ||
} // namespace homething_menu_app | ||
} // namespace esphome |
Oops, something went wrong.