Skip to content

Commit 1151c4f

Browse files
committed
fix idle sd access
1 parent b733cd1 commit 1151c4f

File tree

6 files changed

+28
-48
lines changed

6 files changed

+28
-48
lines changed

ProffieOS.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ void EnableAmplifier();
410410
bool AmplifierIsActive();
411411
void MountSDCard();
412412
const char* GetSaveDir();
413+
bool AvoidIdleSDAccess();
413414

414415
#include "common/lsfs.h"
415416
#include "common/strfun.h"

common/sd_card.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,23 @@ class SDCard : Looper {
8282

8383
SDCard sdcard;
8484
inline void MountSDCard() { sdcard.Mount(); }
85+
86+
bool AvoidIdleSDAccess() {
87+
#ifdef MOUNT_SD_SETTING)
88+
if (LSFS::GetAllowMount()) return true;
89+
#elif defined(USB_CLASS_MSC)
90+
// This fallback won't work as well as the
91+
// MOUNT_SD_SETTING, but it will allow users
92+
// to access the SD card in some cases that
93+
// might otherwise be impossible.
94+
if (USBD_configured()) return true;
95+
#endif
96+
return false;
97+
}
98+
8599
#else
86100
inline void MountSDCard() { }
101+
bool AvoidIdleSDAccess() { return false; }
87102
#endif // v4 && enable_sd
88103

89104
#endif

display/layer_controller.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -531,12 +531,8 @@ class StandarColorDisplayController : public SaberBase, public Looper, public Co
531531
}
532532
} else {
533533
// Off
534-
if (looped_idle_ != Tristate::False) {
535-
// if (EscapeIdleIfNeeded()) {
536-
// SetMessage(" usb\nconnected");
537-
// } else {
534+
if (!AvoidIdleSDAccess()) {
538535
scr_.Play(&SCR_idle);
539-
// }
540536
}
541537
}
542538
}
@@ -549,7 +545,6 @@ class StandarColorDisplayController : public SaberBase, public Looper, public Co
549545
switch (effect) {
550546
case EFFECT_NEWFONT:
551547
looped_on_ = Tristate::Unknown;
552-
looped_idle_ = Tristate::Unknown;
553548
Stop();
554549
if (!scr_.Play(&SCR_font)) {
555550
ShowDefault();
@@ -637,8 +632,6 @@ class StandarColorDisplayController : public SaberBase, public Looper, public Co
637632

638633
// True if IMG_on is looped.
639634
volatile Tristate looped_on_ = Tristate::Unknown;
640-
// True if IMG_idle is looped.
641-
volatile Tristate looped_idle_ = Tristate::Unknown;
642635
};
643636

644637

display/ssd1306.h

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ class DisplayControllerBase {
146146
virtual int FillFrameBuffer(bool advance) = 0;
147147
virtual void SetDisplay(Display<Width, col_t>* display) = 0;
148148
virtual Screen GetScreen() { return SCREEN_UNSET; }
149-
virtual void usb_connected() {}
150149
};
151150

152151
template<int Width, class col_t>
@@ -176,7 +175,6 @@ class DisplayHelper1 {
176175
a->SetDisplay(display);
177176
}
178177
Screen GetScreen() { return a->GetScreen(); }
179-
void usb_connected() { return a->usb_connected(); }
180178
void Advance(int t) { t_ -= t; }
181179
};
182180

@@ -222,11 +220,6 @@ class DisplayHelper : public DisplayControllerBase<Width, col_t> {
222220
}
223221
return SCREEN_UNSET;
224222
}
225-
void usb_connected() override {
226-
for (size_t i = 0; i < sizeof...(OPERATIONS); i++) {
227-
operations_[i].usb_connected();
228-
}
229-
}
230223

