Skocz do zawartości

Mam problem z kodem na arduino ten kod to taki ala system


Pomocna odpowiedź

Napisano
#include <avr/wdt.h>
#define BUZZER_PIN A1
#include <Wire.h> // Added for I2C communication
#include <LiquidCrystal_I2C.h> // Changed library for I2C LCD
#include <DHT.h>
// Prototypy przed uĹźyciem
const char* getAppName(int idx);
int getTotalApps();
bool ustawieniaplus = false;
bool CPUzInstalled = false;
bool debugmode = false;
bool minecraft = false;
int aplikacje = 0;
int downloaded = 0;
bool konsola = false;
// ===================
// Konfiguracja pinĂłw
// ===================
const int pinLeft   = 8;
const int pinRight  = 9;
const int pinUp     = 10;
const int pinDown   = 11;
const int pinSelect = 12;
// ===================
// Konfiguracja LCD
// ===================
// Changed from direct connection to I2C
// Default I2C address is 0x27, change if your display uses a different address
LiquidCrystal_I2C lcd(0x27, 16, 2); // Set the LCD address to 0x27 for a 16 chars and 2 line display
// ===================
// Konfiguracja DHT
// ===================
#define DHTPIN 13
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
// ===================
// Aplikacje bazowe
// ===================
const int baseAppCount = 8;  // 8 pozycji podstawowych
int selectedApp = 0;
// ===================
// Implementacja funkcji getAppName
// ===================
const char* getAppName(int idx) {
  // Tablica nazw aplikacji podstawowych
  const char* baseApps[] = {
    "<Sklep>",
    "<Ustawienia>",
    "<Google Beta>",
    "<Gry>",
    "<Aktualizacje>",
    "<Wyjscie>",
    "<Pliki>",
    "<MenedzerZadan>"
  };
  
  // SprawdĹş czy indeks jest w zakresie podstawowych aplikacji
  if (idx >= 0 && idx < baseAppCount) {
    return baseApps[idx];
  } 
  // SprawdĹş czy to jest aplikacja CPUz (pierwsza po aplikacjach bazowych)
  else if (idx == baseAppCount && CPUzInstalled) {
    return "<CPUz>";
  }
  
  // JeĹli indeks jest niepoprawny, zwrĂłÄ informacjÄ o bĹÄdzie
  return "<BLAD>";
}
// ===================
// Pobieranie nazwy aplikacji
// ===================
const char* consoleItems[] = {
  "<Info>",
  "<ResetSettings>",
  "<TestSensor>",
  "<Reboot>",
  "<Back>"
};
const int consoleItemCount = sizeof(consoleItems) / sizeof(consoleItems[0]);
// Prototyp na gĂłrze pliku
void consoleMode() {
  Serial.begin(115200);
  lcd.clear();
  lcd.print(" CONSOLE MODE ");
  delay(1000);
  int sel = 0;
  int lastSel = -1;
  while (true) {
    // đĽ jeĹli trzymasz L+R, wracasz od razu do bootâmenu
    if (digitalRead(pinLeft) == LOW && digitalRead(pinRight) == LOW) {
      debugmode = false;
      setup();
      return;
    }
    // đ wyĹwietl item tylko jak siÄ zmieni
    if (sel != lastSel) {
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print(">");                        // drukujemy strzaĹkÄ
      lcd.print(consoleItems[sel]);          // drukujemy nazwÄ opcji
      lcd.setCursor(0, 1);
      lcd.print(" Use SEL ");
      lastSel = sel;
    }
    // âď¸âśď¸ nawigacja
    if (digitalRead(pinLeft) == LOW) {
      sel = (sel - 1 + consoleItemCount) % consoleItemCount;
      delay(200);
    }
    if (digitalRead(pinRight) == LOW) {
      sel = (sel + 1) % consoleItemCount;
      delay(200);
    }
    // â wybĂłr
    if (digitalRead(pinSelect) == LOW) {
      lcd.clear();
      lcd.print(consoleItems[sel]);
      Serial.print("CMD: ");
      Serial.println(consoleItems[sel]);
      delay(500);
      switch (sel) {
        case 0: // <Info>
          Serial.println("OSmars 6.0, UNO R3");
          lcd.clear();
          lcd.print("OS 6.0 UNO R3");
          delay(1500);
          break;
        case 1: // <ResetSettings>
          // tu czyĹcisz EEPROM/zmienne
          Serial.println("Settings reset!");
          lcd.clear();
          lcd.print("Settings reset");
          delay(1500);
          break;
        case 2: { // <TestSensor>
          float t = dht.readTemperature();
          float h = dht.readHumidity();
          if (isnan(t) || isnan(h)) {
            Serial.println("Sensor error");
            lcd.clear();
            lcd.print("DHT error");
          } else {
            Serial.print("T="); Serial.print(t);
            Serial.print("C H="); Serial.print(h);
            Serial.println("%");
            lcd.clear();
            lcd.print(t); lcd.print("C ");
            lcd.setCursor(0,1);
            lcd.print(h); lcd.print("%");
          }
          delay(2000);
          break;
        }
        case 3: // <Reboot>
          Serial.println("Rebooting...");
          lcd.clear(); lcd.print("Rebooting...");
          delay(1000);
          setup();
          return;
        case 4: // <Back>
          Serial.println("Back to menu");
          lcd.clear();
          delay(200);
          setup();
          return;
      }
      lastSel = -1; // wymuĹ przerysowanie menu
    }
  }
}
void efektPisania(const char* text, int row = 0) {
  lcd.setCursor(0, row);
  for (int i = 0; text[i] != '\0'; i++) {
    lcd.print(text[i]);
    delay(100);
  }
}
// ===================
// Prototypy funkcji
// ===================
void showSelectedAppName();
void moveLeft();
void moveRight();
void selectApp();
void sklepik();
void showSettings();
void showGoogleBeta();
void showGame();
void aktualizacje();         
void exitSystem();
void autor();
void showTemperature();
void CPUz();
void ustawieniaPlus();
void blueScreen(const char*);
void altF4Fake();
void showTaskManager();
void showFiles();
void minecraftfreeedition();
void minecraftfree();
void minecraftinstall();
void BSOD();
void BSODmc();
void killall();
// ===================
// Setup i Loop
// ===================
void setup() {
  // --- inicjalizacja pinĂłw, LCD, DHT itp. ---
  pinMode(BUZZER_PIN, OUTPUT);
  pinMode(pinLeft,   INPUT_PULLUP);
  pinMode(pinRight,  INPUT_PULLUP);
  pinMode(pinUp,     INPUT_PULLUP);
  pinMode(pinDown,   INPUT_PULLUP);
  pinMode(pinSelect, INPUT_PULLUP);
  
  // Initialize the I2C bus
  Wire.begin();
  
  // Initialize the LCD with I2C
  lcd.init();
  lcd.backlight(); // Turn on backlight
  
  dht.begin();
  // --- wykrycie debugmode przy starcie ---
  // --- softâbootloader tylko gdy debugmode ---
  if (debugmode) {
    unsigned long start = millis();
    int choice = 1; // 0 = Konsola, 1 = OSmars
    while (millis() - start < 5000) {
      lcd.setCursor(0,0); lcd.print("BOOT: L=Konsola");
      lcd.setCursor(0,1); lcd.print("      R=OSmars ");
      if (digitalRead(pinLeft)==HIGH)  choice = 0;
      if (digitalRead(pinRight)==HIGH) choice = 1;
      delay(100);
    }
    lcd.clear();
    if (choice == 0) {
      consoleMode();
    }
  }
  // --- normalny start OSmars (lub debugmode==false) ---
  // 1) ekran powitalny
  lcd.clear();
  lcd.setCursor(1,0); lcd.print("  Welcome to");
  lcd.setCursor(0,1); lcd.print("   OSmars 6!");
  delay(2000);
  // 2) pasek Ĺadowania
  lcd.clear();
  lcd.setCursor(1,0); lcd.print(" LOADING...");
  for (int i = 0; i < 16; i++) {
    lcd.setCursor(i,1);
    lcd.print('#');
    delay(100);
  }
  // 3) efekt pisania
  lcd.clear();
  efektPisania("Witaj w OSmars", 0);
  efektPisania("System booting...", 1);
  delay(2000);
  // 4) start menu
  showSelectedAppName();
}
void loop() {
  // Alt+F4 shortcut: Up+Down
  if (digitalRead(pinUp) == HIGH && digitalRead(pinDown) == HIGH) {
    altF4Fake();
    delay(500);
    return;
  }
  // Toggle debug: Left+Right
  if (digitalRead(pinLeft) == HIGH && digitalRead(pinRight) == HIGH) {
    debugmode = !debugmode;
    lcd.clear();
    lcd.print(debugmode ? "debug mode on" : "debug mode off");
    delay(1000);
    showSelectedAppName();
    return;
  }
  // Normal button handling
  if (digitalRead(pinLeft)   == HIGH) { moveLeft();   delay(150); }
  if (digitalRead(pinRight)  == HIGH) { moveRight();  delay(150); }
  if (digitalRead(pinUp)     == HIGH) { moveLeft();   delay(150); }
  if (digitalRead(pinDown)   == HIGH) { moveRight();  delay(150); }
  if (digitalRead(pinSelect) == HIGH)  { selectApp();  delay(150); }
}
// ===================
// Funkcje menu
// ===================
void showSelectedAppName() {
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Aplikacja:");
  lcd.setCursor(0, 1);
  lcd.print(getAppName(selectedApp));
}
void moveLeft() {
  selectedApp = (selectedApp > 0) ? selectedApp - 1 : getTotalApps() - 1;
  showSelectedAppName();
}
void moveRight() {
  selectedApp = (selectedApp < getTotalApps() - 1) ? selectedApp + 1 : 0;
  showSelectedAppName();
}
void selectApp() {
  int total = getTotalApps();  // Pobranie ĹÄcznej liczby aplikacji
  if (selectedApp < 0 || selectedApp >= total) {
    blueScreen("C:1000");  // JeĹli indeks aplikacji jest nieprawidĹowy, wyĹwietl komunikat o bĹÄdzie
    return;
  }
  lcd.clear();  // Czyszczenie ekranu
  lcd.setCursor(0, 0); 
  efektPisania("STARTING:", 0);  // Efekt pisania "STARTING:"
  lcd.setCursor(0, 1); 
  lcd.print(getAppName(selectedApp));  // Wydrukowanie nazwy aplikacji na ekranie
  delay(800);  // Czekaj przez 800 ms
  // PrzeĹÄczanie na odpowiedniÄ aplikacjÄ w zaleĹźnoĹci od wybranego indeksu
  switch (selectedApp) {
    case 0: sklepik();        break;
    case 1: showSettings();   break;
    case 2: showGoogleBeta(); break;
    case 3: showGame();       break;
    case 4: aktualizacje();   break;
    case 5: exitSystem();     break;
    case 6: showFiles();      break;
    case 7: showTaskManager();break;
    case 8: showTemperature();break;
    default: break; // W przypadku nieprawidĹowego indeksu
  }
}
void uninstallApp(int appIndex) {
  switch (appIndex) {
    case 0: // <CPUz>
      CPUzInstalled = false;
      break;
    case 1: // <Ustawienia+>
      ustawieniaplus = false;
      break;
    default:
      break;
  }
  lcd.clear();
  efektPisania("App uninstalled", 0);
  delay(2000);
  showSelectedAppName();
}
void wyjscie() {
  lcd.clear(); lcd.print("wychodzenie");
  lcd.setCursor(0,1); lcd.print("czekaj");
  delay(1000);
  showSelectedAppName();
}
void altF4Fake() {
  lcd.clear(); lcd.print("ALT+F4 pressed");
  lcd.setCursor(0,1); lcd.print("TASK KILLED");
  delay(2000);
  showSelectedAppName();
}
void sklepik() {
  int sel = 0;
  int lastSel = -1;
  const char* items[] = {"<CPUz>", "<Ustawienia+>", "<konsola>", "<Wyjscie>"};
  while (true) {
    // Alt+F4 in shop
    if (digitalRead(pinUp) == HIGH && digitalRead(pinDown) == HIGH) {
      altF4Fake();
      break;
    }
    // debug in shop
    if (digitalRead(pinLeft) == HIGH && digitalRead(pinRight) == HIGH) {
      debugmode = !debugmode;
      lcd.clear();
      lcd.print(debugmode ? "debug mode on" : "debug mode off");
      delay(1000);
      break;
    }
    // đ Ekran tylko jeĹli coĹ siÄ zmieniĹo
    if (sel != lastSel) {
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("OSmars Store");
      lcd.setCursor(0, 1);
      lcd.print(items[sel]);
      lastSel = sel;
    }
    if (digitalRead(pinLeft) == HIGH)  { sel = (sel > 0) ? sel - 1 : 2; delay(200); }
    if (digitalRead(pinRight) == HIGH) { sel = (sel < 3) ? sel + 1 : 0; delay(200); }
    if (digitalRead(pinSelect) == HIGH) {
      delay(200);
      if      (sel == 0) { CPUz(); }
      else if (sel == 1) { ustawieniaPlus(); }
      else if (sel == 2) { 
        konsola = true;
      }
      else {               // sel == 3
        break;             // Wyjscie
      }
    }
  }
  showSelectedAppName();
}
int getTotalApps() {
  return CPUzInstalled ? baseAppCount + 1 : baseAppCount;  // ZwrĂłci 9, jeĹli CPUz jest zainstalowane
}
void minecraftfreeedition() {
  int sel = 0;
  int lastSel = -1;
  int lastAplikacje = -1;
  // Upewnij siÄ, Ĺźe masz globalnie zadeklarowane:
  // int aplikacje;
  // bool debugmode;
  // const int pinUp, pinDown, pinLeft, pinRight, pinSelect;
  
  const char* items[] = {"<yes>", "<no>"};
  while (true) {
    // Alt+F4: gĂłra+dĂłĹ
    if (digitalRead(pinUp) == HIGH && digitalRead(pinDown) == HIGH) {
      altF4Fake();
      break;
    }
    // Tryb debug: lewo+prawo
    if (digitalRead(pinLeft) == HIGH && digitalRead(pinRight) == HIGH) {
      debugmode = !debugmode;
      lcd.clear();
      lcd.print(debugmode ? "debug mode on" : "debug mode off");
      delay(1000);
      break;
    }
    // đ§  OdĹwieĹź ekran CZEMĂ siÄ zmieniĹo
    if (sel != lastSel || aplikacje != lastAplikacje) {
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("install this app?");
      lcd.setCursor(0, 1);
      lcd.print(items[sel]);
      lastSel = sel;
      lastAplikacje = aplikacje;
    }
    // đ ObsĹuga przyciskĂłw z debounce
    if (digitalRead(pinLeft) == HIGH) {
      sel = (sel > 0) ? sel - 1 : 1;
      delay(200);
    }
    if (digitalRead(pinRight) == HIGH) {
      sel = (sel < 1) ? sel + 1 : 0;
      delay(200);
    }
    // đ WciĹniÄcie SELECT
    if (digitalRead(pinSelect) == HIGH) {
      delay(200); // proste odtrzepanie drgaĹ
      if (sel == 0) {
        minecraftinstall();
      } else {
        showGoogleBeta();
        break;
      }
    }
  }
}
void minecraftinstall(){
  lcd.clear();
  lcd.setCursor(1, 0); lcd.print("downloading...");
  lcd.setCursor(0, 1);
  for (int i = 0; i < 16; i++) {
    lcd.setCursor(i, 1);
    lcd.print('#');
    delay(1000);
  }
  lcd.clear();
  lcd.setCursor(1, 0); lcd.print(" installing...");
  lcd.setCursor(0, 1);
  for (int i = 0; i < 16; i++) {
    lcd.setCursor(i, 1);
    lcd.print('#');
    delay(500);
    minecraft = true;
  }
  minecraftfreeedition();
}
void showGoogleBeta(){
  int sel = 0;
  int lastSel = -1;
  int lastAplikacje = -1;
  const char* items[] = {"<minecraftfreedownload.com>", "<Wyjscie>"};
  while (true) {
    if (digitalRead(pinUp) == HIGH && digitalRead(pinDown) == HIGH) {
      altF4Fake(); break;
    }
    if (digitalRead(pinLeft) == HIGH && digitalRead(pinRight) == HIGH) {
      debugmode = !debugmode;
      lcd.clear();
      lcd.print(debugmode ? "debug mode on" : "debug mode off");
      delay(1000);
      break;
    }
    // đ§  Ekran odĹwieĹźaj TYLKO, jeĹli coĹ siÄ zmieniĹo
    if (sel != lastSel || aplikacje != lastAplikacje) {
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("strona: ");
      lcd.setCursor(0, 1);
      lcd.print(items[sel]);
      lastSel = sel;
      lastAplikacje = aplikacje;
    }
    // đ ObsĹuga przyciskĂłw
    if (digitalRead(pinLeft) == HIGH)  { sel = (sel > 0) ? sel - 1 : 1; delay(200); }
    if (digitalRead(pinRight) == HIGH) { sel = (sel < 1) ? sel + 1 : 0; delay(200); }
    if (digitalRead(pinSelect) == HIGH) {
      delay(200);
      if (sel == 0) {
        minecraftfreeedition();
      } else {
        showSelectedAppName();
        break;
      }
    }
  }
  showSelectedAppName();
}
void CPUz() {
  lcd.clear(); lcd.setCursor(1,0); lcd.print("Downloading...");
  delay(800);
  for(int i=0; i<16; i++){
    lcd.setCursor(0,1);
    for(int j=0; j<16; j++) lcd.print(j<=i?'=':' ');
    delay(100);
  }
  CPUzInstalled = true;
  showSelectedAppName();
}
void showTemperature() {
  aplikacje = aplikacje + 1;
  float t = dht.readTemperature();
  lcd.clear();
  if (isnan(t)) {
    lcd.print("Error reading"); lcd.setCursor(0,1); lcd.print("temperature");
  } else {
    lcd.setCursor(0,1); lcd.print("Temp: "); lcd.print(t); lcd.print("C");
    lcd.setCursor(1,0); lcd.print("UNO R3");
  }
}
void ustawieniaPlus() {
  ustawieniaplus = true;
  lcd.clear(); lcd.print("Downloading+"); delay(800);
  showSelectedAppName();
}
void showSettings() {
  lcd.clear(); lcd.print("system: OSmars 6"); delay(1000);
  lcd.clear(); lcd.print("Arduino: UNO R3"); delay(1000);
  showSelectedAppName();
}
void showGame() {
  int sel = 0;
  int lastSel = -1;
  while (true) {
    const char* items[2];
    int itemCount = 0;
    if (minecraft) {
      items[itemCount++] = "<minecraft>";
    }
    items[itemCount++] = "<Wyjscie>";
    // Alt+F4 / debug
    if (digitalRead(pinUp) == HIGH && digitalRead(pinDown) == HIGH) {
      altF4Fake(); 
      break;
    }
    if (digitalRead(pinLeft) == HIGH && digitalRead(pinRight) == HIGH) {
      debugmode = !debugmode;
      lcd.clear();
      lcd.print(debugmode ? "debug mode on" : "debug mode off");
      delay(1000);
      break;
    }
    // ObsĹuga nawigacji
    if (digitalRead(pinDown) == HIGH) {
      sel = (sel + 1) % itemCount;
      delay(200); // debouncing
    }
    if (digitalRead(pinUp) == HIGH) {
      sel = (sel - 1 + itemCount) % itemCount;
      delay(200); // debouncing
    }
    if (sel != lastSel) {
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("gry:");
      lcd.setCursor(0, 1);
      lcd.print(items[sel]);
      lastSel = sel;
    }
    // ObsĹuga wyboru
    if (digitalRead(pinSelect) == HIGH) {
      if (strcmp(items[sel], "<minecraft>") == 0) {
        BSODmc();
      } else if (strcmp(items[sel], "<Wyjscie>") == 0) {
        BSOD();
      }
      delay(300); // debouncing
    }
  }
}
// âZwykĹy" Blue Screen of Death
void BSOD() {
  efektPisania("ę§ŕźâŹâ ď¸ď¸ đŻđđđ đžđđđ â ď¸ď¸âŹŕźę§  ", 0); lcd.clear();
  efektPisania("ę§ŕźâŹâ ď¸ď¸ đŻđđđ đžđđđ â ď¸ď¸âŹŕźę§  ", 0); lcd.clear();
  efektPisania("ę§ŕźâŹâ ď¸ď¸ đŻđđđ đžđđđ â ď¸ď¸âŹŕźę§  ", 0); lcd.clear();
  // â raz wyĹwietlamy ekran BSOD na LCD â
  lcd.clear();
  lcd.setCursor(0, 0);
  efektPisania("!!SYSTEM CRASH !!", 0);
  lcd.setCursor(0, 1);
  efektPisania(":(     E:001      ", 1);
  delay(3000);
  // â ustawiamy punkt startu i zaczynamy piszczenie â
  unsigned long start = millis();
  while (millis() - start < 10000) {  // przez 10 sekund
    tone(BUZZER_PIN, 800);  // 800 Hz
    delay(200);
    noTone(BUZZER_PIN);
    delay(50);
  }
  // â po 10 s wymuszamy reset przez Watchdoga â
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Restarting...");
  delay(500);
  wdt_enable(WDTO_15MS); // ustawia 15 ms timeout
  while (true) {
    // czekamy na wywoĹanie resetu
  }
}
// âMC edition" Blue Screen
void BSODmc() {
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("running mc...");
  delay(3000);
  lcd.clear();
  efektPisania("!!SYSTEM CRASH!!", 0);
  efektPisania(":(    E:666     ", 1);
  delay(2000);
    while (true) {
    tone(BUZZER_PIN, 1200); // nieco wyĹźszy ton dla MCa
    delay(150);
    noTone(BUZZER_PIN);
    delay(50);
  }
}
void autor() {
  int sel = 0;
  int lastSel = -1;
  int lastAplikacje = -1;
  const char* items[] = {"<CPUz>", "<Wyjscie>"};
  while (true) {
    if (digitalRead(pinUp) == HIGH && digitalRead(pinDown) == HIGH) {
      altF4Fake(); break;
    }
    if (digitalRead(pinLeft) == HIGH && digitalRead(pinRight) == HIGH) {
      debugmode = !debugmode;
      lcd.clear();
      lcd.print(debugmode ? "debug mode on" : "debug mode off");
      delay(1000);
      break;
    }
    // đ§  Ekran odĹwieĹźaj TYLKO, jeĹli coĹ siÄ zmieniĹo
    if (sel != lastSel || aplikacje != lastAplikacje) {
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("aplikacje: ");
      lcd.print(aplikacje);
      lcd.setCursor(0, 1);
      lcd.print(items[sel]);
      lastSel = sel;
      lastAplikacje = aplikacje;
    }
    // đ ObsĹuga przyciskĂłw
    if (digitalRead(pinLeft) == HIGH)  { sel = (sel > 0) ? sel - 1 : 1; delay(200); }
    if (digitalRead(pinRight) == HIGH) { sel = (sel < 1) ? sel + 1 : 0; delay(200); }
    if (digitalRead(pinSelect) == HIGH) {
      delay(200);
      if (sel == 0) {
        killall();
      } else {
        showSelectedAppName();
        break;
      }
    }
  }
}
void aktualizacje() {
  lcd.clear(); lcd.print("skanowanie..."); delay(1000);
  for (int i = 0; i < 16; i++) {
    lcd.setCursor(i, 1);
    lcd.print('#');
    delay(100);
  }
  lcd.clear(); lcd.print("sprawdzanie OS"); delay(5000);
  for (int i = 0; i < 16; i++) {
    lcd.setCursor(i, 1);
    lcd.print('#');
    delay(100);
  }
  lcd.clear(); lcd.print("brak dostepnych"); delay(1000); lcd.setCursor(0,1); lcd.print("aktualizacji"); delay(4000);
  lcd.clear(); lcd.print("restarting..."); delay(2000);
  setup();
}
void exitSystem() {
  lcd.clear(); efektPisania("OSmars REBOOTING",0); delay(6000); setup();
}
void blueScreen(const char* code) {
  lcd.clear(); lcd.setCursor(0,0); lcd.print("!! SYSTEM CRASH !!");
  lcd.setCursor(0,1); lcd.print(code); while(1);
}
void killall() {
  aplikacje = 0;
  lcd.clear();
  efektPisania("all tasks killed", 0);
  delay(2000);
  showTaskManager();
}
void showTaskManager() {
  int sel = 0;
  int lastSel = -1;
  int lastAplikacje = -1;
  const char* items[] = {"<killall>", "<Wyjscie>"};
  while (true) {
    if (digitalRead(pinUp) == HIGH && digitalRead(pinDown) == HIGH) {
      altF4Fake(); break;
    }
    if (digitalRead(pinLeft) == HIGH && digitalRead(pinRight) == HIGH) {
      debugmode = !debugmode;
      lcd.clear();
      lcd.print(debugmode ? "debug mode on" : "debug mode off");
      delay(1000);
      break;
    }
    // đ§  Ekran odĹwieĹźaj TYLKO, jeĹli coĹ siÄ zmieniĹo
    if (sel != lastSel || aplikacje != lastAplikacje) {
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("aplikacje: ");
      lcd.print(aplikacje);
      lcd.setCursor(0, 1);
      lcd.print(items[sel]);
      lastSel = sel;
      lastAplikacje = aplikacje;
    }
    // đ ObsĹuga przyciskĂłw
    if (digitalRead(pinLeft) == HIGH)  { sel = (sel > 0) ? sel - 1 : 1; delay(200); }
    if (digitalRead(pinRight) == HIGH) { sel = (sel < 1) ? sel + 1 : 0; delay(200); }
    if (digitalRead(pinSelect) == HIGH) {
      delay(200);
      if (sel == 0) {
        killall();
      } else {
        showSelectedAppName();
        break;
      }
    }
  }
  showSelectedAppName();
}
void showFiles() {
  int sel = 0;
  int lastSel = -1;
  while (true) {
    // âď¸ Zbuduj dynamicznie listÄ aptek + exit
    const char* items[3];
    int itemCount = 0;
    if (CPUzInstalled) {
      items[itemCount++] = "<CPUz>";
    }
    if (ustawieniaplus) {
      items[itemCount++] = "<Ustawienia+>";
    }
    items[itemCount++] = "<Wyjscie>";
    // đ ObsĹuga Alt+F4 / debug
    if (digitalRead(pinUp) == HIGH && digitalRead(pinDown) == HIGH) { 
      altF4Fake(); 
      break; 
    }
    if (digitalRead(pinLeft) == HIGH && digitalRead(pinRight) == HIGH) {
      debugmode = !debugmode;
      lcd.clear();
      lcd.print(debugmode ? "debug mode on" : "debug mode off");
      delay(1000);
      break;
    }
    // đ OdĹwieĹź ekran jeĹli zmieniĹ siÄ sel
    if (sel != lastSel) {
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Pliki:");
      lcd.setCursor(0, 1);
      lcd.print(items[sel]);
      lastSel = sel;
    }
    // âď¸âśď¸ Nawigacja
    if (digitalRead(pinLeft) == HIGH)  { sel = (sel > 0) ? sel - 1 : itemCount - 1; delay(150); }
    if (digitalRead(pinRight) == HIGH) { sel = (sel < itemCount - 1) ? sel + 1 : 0; delay(150); }
    // â WybĂłr
    if (digitalRead(pinSelect) == HIGH) {
      delay(150);
      // jeĹli Wyjscie
      if (sel == itemCount - 1) break;
      // odinstaluj CPUz
      if (CPUzInstalled && sel == 0) {
        CPUzInstalled = false;
        lcd.clear();
        efektPisania("CPUz removed", 0);
        delay(1500);
      }
      // odinstaluj Ustawienia+
      else if (ustawieniaplus && ((CPUzInstalled && sel == 1) || (!CPUzInstalled && sel == 0))) {
        ustawieniaplus = false;
        lcd.clear();
        efektPisania("Ustaw+ removed", 0);
        delay(1500);
      }
      break;
    }
  }
  showSelectedAppName();
}

 

  • Lubię! 1

Bug w showFiles():

if (CPUzInstalled && sel == 0) { CPUzInstalled = false; ... }

– Jeśli CPUzInstalled == false i ustawieniaplus == true, to sel == 0 odnosi się do Ustawienia+, ale przypadek ten nie jest poprawnie obsłużony (trzeba uwzględnić offsety w indeksowaniu zależne od obu flag).

 

Dodatkowo: podziel ten plik na kilka mniejszych źródeł, będzie łatwiej go analizować i ogarniać - np. cała sekcja z prototypami funkcji aż się prosi by ją przenieść do pliku .h.

Zastanów się też czy tak częste używanie delay() to dobry pomysł. 

Bądź aktywny - zaloguj się lub utwórz konto!

Tylko zarejestrowani użytkownicy mogą komentować zawartość tej strony

Utwórz konto w ~20 sekund!

Zarejestruj nowe konto, to proste!

Zarejestruj się »

Zaloguj się

Posiadasz własne konto? Użyj go!

Zaloguj się »
×
×
  • Utwórz nowe...