Advertisement
Guest User

Untitled

a guest
May 28th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.80 KB | None | 0 0
  1. /*****************************************************************************
  2. * University of Southern Denmark
  3. * Embedded C Programming (ECP)
  4. *
  5. * MODULENAME.: .c
  6. *
  7. * PROJECT....: ECP
  8. *
  9. * DESCRIPTION: See module specification file (.h-file).
  10. *
  11. * Change Log:
  12. ******************************************************************************
  13. * Date Id Change
  14. * YYMMDD
  15. * --------------------
  16. * 180507 KA Module created.
  17. *
  18. *****************************************************************************/
  19.  
  20. /***************************** Include files *******************************/
  21. #include <stdint.h>
  22. #include <ui.h>
  23. #include "tm4c123gh6pm.h"
  24. #include "FreeRTOS.h"
  25. #include "Task.h"
  26. #include "queue.h"
  27. #include "semphr.h"
  28. #include "emp_type.h"
  29. #include "lcd.h"
  30. #include "string.h"
  31. #include "device.h"
  32.  
  33.  
  34. /***************************** Defines *******************************/
  35. #define O92 0
  36. #define O95 1
  37. #define E10 2
  38.  
  39. /***************************** Constants *******************************/
  40. extern QueueHandle_t keyboard_queue;
  41. extern QueueHandle_t cash_queue;
  42. extern QueueHandle_t gas_queue;
  43. extern SemaphoreHandle_t paid;
  44. extern SemaphoreHandle_t start_signal;
  45. extern SemaphoreHandle_t digi_signal;
  46. /***************************** Variables *******************************/
  47.  
  48. /***************************** Functions *******************************/
  49.  
  50. INT16U calculate_price(INT16U fuel_type, INT16U fuel_count)
  51. {
  52. INT16U price = 0;
  53.  
  54. switch(fuel_type)
  55. {
  56. case 1:
  57. price = fuel_count*1;
  58. break;
  59. case 2:
  60. price = fuel_count*2;
  61. break;
  62. case 3:
  63. price = fuel_count*3;
  64.  
  65. break;
  66. }
  67. return price;
  68. }
  69.  
  70. void ui_init(void)
  71. /*****************************************************************************
  72. * Input : -
  73. * Output : -
  74. * Function :
  75. *****************************************************************************/
  76. {
  77. INT8S dummy;
  78.  
  79. // Enable the GPIO port that is used for the on-board LED.
  80. SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOD;
  81.  
  82. // Do a dummy read to insert a few cycles after enabling the peripheral.
  83. dummy = SYSCTL_RCGC2_R;
  84. }
  85.  
  86.  
  87. void ui_task(void *pvParameters)
  88. {
  89. INT8U ui_state = WELCOME;
  90. INT8U keyboard_input;
  91. INT8U pin_counter = 0;
  92. INT8U account_counter = 0;
  93. INT16U fuel_select;
  94. INT16U cash_balance = 0;
  95. INT16U fuel_amount = 0;
  96. INT16U ticks = pdMS_TO_TICKS(20);
  97.  
  98. while(1)
  99. {
  100. switch(ui_state)
  101. {
  102. case WELCOME:
  103. gfprintf(COM2,"%c%cWelcome!",ESC,'@');
  104. move_LCD(0, 1);
  105. gfprintf(COM2, "1.Cash 2.Account");
  106. if(xQueueReceive(keyboard_queue, &keyboard_input, 100))
  107. {
  108. switch(keyboard_input)
  109. {
  110. case '1':
  111. xSemaphoreGive(digi_signal);
  112. ui_state = CASH;
  113. gfprintf(COM2, "%c%c%cInsert Cash:", 0xFF, ESC, '@');
  114. move_LCD(0,1);
  115. gfprintf(COM2, "%04d", cash_balance);
  116. move_LCD(0,1);
  117. break;
  118. case '2':
  119. ui_state = ACCOUNT;
  120. gfprintf(COM2, "%c%c%cEnter Account:", 0xFF, ESC, '@');
  121. move_LCD(0,1);
  122. break;
  123. default:
  124. break;
  125. }
  126. }
  127. break;
  128. case CASH:
  129. if(xQueueReceive(cash_queue, &cash_balance, 10))
  130. {
  131. gfprintf(COM2, "%04d", cash_balance);
  132. move_LCD(0,1);
  133. }
  134.  
  135. if(xSemaphoreTake(paid, 10))
  136. {
  137.  
  138. ui_state = FUEL_SELECT;
  139. gfprintf(COM2, "%c%c%cSelect Fuel", 0xFF, ESC, '@');
  140. move_LCD(0,1);
  141. gfprintf(COM2, "1.92/2.95/3.E10", 0xFF, ESC, '@');
  142. }
  143. break;
  144. case ACCOUNT:
  145. if(account_counter < 6)
  146. {
  147. if(xQueueReceive(keyboard_queue, &keyboard_input, 10))
  148. {
  149. wr_ch_LCD(keyboard_input);
  150. account_counter++;
  151. }
  152. }
  153. else
  154. {
  155. account_counter = 0;
  156. wr_ch_LCD(0xFF);
  157. wr_ch_LCD(0x1B);
  158. wr_ch_LCD('@');
  159. ui_state = PIN;
  160. gfprintf(COM2, "%c%c%cEnter PIN:", 0xFF, ESC, '@');
  161. move_LCD(0,1);
  162. }
  163. break;
  164. case PIN:
  165. if(pin_counter < 4)
  166. {
  167. if(xQueueReceive(keyboard_queue, &keyboard_input, 10))
  168. {
  169. wr_ch_LCD(keyboard_input);
  170. pin_counter++;
  171. }
  172. }
  173. else
  174. {
  175. pin_counter = 0;
  176. gfprintf(COM2, "%c%c%cSelect Fuel", 0xFF, ESC, '@');
  177. move_LCD(0,1);
  178. gfprintf(COM2, "1.92/2.95/3.E10");
  179.  
  180. ui_state = FUEL_SELECT;
  181. }
  182. break;
  183. case FUEL_SELECT:
  184. if(xQueueReceive(keyboard_queue, &keyboard_input, 10))
  185. {
  186. switch(keyboard_input)
  187. {
  188. case '1':
  189. fuel_select = O92;
  190. ui_state = FUEL;
  191. gfprintf(COM2, "%c%c%cP/L:", 0xFF, ESC, '@');
  192. move_LCD(0,1);
  193. gfprintf(COM2, "L: P:", 0xFF, ESC, '@');
  194. break;
  195. case '2':
  196. fuel_select = O95;
  197. ui_state = FUEL;
  198. gfprintf(COM2, "%c%c%cP/L:", 0xFF, ESC, '@');
  199. move_LCD(0,1);
  200. gfprintf(COM2, "L: P:");
  201. break;
  202. case '3':
  203. fuel_select = E10;
  204. ui_state = FUEL;
  205. gfprintf(COM2, "%c%c%cP/L:", 0xFF, ESC, '@');
  206. move_LCD(0,1);
  207. gfprintf(COM2, "L: P:");
  208. break;
  209. default:
  210. break;
  211. }
  212. xSemaphoreGive(start_signal);
  213. }
  214. break;
  215. case FUEL:
  216. if(xQueueReceive(gas_queue, &fuel_amount, 10))
  217. {
  218. if(!ticks--)
  219. {
  220. move_LCD(0,1);
  221. gfprintf(COM2, "L:%d P:%d", fuel_amount, calculate_price(fuel_select, fuel_amount));
  222. ticks = pdMS_TO_TICKS(20);
  223. }
  224. }
  225. break;
  226. default:
  227. break;
  228. }
  229. }
  230. }
  231.  
  232.  
  233. /****************************** End Of Module *******************************/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement