Skip to content

Commit

Permalink
foobar2000 integration
Browse files Browse the repository at this point in the history
  • Loading branch information
akasaka committed May 31, 2024
1 parent 48d148e commit 6767966
Show file tree
Hide file tree
Showing 12 changed files with 381 additions and 5 deletions.
5 changes: 4 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ ADMIN_PASS=\"plasma\"
# OpenWeatherMap configuration
WEATHER_LAT=\"43.0642\"
WEATHER_LON=\"141.3469\"
WEATHER_API_KEY=\"your OpenWeatherMap API Key\"
WEATHER_API_KEY=\"your OpenWeatherMap API Key\"

# Wordnik configuration
WORDNIK_API_KEY=\"your Wordnik API key\"
15 changes: 15 additions & 0 deletions include/service/foo_client.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once
#include <freertos/FreeRTOS.h>

// Output option for foo_controlserver:
// %artist%|%title%
// Also set the main delimiter to |

#define FOO_SEPARATOR '|'

void foo_client_begin();

bool foo_is_playing();
void foo_get_title(char *, size_t);
void foo_get_artist(char *, size_t);
TickType_t foo_last_recv();
4 changes: 4 additions & 0 deletions include/service/prefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ static constexpr prefs_key_t PREFS_KEY_SCRN_TIME_CLOCK_SECONDS = "s_clock_s";
static constexpr prefs_key_t PREFS_KEY_SCRN_TIME_INDOOR_SECONDS = "s_inside_s";
static constexpr prefs_key_t PREFS_KEY_SCRN_TIME_OUTDOOR_SECONDS = "s_outside_s";
static constexpr prefs_key_t PREFS_KEY_SCRN_TIME_WORD_OF_THE_DAY_SECONDS = "s_wotd_s";
static constexpr prefs_key_t PREFS_KEY_SCRN_TIME_FOOBAR_SECONDS = "s_foo_s";

static constexpr prefs_key_t PREFS_KEY_HOURLY_CHIME_ON = "h_chime_on";
static constexpr prefs_key_t PREFS_KEY_HOURLY_CHIME_START_HOUR = "h_chime_start";
Expand All @@ -44,6 +45,9 @@ static constexpr prefs_key_t PREFS_KEY_TIMEZONE = "tk_tz";
static constexpr prefs_key_t PREFS_KEY_TIMESERVER = "tk_ntp_serv";
static constexpr prefs_key_t PREFS_KEY_TIME_SYNC_INTERVAL_SEC = "tk_intv_s";

static constexpr prefs_key_t PREFS_KEY_FOOBAR_SERVER = "foo_svr";
static constexpr prefs_key_t PREFS_KEY_FOOBAR_PORT = "foo_prt";

void prefs_force_save();

String prefs_get_string(prefs_key_t, String def = String());
Expand Down
21 changes: 21 additions & 0 deletions include/views/fb2k.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once
#include "view.h"
#include <plasma/fanta_manipulator.h>
#include <views/string_scroll.h>

