SHARE
TWEET

Untitled

a guest Oct 15th, 2019 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. void display_character (char character)
  59. {
  60.     char buffer[2];
  61.  
  62.     buffer[0] = character;
  63.     buffer[1] = '\0';
  64.     tinygl_text (buffer);
  65. }
  66.  
  67. static void ready_loop (void)
  68. {
  69.     while (1) {
  70.         uint8_t data;
  71.         pacer_wait();
  72.         tinygl_update();
  73.         ir_serial_ret_t ret;
  74.         ir_serial_transmit (1);
  75.         ret = ir_serial_receive (&data);
  76.         if (ret == IR_SERIAL_OK) {
  77.             if (data == 1) {
  78.                 ready = !ready;
  79.                 handshake = true;
  80.             }
  81.         } else if (ret < 0) {
  82.             show_err (-ret);
  83.         }
  84.     }
  85. }
  86.  
  87. int main (void)
  88. {
  89.     ready_screen_init();
  90.     button_init();
  91.     system_init();
  92.     handshake_init();
  93.     ir_serial_init();
  94.     pacer_init (PACER_RATE);
  95.     tinygl_init(PACER_RATE);
  96.     tinygl_task_init();
  97.     //Intro screen
  98.     tinygl_text("SUPER DODGEBALL 9000");
  99.  
  100.     while(1)
  101.     {
  102.         pacer_wait();
  103.         tinygl_update();
  104.         button_update();
  105.         //Break out of Intro screen and into the Ready loop
  106.         if (button_push_event_p(BUTTON1) && !ready && !handshake) {
  107.             ready_screen_task();
  108.             tinygl_text("READY?");
  109.             ready_loop();
  110.         } else if (handshake && !ready) {
  111.             display_character('A');
  112.         }
  113.     }
  114.     return 0;
  115.  
  116. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top