Skip to content

Commit

Permalink
fix a few display bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
profezzorn committed Dec 28, 2021
1 parent 45fcc63 commit f383521
Showing 1 changed file with 30 additions and 12 deletions.
42 changes: 30 additions & 12 deletions display/ssd1306.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,19 +281,31 @@ class StandardDisplayController : public DisplayControllerBase<Width, col_t>, Sa
return last_delay_ = FillFrameBuffer2(advance);
}

#ifdef USB_CLASS_MSC
bool EscapeIdleIfNeeded() {
return looped_idle_ == Tristate::True && USBD_Configured();
}
#else
bool EscapeIdleIfNeeded() { return false; }
#endif

void ShowDefault(bool ignore_lockup = false) {
screen_ = SCREEN_PLI;
t_ = 0;
if (SaberBase::IsOn()) {
if (SaberBase::Lockup() && IMG_lock && !ignore_lockup) {
ShowFile(&IMG_lock, 3600000.0);
SetFile(&IMG_lock, 3600000.0);
} else if (looped_on_ == Tristate::True) {
ShowFile(&IMG_on, font_config.ProffieOSOnImageDuration);
SetFile(&IMG_on, font_config.ProffieOSOnImageDuration);
}
} else {
// Off
if (looped_idle_ != Tristate::False) {
ShowFile(&IMG_idle, 3600000.0);
if (EscapeIdleIfNeeded()) {
SetMessage("usb");
} else {
SetFile(&IMG_idle, 3600000.0);
}
}
}
}
Expand Down Expand Up @@ -361,13 +373,11 @@ class StandardDisplayController : public DisplayControllerBase<Width, col_t>, Sa
}

case SCREEN_IMAGE:
#ifdef USB_CLASS_MSC
if (looped_idle_ == Tristate::True && current_effect_ == &IMG_idle && USBD_Configured()) {
if (EscapeIdleIfNeeded() && current_effect_ == &IMG_idle) {
// We are idle-looping, and usb is connected. Time to stop.
SB_Message("usb");
SetMessage("usb");
return FillFrameBuffer2(advance);
}
#endif
MountSDCard();
{
int count = 0;
Expand Down Expand Up @@ -435,7 +445,8 @@ class StandardDisplayController : public DisplayControllerBase<Width, col_t>, Sa
if (IMG_font) {
ShowFile(&IMG_font, font_config.ProffieOSFontImageDuration);
} else if (prop.current_preset_name()) {
SB_Message(prop.current_preset_name());
SetMessage(prop.current_preset_name());
SetScreenNow(SCREEN_MESSAGE);
} else if (IMG_idle) {
ShowFile(&IMG_idle, 3600000.0);
}
Expand All @@ -460,10 +471,10 @@ class StandardDisplayController : public DisplayControllerBase<Width, col_t>, Sa
}
}

void SB_Message(const char* text) {
void SetMessage(const char* text) {
strncpy(message_, text, sizeof(message_));
message_[sizeof(message_)-1] = 0;
SetScreenNow(SCREEN_MESSAGE);
screen_ = SCREEN_MESSAGE;
}

void SB_Top(uint64_t total_cycles) override {
Expand Down Expand Up @@ -497,20 +508,27 @@ class StandardDisplayController : public DisplayControllerBase<Width, col_t>, Sa
display_->Page();
}

bool ShowFile(Effect* effect, float duration) {
bool SetFile(Effect* effect, float duration) {
if (!*effect) return false;
MountSDCard();
eof_ = true;
file_.Play(effect);
frame_available_ = false;
frame_count_ = 0;
SetScreenNow(SCREEN_IMAGE);
screen_ = SCREEN_IMAGE;
eof_ = false;
current_effect_ = effect;
effect_display_duration_ = duration;
return true;
}

bool ShowFile(Effect* effect, float duration) {
if (SetFile(effect, duration)) {
SetScreenNow(SCREEN_IMAGE);
}
return true;
}

void ShowFile(const char* file) {
MountSDCard();
eof_ = true;
Expand Down

0 comments on commit f383521

Please sign in to comment.