Advertisement
Guest User

260

a guest
Oct 15th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. #include <string.h>
  2. #include "system.h"
  3. #include "tinygl.h"
  4. #include "task.h"
  5. #include "navswitch.h"
  6. #include "eeprom.h"
  7. #include "uint8toa.h"
  8. #include "../fonts/font3x5_1.h"
  9. #include "pacer.h"
  10. #include <avr/io.h>
  11. #include "tweeter.h"
  12. #include "mmelody.h"
  13. #include "button.h"
  14. #include "pio.h"
  15. #include <stdbool.h>
  16. #include "ir_serial.h"
  17. #include "ir.h"
  18.  
  19. #define PACER_RATE 500
  20. #define MESSAGE_RATE 20
  21.  
  22. static _Bool ready;
  23. static _Bool handshake;
  24.  
  25. static void handshake_init (void)
  26. {
  27. handshake = false;
  28. }
  29.  
  30. static void ready_screen_init(void)
  31. {
  32. ready = false;
  33. }
  34.  
  35. static void ready_screen_task(void)
  36. {
  37. ready = true;
  38. }
  39.  
  40. static void tinygl_task_init(void)
  41. {
  42. tinygl_font_set(&font3x5_1);
  43. tinygl_text_speed_set(MESSAGE_RATE);
  44. tinygl_text_mode_set(TINYGL_TEXT_MODE_SCROLL);
  45. tinygl_text_dir_set (TINYGL_TEXT_DIR_ROTATE);
  46. }
  47.  
  48. static void show_err (uint8_t err)
  49. {
  50. char buffer[3];
  51.  
  52. buffer[0] = 'E';
  53. buffer[1] = err + '0';
  54. buffer[2] = 0;
  55. tinygl_text (buffer);
  56. }
  57.  
  58. static _Bool ready_loop (_Bool ready, _Bool handshake)
  59. {
  60. int ret;
  61. uint8_t data;
  62.  
  63. if (ready && !handshake) {
  64. tinygl_text("READY?");
  65. ir_serial_ret_t ret;
  66. ir_serial_transmit (1);
  67. ret = ir_serial_receive (&data);
  68. if (ret == IR_SERIAL_OK)
  69. {
  70. if (data == 1) {
  71. handshake = true;
  72. ready = !ready;
  73. }
  74. } else if (ret < 0) {
  75. show_err (-ret);
  76. }
  77. }
  78. return handshake;
  79. }
  80.  
  81. int main (void)
  82. {
  83. ready_screen_init();
  84. button_init();
  85. system_init();
  86. handshake_init();
  87. ir_serial_init();
  88. pacer_init (PACER_RATE);
  89. tinygl_init(PACER_RATE);
  90. tinygl_task_init();
  91. //Intro screen
  92. tinygl_text("SUPER DODGEBALL 9000");
  93.  
  94. while(1)
  95. {
  96. pacer_wait();
  97. tinygl_update();
  98. button_update();
  99. //Break out of Intro screen and into the Ready loop
  100. if (button_push_event_p(BUTTON1) && !ready && !handshake) {
  101. ready_screen_task();
  102. ready_loop(ready, handshake);
  103. }
  104. //Check if both players are ready
  105. if (ready_loop(ready, handshake)) {
  106. tinygl_text("A1");
  107. }
  108. }
  109. return 0;
  110.  
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement