44#include  " config.h" 
55#include  " player.h" 
66#include  " display.h" 
7+ #include  " network.h" 
78#include  " netserver.h" 
89
910long  encOldPosition  = 0 ;
@@ -67,14 +68,14 @@ decode_results irResults;
6768#if  ENC_BTNL!=255
6869void  IRAM_ATTR readEncoderISR ()
6970{
70-   if (display.mode ()==LOST || display.mode ()==UPDATING) return ;
71+   if ((SDC_CS== 255  &&  display.mode ()==LOST)  || display.mode ()==UPDATING) return ;
7172  encoder.readEncoder_ISR ();
7273}
7374#endif 
7475#if  ENC2_BTNL!=255
7576void  IRAM_ATTR readEncoder2ISR ()
7677{
77-   if (display.mode ()==LOST || display.mode ()==UPDATING) return ;
78+   if ((SDC_CS== 255  &&  display.mode ()==LOST)  || display.mode ()==UPDATING) return ;
7879  encoder2.readEncoder_ISR ();
7980}
8081#endif 
@@ -129,8 +130,9 @@ void initControls() {
129130}
130131
131132void  loopControls () {
132-   if (display.mode ()==LOST || display.mode ()==UPDATING || display.mode ()==SDCHANGE) return ;
133-   if  (ctrls_on_loop) ctrls_on_loop ();
133+   if (display.mode ()==UPDATING || display.mode ()==SDCHANGE) return ;
134+   if (SDC_CS==255  && display.mode ()==LOST) return ;
135+   if (ctrls_on_loop) ctrls_on_loop ();
134136#if  ENC_BTNL!=255
135137  encoder1Loop ();
136138#endif 
@@ -152,11 +154,13 @@ void loopControls() {
152154  irLoop ();
153155#endif 
154156#if  (TS_MODEL!=TS_MODEL_UNDEFINED) && (DSP_MODEL!=DSP_DUMMY)
155-   touchscreen.loop ();
157+   if  (network. status  == CONNECTED || network. status ==SDREADY)  touchscreen.loop ();
156158#endif 
157159}
158160#if  ENC_BTNL!=255 || ENC2_BTNL!=255
159161void  encodersLoop (yoEncoder *enc, bool  first){
162+   if  (network.status  != CONNECTED && network.status !=SDREADY) return ;
163+   if (display.mode ()==LOST) return ;
160164  int8_t  encoderDelta = enc->encoderChanged ();
161165  if  (encoderDelta!=0 )
162166  {
@@ -246,6 +250,8 @@ void irLoop() {
246250    for (int  target=0 ; target<17 ; target++){
247251      for (int  j=0 ; j<3 ; j++){
248252        if (config.ircodes .irVals [target][j]==irResults.value ){
253+           if  (network.status  != CONNECTED && network.status !=SDREADY && target!=IR_AST) return ;
254+           if (target!=IR_AST && display.mode ()==LOST) return ;
249255          switch  (target){
250256            case  IR_PLAY: {
251257                irBlink ();
@@ -402,6 +408,7 @@ boolean checklpdelay(int m, unsigned long &tstamp) {
402408}
403409
404410void  onBtnDuringLongPress (int  id) {
411+   if  (network.status  != CONNECTED && network.status !=SDREADY) return ;
405412  if  (checklpdelay (BTN_LONGPRESS_LOOP_DELAY, lpdelay)) {
406413    switch  ((controlEvt_e)id) {
407414      case  EVT_BTNLEFT: {
@@ -457,6 +464,8 @@ void controlsEvent(bool toRight, int8_t volDelta) {
457464}
458465
459466void  onBtnClick (int  id) {
467+   bool  passBnCenter = (controlEvt_e)id==EVT_BTNCENTER || (controlEvt_e)id==EVT_ENCBTNB || (controlEvt_e)id==EVT_ENC2BTNB;
468+   if  (network.status  != CONNECTED && network.status !=SDREADY && (controlEvt_e)id!=EVT_BTNMODE && !passBnCenter) return ;
460469  switch  ((controlEvt_e)id) {
461470    case  EVT_BTNLEFT: {
462471        controlsEvent (false );
@@ -479,6 +488,11 @@ void onBtnClick(int id) {
479488          #endif 
480489          player.sendCommand ({PR_PLAY, display.currentPlItem });
481490        }
491+         if (network.status ==SOFT_AP || display.mode ()==LOST){
492+           #ifdef  USE_SD
493+             config.changeMode ();
494+           #endif 
495+         }
482496        break ;
483497      }
484498    case  EVT_BTNRIGHT: {
@@ -517,6 +531,7 @@ void onBtnDoubleClick(int id) {
517531  switch  ((controlEvt_e)id) {
518532    case  EVT_BTNLEFT: {
519533        if  (display.mode () != PLAYER) return ;
534+         if  (network.status  != CONNECTED && network.status !=SDREADY) return ;
520535        player.prev ();
521536        break ;
522537      }
@@ -529,6 +544,7 @@ void onBtnDoubleClick(int id) {
529544      }
530545    case  EVT_BTNRIGHT: {
531546        if  (display.mode () != PLAYER) return ;
547+         if  (network.status  != CONNECTED && network.status !=SDREADY) return ;
532548        player.next ();
533549        break ;
534550      }
0 commit comments