Skip to content

Commit

Permalink
small update charge management and audio player
Browse files Browse the repository at this point in the history
  • Loading branch information
pebri86 committed Dec 2, 2019
1 parent 0fabdc4 commit d7a96dc
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 4 deletions.
Binary file modified assets/gfxTile.xcf
Binary file not shown.
14 changes: 11 additions & 3 deletions esplay-launcher/main/audio_player.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ static PlayerState player_state = {
};
static bool keys_locked = false;
static bool backlight_on = true;
static bool speaker_on = false;

// These need to be implemented for SDL/FreeRTOS seperately
static PlayerCmd player_poll_cmd(void);
Expand Down Expand Up @@ -202,7 +203,7 @@ static PlayerResult handle_cmd(PlayerState *const state, const AudioInfo info, c
if (state->playing)
{
audio_init((int)info.sample_rate);
audio_amp_disable();
speaker_on ? audio_amp_enable() : audio_amp_disable();
}
else
{
Expand All @@ -214,7 +215,7 @@ static PlayerResult handle_cmd(PlayerState *const state, const AudioInfo info, c
if (state->playing)
audio_terminate();
audio_init((int)info.sample_rate);
audio_amp_disable();
speaker_on ? audio_amp_enable() : audio_amp_disable();
push_audio_event(AudioPlayerEventStateChanged);
break;
case PlayerCmdToggleLoopMode:
Expand Down Expand Up @@ -272,7 +273,7 @@ static PlayerResult play_song(const Song *const song)
}

audio_init((int)info.sample_rate);
audio_amp_disable();
speaker_on ? audio_amp_enable() : audio_amp_disable();

int n_frames = 0;
state->playing = true;
Expand Down Expand Up @@ -434,6 +435,7 @@ static void draw_player(const PlayerState *const state)
// Show Playing or paused/DAC on image
UG_PutString(222, y + 11, state->playing ? "Pause" : "Continue");
UG_PutString(222, y + 50, "Go Back");
UG_PutString(222, y + 89, speaker_on ? "Speaker off" : "Speaker on");
y += 115;

// Explain start and stop button behaviour
Expand Down Expand Up @@ -634,6 +636,12 @@ static void handle_keypress(event_keypad_t keys, bool *quit)
set_display_brightness(backlight_on ? 0 : 50);
backlight_on = !backlight_on;
}
if (!lastJoystickState.values[GAMEPAD_INPUT_L] && joystick.values[GAMEPAD_INPUT_L])
{
speaker_on = !speaker_on;
speaker_on ? audio_amp_enable() : audio_amp_disable();
draw_player(&player_state);
}

lastJoystickState = joystick;
}
Expand Down
Binary file modified esplay-launcher/main/gfxTile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions esplay-launcher/main/graphics.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ static const char gfxTile[]={
#include "gfxTile.inc"
};

#define GFX_O_EMPTY 0
#define GFX_O_FULL 1
#define GFX_O_CHG 2
#define GFX_O_CHGNEARFULL 3

const char * chargeinfo = "Press A to Play";

void renderGraphics(int dx, int dy, int sx, int sy, int sw, int sh)
{
uint16_t *fb = ui_get_fb();
Expand Down Expand Up @@ -42,6 +49,34 @@ void renderGraphics(int dx, int dy, int sx, int sy, int sw, int sh)
}
}

void guiCharging(int almostFull) {
ui_clear_screen();
UG_FontSelect(&FONT_6X8);
UG_PutString((320 - strlen(chargeinfo) * 7)/2, ((240 - 11)/2)+15, chargeinfo);
if (!almostFull) {
renderGraphics((320-41)/2, (240 - 11)/2, 208, 439 + (11*GFX_O_CHG), 41, 11);
} else {
renderGraphics((320-41)/2, (240 - 11)/2, 208, 439 + (11*GFX_O_CHGNEARFULL), 41, 11);
}
ui_flush();
}

void guiFull() {
ui_clear_screen();
UG_FontSelect(&FONT_6X8);
UG_PutString((320 - strlen(chargeinfo) * 7)/2, ((240 - 11)/2)+15, chargeinfo);
renderGraphics((320-41)/2, (240 - 11)/2, 208, 439 + (11*GFX_O_FULL), 41, 11);
ui_flush();
}

void guiBatEmpty() {
ui_clear_screen();
UG_FontSelect(&FONT_6X8);
UG_PutString((320 - strlen(chargeinfo) * 7)/2, ((240 - 11)/2)+15, chargeinfo);
renderGraphics((320-41)/2, (240 - 11)/2, 208, 439 + (11*GFX_O_EMPTY), 41, 11);
ui_flush();
}

void drawBattery(int batPercent)
{
charging_state st = getChargeStatus();
Expand Down
5 changes: 4 additions & 1 deletion esplay-launcher/main/include/graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@

void renderGraphics(int dx, int dy, int sx, int sy, int sw, int sh);
void drawBattery(int batPercent);
void drawVolume(int volume);
void drawVolume(int volume);
void guiCharging(int almostFull);
void guiFull();
void guiBatEmpty();
56 changes: 56 additions & 0 deletions esplay-launcher/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
#include "esp_ota_ops.h"
#include "esp_heap_caps.h"
#include "esp_http_server.h"
#include "soc/dport_reg.h"

#include "rom/rtc.h"
#include "soc/soc.h"
#include "soc/rtc.h"
#include "soc/rtc_cntl_reg.h"

#include "settings.h"
#include "gamepad.h"
Expand Down Expand Up @@ -49,6 +55,52 @@ esp_err_t event_handler(void *ctx, system_event_t *event)
return ESP_OK;
}

static void handleCharging() {
int r;
int fullCtr=0;
//The LiIon charger sometimes goes back from 'full' to 'charging', which is
//confusing to the end user. This variable becomes true if the LiIon has indicated 'full'
//for a while, and it being true causes the 'full' icon to always show.
int fixFull=0;

//Force brightness low to decrease chance of burn-in
set_display_brightness(30);
printf("Detected charger.\n");
guiCharging(0);

//Speed down
rtc_clk_cpu_freq_set(RTC_CPU_FREQ_80M);
input_gamepad_state prevKey;
gamepad_read(&prevKey);
do {
input_gamepad_state key;
gamepad_read(&key);
r=getChargeStatus();
if (r==FULL_CHARGED || fixFull) {
guiFull();
printf("Full!\n");
fullCtr++;
} else if (r==CHARGING) {
battery_level_read(&bat_state);
guiCharging(bat_state.millivolts > 4100);
printf("Charging...\n");
fullCtr=0;
}

if (!prevKey.values[GAMEPAD_INPUT_A] && key.values[GAMEPAD_INPUT_A]) {
printf("Power btn A; go to launcher menu\n");
break;
}
if (fullCtr==32) {
fixFull=1;
}
vTaskDelay(1);
prevKey = key;
} while (r!=NO_CHRG);

rtc_clk_cpu_freq_set(RTC_CPU_FREQ_240M);
}

static void drawHomeScreen()
{
ui_clear_screen();
Expand Down Expand Up @@ -379,7 +431,11 @@ void app_main(void)
sdcard_open("/sd"); // map SD card.

ui_init();
charging_state st = getChargeStatus();
if (st == CHARGING)
handleCharging();

UG_FontSelect(&FONT_8X12);
if(settings_load(SettingWifi, &wifi_en) != 0)
settings_save(SettingWifi, (int32_t)wifi_en);
if(settings_load(SettingAudioVolume, &volume) != 0)
Expand Down

0 comments on commit d7a96dc

Please sign in to comment.