#include <LiquidCrystal_I2C.h>
#include <IRremote.h>
#include <Adafruit_NeoPixel.h>
//Joystick button codes
#define JOYSTICK_UP 1
#define JOYSTICK_CENTER 2
#define JOYSTICK_LEFT 3
#define JOYSTICK_DOWN 4
#define JOYSTICK_RIGHT 5
//IR remote button codes 
#define IRButton_1 1
#define IRButton_2 2
#define IRButton_3 3
#define IRButton_4 4
#define IRButton_5 5
#define IRButton_6 6
#define IRButton_7 7
#define IRButton_8 8
#define IRButton_9 9
#define IRButton_STAR 10 //*
#define IRButton_0 11 
#define IRButton_SHARP 12 //#
#define IRButton_UP 13
#define IRButton_LEFT 14 
#define IRButton_OK 15 
#define IRButton_RIGHT 16 
#define IRButton_DOWN 17 

typedef enum {
  APPSTATE_START = 0,
  APPSTATE_DISPLAY,
  APPSTATE_SETTINGS,
} AppState;

AppState appState = APPSTATE_START;
AppState prevAppState = -1;

LiquidCrystal_I2C lcd(0x20, 16, 2);

void setup() {
  
  Joystick_Init();
  Pot_Init();
  Photosensor_Init();
  IR_Init();
  RGB_Init();
  LCD_Init(&lcd);
  Calendar_Init(2023, 11, 26, 14, 0, 0);

  Serial.begin(115200);
  Serial.println("Start");
  pinMode(13, OUTPUT);
}

void loop() {

    IR_Check();
    Joystick_Check();
    Calendar_Update();

    switch(appState){
      case APPSTATE_START:
        appState = StartScreen(&lcd, prevAppState);
        prevAppState = APPSTATE_START;
        break;
      case APPSTATE_DISPLAY:
        appState = DisplayScreen(&lcd, prevAppState);
        prevAppState = APPSTATE_DISPLAY;
        break;
      case APPSTATE_SETTINGS:
        appState = SettingsScreen(&lcd, prevAppState);
        prevAppState = APPSTATE_SETTINGS;
        break;
    }
    delay(1);
}