class Fb2kView: public Renderable {
public:
Fb2kView();
void prepare();
void step();
void render(FantaManipulator*);

private:
void update_if_needed();
const font_definition_t * font;
char artist_buffer[128];
char title_buffer[128];
TickType_t last_update;
StringScroll * top_line;
StringScroll * bottom_line;
};
1 change: 1 addition & 0 deletions include/views/string_scroll.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class StringScroll: public Renderable {
private:
const font_definition_t * font;
const char * string;
bool scroll_only_if_not_fit;
int y_position;
int position;
int frame_divisor;
Expand Down
11 changes: 10 additions & 1 deletion src/idle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
#include <service/time.h>
#include <service/owm/weather.h>
#include <service/prefs.h>
#include <service/foo_client.h>
#include <views/simple_clock.h>
#include <views/rain_ovl.h>
#include <views/thunder_ovl.h>
#include <views/indoor_view.h>
#include <views/framework.h>
#include <views/current_weather.h>
#include <views/word_of_the_day.h>
#include <views/fb2k.h>

static char LOG_TAG[] = "APL_IDLE";

Expand All @@ -20,6 +22,7 @@ typedef enum MainViewId: uint16_t {
VIEW_INDOOR_WEATHER,
VIEW_OUTDOOR_WEATHER,
VIEW_WORD_OF_THE_DAY,
VIEW_FB2K,

VIEW_MAX
} MainViewId_t;
Expand All @@ -29,6 +32,7 @@ static int screen_times_ms[VIEW_MAX] = {
10000, // VIEW_INDOOR_WEATHER
25000, // VIEW_OUTDOOR_WEATHER
25000, // VIEW_WORD_OF_THE_DAY
0, // VIEW_FB2K
};

static bool did_prepare = false;
Expand All @@ -46,8 +50,8 @@ static ThunderOverlay * thunder;

static IndoorView * indoorView;
static CurrentWeatherView * weatherView;

static WordOfTheDayView * wotdView;
static Fb2kView *fb2kView;

static ViewMultiplexor * slideShow;

Expand Down Expand Up @@ -159,6 +163,7 @@ void app_idle_prepare(SensorPool* s, Beeper* b) {
screen_times_ms[VIEW_INDOOR_WEATHER] = prefs_get_int(PREFS_KEY_SCRN_TIME_INDOOR_SECONDS) * 1000;
screen_times_ms[VIEW_OUTDOOR_WEATHER] = prefs_get_int(PREFS_KEY_SCRN_TIME_OUTDOOR_SECONDS) * 1000;
screen_times_ms[VIEW_WORD_OF_THE_DAY] = prefs_get_int(PREFS_KEY_SCRN_TIME_WORD_OF_THE_DAY_SECONDS) * 1000;
// VIEW_FB2K gets set dynamically in processing()

bool has_at_least_one_screen = false;
for(int i = 0; i < VIEW_MAX; i++) {
Expand All @@ -177,6 +182,7 @@ void app_idle_prepare(SensorPool* s, Beeper* b) {
thunder = new ThunderOverlay(101, 16);
weatherView = new CurrentWeatherView();
wotdView = new WordOfTheDayView();
fb2kView = new Fb2kView();

// thunder hurts readability on other views, so keep it on clock only
ViewCompositor * thunderClock = new ViewCompositor();
Expand All @@ -188,6 +194,7 @@ void app_idle_prepare(SensorPool* s, Beeper* b) {
slideShow->add_view(indoorView, VIEW_INDOOR_WEATHER);
slideShow->add_view(weatherView, VIEW_OUTDOOR_WEATHER);
slideShow->add_view(wotdView, VIEW_WORD_OF_THE_DAY);
slideShow->add_view(fb2kView, VIEW_FB2K);

lastScreenSwitch = xTaskGetTickCount();

Expand Down Expand Up @@ -237,4 +244,6 @@ void app_idle_process() {

tick_tock_enable = prefs_get_bool(PREFS_KEY_TICKING_SOUND);
hourly_chime_on = prefs_get_bool(PREFS_KEY_HOURLY_CHIME_ON);
screen_times_ms[VIEW_FB2K] =
foo_is_playing() ? (prefs_get_int(PREFS_KEY_SCRN_TIME_FOOBAR_SECONDS) * 1000) : 0;
}
2 changes: 2 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <service/time.h>
#include <service/prefs.h>
#include <service/wordnik.h>
#include <service/foo_client.h>
#include <network/admin_panel.h>
#include <utils.h>
#include <state.h>
Expand Down Expand Up @@ -132,6 +133,7 @@ void setup() {
timekeeping_begin();
weather_start();
wotd_start();
foo_client_begin();
power_mgmt_start(sensors, &plasma, beepola);
admin_panel_prepare(sensors, beepola);
fps_counter = prefs_get_bool(PREFS_KEY_FPS_COUNTER);
Expand Down
12 changes: 12 additions & 0 deletions src/network/admin_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ void build() {
render_int("Show current weather for [s]:", PREFS_KEY_SCRN_TIME_OUTDOOR_SECONDS);
GP.BREAK();
render_int("Show word of the day for [s]:", PREFS_KEY_SCRN_TIME_WORD_OF_THE_DAY_SECONDS);
GP.BREAK();
render_int("Show Fb2k for [s]:", PREFS_KEY_SCRN_TIME_FOOBAR_SECONDS);
GP.HR();
GP.LABEL("Screen transition:");
GP.SELECT(PREFS_KEY_TRANSITION_TYPE, "Off,Wipe,Horizontal Slide,Vertical Slide,Random", prefs_get_int(PREFS_KEY_TRANSITION_TYPE));
Expand Down Expand Up @@ -234,6 +236,13 @@ void build() {
GP.SPAN(definition);
}
GP.SPOILER_END();
GP.BREAK();

GP.SPOILER_BEGIN("Foobar2000", GP_BLUE);
render_string("Control Server IP", PREFS_KEY_FOOBAR_SERVER);
render_int("Control Server Port:", PREFS_KEY_FOOBAR_PORT);
GP.SPAN("Please set the format in foo_controlserver to: %artist%|%title%, and main delimiter to: |");
GP.SPOILER_END();

GP.HR();
#if defined(PDFB_PERF_LOGS)
Expand Down Expand Up @@ -261,6 +270,7 @@ void action() {
save_int(PREFS_KEY_SCRN_TIME_INDOOR_SECONDS, 0, 3600);
save_int(PREFS_KEY_SCRN_TIME_OUTDOOR_SECONDS, 0, 3600);
save_int(PREFS_KEY_SCRN_TIME_WORD_OF_THE_DAY_SECONDS, 0, 3600);
save_int(PREFS_KEY_SCRN_TIME_FOOBAR_SECONDS, 0, 3600);
save_bool(PREFS_KEY_NO_SOUND_WHEN_OFF);
save_int(PREFS_KEY_TRANSITION_TYPE, TRANSITION_NONE, TRANSITION_RANDOM);
save_int(PREFS_KEY_DISP_SCROLL_SPEED, 0, 4);
Expand All @@ -274,6 +284,8 @@ void action() {
save_int(PREFS_KEY_WEATHER_INTERVAL_MINUTES, 30, 24 * 60);
save_string(PREFS_KEY_WORDNIK_APIKEY);
save_int(PREFS_KEY_WORDNIK_INTERVAL_MINUTES, 60, 3600);
save_string(PREFS_KEY_FOOBAR_SERVER);
save_int(PREFS_KEY_FOOBAR_PORT, 1000, 9999);
save_bool(PREFS_KEY_FPS_COUNTER);

#ifdef DEMO_WEATHER_WEBADMIN
Expand Down
Loading

0 comments on commit 6767966

Please sign in to comment.