Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*****************************************************************************
- * University of Southern Denmark
- * Embedded C Programming (ECP)
- *
- * MODULENAME.: .c
- *
- * PROJECT....: ECP
- *
- * DESCRIPTION: See module specification file (.h-file).
- *
- * Change Log:
- ******************************************************************************
- * Date Id Change
- * YYMMDD
- * --------------------
- * 180507 KA Module created.
- *
- *****************************************************************************/
- /***************************** Include files *******************************/
- #include <stdint.h>
- #include <ui.h>
- #include "tm4c123gh6pm.h"
- #include "FreeRTOS.h"
- #include "Task.h"
- #include "queue.h"
- #include "semphr.h"
- #include "emp_type.h"
- #include "lcd.h"
- #include "string.h"
- #include "device.h"
- /***************************** Defines *******************************/
- #define O92 0
- #define O95 1
- #define E10 2
- /***************************** Constants *******************************/
- extern QueueHandle_t keyboard_queue;
- extern QueueHandle_t cash_queue;
- extern QueueHandle_t gas_queue;
- extern SemaphoreHandle_t paid;
- extern SemaphoreHandle_t start_signal;
- extern SemaphoreHandle_t digi_signal;
- /***************************** Variables *******************************/
- /***************************** Functions *******************************/
- INT16U calculate_price(INT16U fuel_type, INT16U fuel_count)
- {
- INT16U price = 0;
- switch(fuel_type)
- {
- case 1:
- price = fuel_count*1;
- break;
- case 2:
- price = fuel_count*2;
- break;
- case 3:
- price = fuel_count*3;
- break;
- }
- return price;
- }
- void ui_init(void)
- /*****************************************************************************
- * Input : -
- * Output : -
- * Function :
- *****************************************************************************/
- {
- INT8S dummy;
- // Enable the GPIO port that is used for the on-board LED.
- SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOD;
- // Do a dummy read to insert a few cycles after enabling the peripheral.
- dummy = SYSCTL_RCGC2_R;
- }
- void ui_task(void *pvParameters)
- {
- INT8U ui_state = WELCOME;
- INT8U keyboard_input;
- INT8U pin_counter = 0;
- INT8U account_counter = 0;
- INT16U fuel_select;
- INT16U cash_balance = 0;
- INT16U fuel_amount = 0;
- INT16U ticks = pdMS_TO_TICKS(20);
- while(1)
- {
- switch(ui_state)
- {
- case WELCOME:
- gfprintf(COM2,"%c%cWelcome!",ESC,'@');
- move_LCD(0, 1);
- gfprintf(COM2, "1.Cash 2.Account");
- if(xQueueReceive(keyboard_queue, &keyboard_input, 100))
- {
- switch(keyboard_input)
- {
- case '1':
- xSemaphoreGive(digi_signal);
- ui_state = CASH;
- gfprintf(COM2, "%c%c%cInsert Cash:", 0xFF, ESC, '@');
- move_LCD(0,1);
- gfprintf(COM2, "%04d", cash_balance);
- move_LCD(0,1);
- break;
- case '2':
- ui_state = ACCOUNT;
- gfprintf(COM2, "%c%c%cEnter Account:", 0xFF, ESC, '@');
- move_LCD(0,1);
- break;
- default:
- break;
- }
- }
- break;
- case CASH:
- if(xQueueReceive(cash_queue, &cash_balance, 10))
- {
- gfprintf(COM2, "%04d", cash_balance);
- move_LCD(0,1);
- }
- if(xSemaphoreTake(paid, 10))
- {
- ui_state = FUEL_SELECT;
- gfprintf(COM2, "%c%c%cSelect Fuel", 0xFF, ESC, '@');
- move_LCD(0,1);
- gfprintf(COM2, "1.92/2.95/3.E10", 0xFF, ESC, '@');
- }
- break;
- case ACCOUNT:
- if(account_counter < 6)
- {
- if(xQueueReceive(keyboard_queue, &keyboard_input, 10))
- {
- wr_ch_LCD(keyboard_input);
- account_counter++;
- }
- }
- else
- {
- account_counter = 0;
- wr_ch_LCD(0xFF);
- wr_ch_LCD(0x1B);
- wr_ch_LCD('@');
- ui_state = PIN;
- gfprintf(COM2, "%c%c%cEnter PIN:", 0xFF, ESC, '@');
- move_LCD(0,1);
- }
- break;
- case PIN:
- if(pin_counter < 4)
- {
- if(xQueueReceive(keyboard_queue, &keyboard_input, 10))
- {
- wr_ch_LCD(keyboard_input);
- pin_counter++;
- }
- }
- else
- {
- pin_counter = 0;
- gfprintf(COM2, "%c%c%cSelect Fuel", 0xFF, ESC, '@');
- move_LCD(0,1);
- gfprintf(COM2, "1.92/2.95/3.E10");
- ui_state = FUEL_SELECT;
- }
- break;
- case FUEL_SELECT:
- if(xQueueReceive(keyboard_queue, &keyboard_input, 10))
- {
- switch(keyboard_input)
- {
- case '1':
- fuel_select = O92;
- ui_state = FUEL;
- gfprintf(COM2, "%c%c%cP/L:", 0xFF, ESC, '@');
- move_LCD(0,1);
- gfprintf(COM2, "L: P:", 0xFF, ESC, '@');
- break;
- case '2':
- fuel_select = O95;
- ui_state = FUEL;
- gfprintf(COM2, "%c%c%cP/L:", 0xFF, ESC, '@');
- move_LCD(0,1);
- gfprintf(COM2, "L: P:");
- break;
- case '3':
- fuel_select = E10;
- ui_state = FUEL;
- gfprintf(COM2, "%c%c%cP/L:", 0xFF, ESC, '@');
- move_LCD(0,1);
- gfprintf(COM2, "L: P:");
- break;
- default:
- break;
- }
- xSemaphoreGive(start_signal);
- }
- break;
- case FUEL:
- if(xQueueReceive(gas_queue, &fuel_amount, 10))
- {
- if(!ticks--)
- {
- move_LCD(0,1);
- gfprintf(COM2, "L:%d P:%d", fuel_amount, calculate_price(fuel_select, fuel_amount));
- ticks = pdMS_TO_TICKS(20);
- }
- }
- break;
- default:
- break;
- }
- }
- }
- /****************************** End Of Module *******************************/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement