|
|
@ -2,8 +2,10 @@ |
|
|
|
#include <FirebaseJson.h> |
|
|
|
#include <FirebaseJson.h> |
|
|
|
|
|
|
|
|
|
|
|
#define PLAYER_UPDATE_INTERVAL_MS (500) |
|
|
|
#define PLAYER_UPDATE_INTERVAL_MS (500) |
|
|
|
|
|
|
|
#define UI_ENTRIES_TO_LOAD (20) |
|
|
|
|
|
|
|
|
|
|
|
static unsigned long playerLastUpdateTime = 0; |
|
|
|
static unsigned long playerLastUpdateTime = 0; |
|
|
|
|
|
|
|
static ViewMode lastViewMode = (ViewMode)-1; |
|
|
|
|
|
|
|
|
|
|
|
String httpURL(String path) { |
|
|
|
String httpURL(String path) { |
|
|
|
return String(OWNTONE_SERVER_ADDRESS) + "/api/" + path; |
|
|
|
return String(OWNTONE_SERVER_ADDRESS) + "/api/" + path; |
|
|
@ -35,13 +37,55 @@ void apiLoop(AppState *state) { |
|
|
|
json.setJsonData(playerText); |
|
|
|
json.setJsonData(playerText); |
|
|
|
FirebaseJsonData result; |
|
|
|
FirebaseJsonData result; |
|
|
|
json.get(result, "volume"); |
|
|
|
json.get(result, "volume"); |
|
|
|
Serial.println(result.type); |
|
|
|
|
|
|
|
Serial.println(result.to<int>()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
state->volume = result.to<int>(); |
|
|
|
state->volume = result.to<int>(); |
|
|
|
|
|
|
|
|
|
|
|
playerLastUpdateTime = state->sinceBoot; |
|
|
|
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<FirebaseJsonArray>(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<String>().c_str(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Serial.println("id..."); |
|
|
|
|
|
|
|
arr.get(arrayIndexResult, idPath); |
|
|
|
|
|
|
|
int id = arrayIndexResult.to<int>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Serial.println("setting..."); |
|
|
|
|
|
|
|
state->uiEntries[i].text = text; |
|
|
|
|
|
|
|
state->uiEntries[i].id = id; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Serial.println(text); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void apiSetup(AppState *state) { |
|
|
|
void apiSetup(AppState *state) { |
|
|
|