Browse Source

more progress

master
Peter Hajas 3 years ago
parent
commit
6cf310eeab
  1. 50
      api.ino
  2. 1
      ui.ino
  3. 31
      wiowntone.ino

50
api.ino

@ -2,8 +2,10 @@
#include <FirebaseJson.h>
#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<int>());
state->volume = result.to<int>();
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) {

1
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);

31
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;
}

Loading…
Cancel
Save