From 6cf310eeab1b70941de5bf19a6324b169c0cf7bd Mon Sep 17 00:00:00 2001 From: Peter Hajas Date: Tue, 19 Jul 2022 22:54:44 -0600 Subject: [PATCH] more progress --- api.ino | 50 +++++++++++++++++++++++++++++++++++++++++++++++--- ui.ino | 1 + wiowntone.ino | 31 +++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 3 deletions(-) diff --git a/api.ino b/api.ino index ee9e45a..77d5c62 100644 --- a/api.ino +++ b/api.ino @@ -2,8 +2,10 @@ #include #define PLAYER_UPDATE_INTERVAL_MS (500) +#define UI_ENTRIES_TO_LOAD (20) static unsigned long playerLastUpdateTime = 0; +static ViewMode lastViewMode = (ViewMode)-1; String httpURL(String path) { return String(OWNTONE_SERVER_ADDRESS) + "/api/" + path; @@ -35,13 +37,55 @@ void apiLoop(AppState *state) { json.setJsonData(playerText); FirebaseJsonData result; json.get(result, "volume"); - Serial.println(result.type); - Serial.println(result.to()); - + state->volume = result.to(); playerLastUpdateTime = state->sinceBoot; } + + bool viewNeedsUpdate = (state->viewMode != lastViewMode); + if (viewNeedsUpdate) { + String parameters = "?limit=" + String(UI_ENTRIES_TO_LOAD); + lastViewMode = state->viewMode; + if (state->viewMode == ViewModeArtists) { + String artistsText = httpGET(String("library/artists" + parameters)); + FirebaseJson json; + json.setJsonData(artistsText); + FirebaseJsonData result; + json.get(result, "items"); + FirebaseJsonArray arr; + result.get(arr); + Serial.println(arr.size()); + + if(state->uiEntries != NULL) { + free(state->uiEntries); + } + state->uiEntries = (UIEntry *)malloc(UI_ENTRIES_TO_LOAD * sizeof(UIEntry)); + state->uiEntriesCount = UI_ENTRIES_TO_LOAD; + + FirebaseJsonData arrayIndexResult; + for (size_t i = 0; i < arr.size(); i++) { + Serial.println("Processing item..."); + String path = "/[" + String(i) + "]/"; + String namePath = path + "name"; + String idPath = path + "id"; + + Serial.println("name..."); + arr.get(arrayIndexResult, namePath); + String text = arrayIndexResult.to().c_str(); + + Serial.println("id..."); + arr.get(arrayIndexResult, idPath); + int id = arrayIndexResult.to(); + + Serial.println("setting..."); + state->uiEntries[i].text = text; + state->uiEntries[i].id = id; + + Serial.println(text); + } + } + } } void apiSetup(AppState *state) { diff --git a/ui.ino b/ui.ino index 06cd758..6f0f02c 100644 --- a/ui.ino +++ b/ui.ino @@ -40,6 +40,7 @@ void uiLoop(AppState *state) { void uiSetup(AppState *state) { lcd.init(); + lcd.setColorDepth(16); lcd.fillScreen(0xFF0000); lcd.setBrightness(128); diff --git a/wiowntone.ino b/wiowntone.ino index 19ff0b9..5d361a8 100644 --- a/wiowntone.ino +++ b/wiowntone.ino @@ -6,12 +6,36 @@ const char *WIFI_SSID = "TortugaNoT"; const char *WIFI_PASS = "april302021"; const char *OWNTONE_SERVER_ADDRESS = "http://192.168.1.2:3689"; +enum ViewMode { + ViewModeArtists = 0, + ViewModeAlbums = 1, + ViewModeTracks = 2, +}; + +typedef struct UIEntry { + // OwnTone ID + int id; + + // Text (name, title, etc.) + String text; +} UIEntry; + typedef struct AppState { unsigned long sinceBoot; bool wifiOnline; IPAddress wifiIP; + ViewMode viewMode; + + size_t uiEntriesCount; + int uiEntryIndex; + UIEntry *uiEntries; + + int songCount; + int artistCount; + int albumCount; + int volume; // out of 100; } AppState; @@ -20,6 +44,13 @@ AppState AppStateMake(void) { out.sinceBoot = 0; out.wifiOnline = false; out.wifiIP = IPAddress(); + out.viewMode = ViewModeArtists; + out.uiEntriesCount = 0; + out.uiEntryIndex = 0; + out.uiEntries = NULL; + out.songCount = 0; + out.artistCount = 0; + out.albumCount = 0; out.volume = 0; return out; }