diff --git a/code/LCDScreen.cpp b/code/LCDScreen.cpp index c81db86..df04b9d 100644 --- a/code/LCDScreen.cpp +++ b/code/LCDScreen.cpp @@ -2,7 +2,7 @@ #include enum LCDScreenState { - DISPLAY_DEFAULT_MESSAGE, + DISPLAY_DEFAULT_MESSAGE = 0, DISPLAY_TEMPERATURE, DISPLAY_PARKING_SPOTS }; @@ -11,10 +11,16 @@ class LCDScreen { private: LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27,20,4); - LCDScreenState state; + LCDScreenState current_state; String default_message = "Bem vindo!"; public: + LCDScreenState ordered_states[3] = { + DISPLAY_DEFAULT_MESSAGE, + DISPLAY_TEMPERATURE, + DISPLAY_PARKING_SPOTS + }; + LCDScreen(String default_message = ""){ if (default_message != ""){ this->default_message = default_message; @@ -32,10 +38,7 @@ class LCDScreen { } void display_temperature(float temp){ - if (this->state != DISPLAY_TEMPERATURE){ - this->clear(); - this->state = DISPLAY_TEMPERATURE; - } + lcd.setCursor(0, 0); lcd.print("Temp: "); lcd.print(temp,1); @@ -43,19 +46,13 @@ class LCDScreen { } void display_default_message(){ - if (this->state != DISPLAY_DEFAULT_MESSAGE){ - this->clear(); - this->state = DISPLAY_DEFAULT_MESSAGE; - } + lcd.setCursor(0, 0); lcd.print(this->default_message); } void display_parking_spots(int total_spots, int occupied_spots){ - if (this->state != DISPLAY_PARKING_SPOTS){ - this->clear(); - this->state = DISPLAY_PARKING_SPOTS; - } + int free_spots = total_spots - occupied_spots; lcd.setCursor(0, 0); lcd.print("Occupied: "); @@ -67,4 +64,31 @@ class LCDScreen { lcd.print(free_spots); } -}; \ No newline at end of file + LCDScreenState get_next_state(){ + return this->ordered_states[this->current_state + 1]; + } + + LCDScreenState get_previous_state(){ + return this->ordered_states[this->current_state - 1]; + } + + void set_state(LCDScreenState state){ + this->clear(); + this->current_state = state; + } + + void display(float temperature_in_c, int total_spots, int occupied_spots){ + switch(this->current_state){ + case DISPLAY_DEFAULT_MESSAGE: + this->display_default_message(); + break; + case DISPLAY_TEMPERATURE: + this->display_temperature(temperature_in_c); + break; + case DISPLAY_PARKING_SPOTS: + this->display_parking_spots(total_spots, occupied_spots); + break; + } + } + +};