Exemple #1
0
void comm_attempt_send(void) {
    if (is_sending && ir_uart_write_ready_p()) {
        ir_uart_putc(sending_packet[send_index]);
        if (ir_uart_read_ready_p()) {
            ir_uart_getc();  // Workaround for UCFK bug
        }
        send_index += 1;
        if (send_index > 3 || sending_packet[send_index] == 0) {
            is_sending = FALSE;
        }
    }
}
Exemple #2
0
static void ir_uart_tx_task (__unused__ void *data)
{
    /* Send our state.  */
    ir_uart_putc ('A' + this_state);
}
Exemple #3
0
int main (void)
{
    int count;
    uint8_t data = 'M';

    system_init ();
    tinygl_init (LOOP_RATE);
    tinygl_font_set (&font3x5_1);
    tinygl_text_speed_set (MESSAGE_RATE);
    tinygl_text_mode_set (TINYGL_TEXT_MODE_STEP);
    tinygl_text_dir_set (TINYGL_TEXT_DIR_ROTATE);

    navswitch_init ();
    ir_uart_init ();

    pacer_init (LOOP_RATE);

    show_byte ('M');

    count = 0;

    /* Paced loop.  */
    while (1)
    {
        /* Wait for next tick.  */
        pacer_wait ();

        tinygl_update ();

        if (ir_uart_read_ready_p ())
        {
            uint8_t data;

            data = ir_uart_getc ();

            /* Note, if messages come in too fast, say due to IR
               inteference from fluorescent lights, then the display
               will not keep up and will appear to freeze.  */
            show_byte (data);
        }

        count++;
        if (count > LOOP_RATE / SWITCH_POLL_RATE)
        {
            count = 0;

            navswitch_update ();

            if (navswitch_push_event_p (NAVSWITCH_WEST))
            {
                ir_uart_putc (--data);
                /* Gobble echoed character.  */
                ir_uart_getc ();
            }

            if (navswitch_push_event_p (NAVSWITCH_EAST))
            {
                ir_uart_putc (++data);
                /* Gobble echoed character.  */
                ir_uart_getc ();
            }
        }
    }

    return 0;
}
Exemple #4
0
void painting(void){
  //receive from other players
  if (ir_uart_read_ready_p ()){
      paintP2 = 1;
      //get their position from the signal
      player2_pen.pos.x = ir_uart_getc();
      player2_pen.pos.y = ir_uart_getc();

      /* update the information about other player territory. */
      setTerritoryP2(player2_pen.pos.y, player2_pen.pos.x);
      tinygl_update ();
}

if (navswitch_push_event_p (NAVSWITCH_NORTH) && player1_pen.pos.y > 0)
{
    player1_pen.pos.y--;
    paintP1= 1;

     ir_uart_putc(player1_pen.pos.x);
     ir_uart_putc(player1_pen.pos.y);

     //check if the player lands on their own territory
     if(!isTerritoryTakenP1(player1_pen.pos.y, player1_pen.pos.x)){
       //check if the player lands on other player territory
        if(isTerritoryTakenP2(player1_pen.pos.y, player1_pen.pos.x)){
           specialScore();
        }
        //the player lands on territory that hasn't been painted
        else{
          incrementScore();
        }
     }
     //update information about the player territory
         setTerritoryP1(player1_pen.pos.y, player1_pen.pos.x);

}

if (navswitch_push_event_p (NAVSWITCH_SOUTH) && player1_pen.pos.y < TINYGL_HEIGHT - 1)
{
    player1_pen.pos.y++;
    paintP1= 1;

       ir_uart_putc(player1_pen.pos.x);
       ir_uart_putc(player1_pen.pos.y);

       //check if the player lands on their own territory
       if(!isTerritoryTakenP1(player1_pen.pos.y, player1_pen.pos.x)){
          //check if the player lands on other player territory
          if(isTerritoryTakenP2(player1_pen.pos.y, player1_pen.pos.x)){
             specialScore();
          }
          //the player lands on territory that hasn't been painted
          else{
            incrementScore();
          }
       }
       //update information about the player territory
       setTerritoryP1(player1_pen.pos.y, player1_pen.pos.x);
}
if (navswitch_push_event_p (NAVSWITCH_EAST) && player1_pen.pos.x < TINYGL_WIDTH - 1)
{
    player1_pen.pos.x++;
    paintP1= 1;

     ir_uart_putc(player1_pen.pos.x);
     ir_uart_putc(player1_pen.pos.y);

     //check if the player lands on their own territory
     if(!isTerritoryTakenP1(player1_pen.pos.y, player1_pen.pos.x)){
        //check if the player lands on other player territory
        if(isTerritoryTakenP2(player1_pen.pos.y, player1_pen.pos.x)){
           specialScore();
        }
        //the player lands on territory that hasn't been painted
        else{
          incrementScore();
        }
     }
   //update information about the player territory
   setTerritoryP1(player1_pen.pos.y, player1_pen.pos.x);

}

if(navswitch_push_event_p(NAVSWITCH_WEST) && player1_pen.pos.x > 0)
{
  player1_pen.pos.x--;
  paintP1= 1;

  ir_uart_putc(player1_pen.pos.x);
  ir_uart_putc(player1_pen.pos.y);

  //check if the player lands on their own territory
  if(!isTerritoryTakenP1(player1_pen.pos.y, player1_pen.pos.x)){
     //check if the player lands on other player territory
     if(isTerritoryTakenP2(player1_pen.pos.y, player1_pen.pos.x)){
        specialScore();
     }
     //the player lands on territory that hasn't been painted
     else{
       incrementScore();
     }
  }
  //update information about the player territory
   setTerritoryP1(player1_pen.pos.y, player1_pen.pos.x);
}


    if (paintP1)
        tinygl_draw_point (player1_pen.pos, player1_pen.state);
        tinygl_update();


   if (paintP2)
        tinygl_draw_point (player2_pen.pos, player2_pen.state);
        tinygl_update();
}