231224
int FillFrameBuffer(bool advance) override {
232225
for (size_t i = 0; i < sizeof...(OPERATIONS); i++) {
@@ -407,14 +400,6 @@ class StandardDisplayController : public DisplayControllerBase<Width, col_t>, pu
407400
return last_delay_ = FillFrameBuffer2(advance);
408401
}
409402

410-
#ifdef USB_CLASS_MSC
411-
bool EscapeIdleIfNeeded() {
412-
return looped_idle_ == Tristate::True && USBD_Configured();
413-
}
414-
#else
415-
bool EscapeIdleIfNeeded() { return false; }
416-
#endif
417-
418403
void ShowDefault(bool ignore_lockup = false) {
419404
screen_ = SCREEN_PLI;
420405
t_ = 0;
@@ -427,7 +412,7 @@ class StandardDisplayController : public DisplayControllerBase<Width, col_t>, pu
427412
} else {
428413
// Off
429414
if (looped_idle_ != Tristate::False) {
430-
if (EscapeIdleIfNeeded()) {
415+
if (AvoidIdleSDAccess()) {
431416
SetMessage(" usb\nconnected");
432417
} else {
433418
SetFile(&img_.IMG_idle, 3600000.0);
@@ -518,11 +503,6 @@ class StandardDisplayController : public DisplayControllerBase<Width, col_t>, pu
518503
}
519504

520505
case SCREEN_IMAGE:
521-
if (EscapeIdleIfNeeded() && current_effect_ == &img_.IMG_idle) {
522-
// We are idle-looping, and usb is connected. Time to stop.
523-
SetMessage(" usb\nconnected");
524-
return FillFrameBuffer2(advance);
525-
}
526506
MountSDCard();
527507
{
528508
int count = 0;
@@ -585,14 +565,6 @@ class StandardDisplayController : public DisplayControllerBase<Width, col_t>, pu
585565
}
586566
}
587567

588-
void usb_connected() override {
589-
if (EscapeIdleIfNeeded() && current_effect_ == &img_.IMG_idle) {
590-
// We are idle-looping, and usb is connected. Time to stop.
591-
SetMessage(" usb\nconnected");
592-
SetScreenNow(SCREEN_MESSAGE);
593-
}
594-
}
595-
596568
void ShowFileWithSoundLength(Effect* e, float duration) {
597569
if (duration == 0.0) {
598570
duration = SaberBase::sound_length * 1000;
@@ -1121,13 +1093,6 @@ class SSD1306Template : public Display<WIDTH, col_t>, I2CDevice, Looper, StateMa
11211093
}
11221094

11231095
void Loop() override {
1124-
#ifdef USB_CLASS_MSC
1125-
static bool last_connected = false;
1126-
bool connected = USBD_Configured();
1127-
if (connected && !last_connected) controller_->usb_connected();
1128-
last_connected = connected;
1129-
#endif
1130-
11311096
STATE_MACHINE_BEGIN();
11321097
while(true) {
11331098
on_ = true;

props/prop_base.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,9 +1640,15 @@ class PropBase : CommandParser, Looper, protected SaberBase, public ModeInterfac
16401640
bool mountable = atoi(arg) > 0;
16411641
LSFS::SetAllowMount(mountable);
16421642
if (mountable) {
1643-
// Trigger the IDLE_OFF_TIME behavior to turn off idle sounds and animations.
1644-
// (Otherwise we can't mount the sd card).
1645-
if (!SaberBase::IsOn()) SaberBase::DoOff(OFF_IDLE, 0);
1643+
if (SaberBase::IsOn()) {
1644+
// Turn off. Idle sounds/animations should not start since we already set
1645+
// SetAllowMount to true.
1646+
Off();
1647+
} else {
1648+
// Trigger the IDLE_OFF_TIME behavior to turn off idle sounds and animations.
1649+
// (Otherwise we can't mount the sd card).
1650+
SaberBase::DoOff(OFF_IDLE, 0);
1651+
}
16461652
}
16471653
}
16481654
STDOUT << "SD Access "

sound/hybrid_font.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ class HybridFont : public SaberBase, public Looper {
483483
bool most_blades = location.on_blade(0);
484484
// SFX_in.SetFollowing( most_blades ? &SFX_pstoff : nullptr );
485485
#ifdef ENABLE_IDLE_SOUND
486-
if (most_blades) {
486+
if (most_blades && CurrentIdleAccessState() == IDLE_ACCESS_OK) {
487487
if (SFX_pstoff) {
488488
SFX_in.SetFollowing(&SFX_pstoff);
489489
SFX_pstoff.SetFollowing(&SFX_idle);

0 commit comments

Comments
 (0)