Esempio n. 1
0
int main (void)
{
    int count = 5;

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

    navswitch_init ();
    ir_serial_init ();

    show_count (count);

    pacer_init (LOOP_RATE);

    /* Paced loop.  */
    while (1)
    {
        int ret;
        uint8_t data;

        /* Wait for next tick.  */
        pacer_wait ();

        tinygl_update ();

        navswitch_update ();

        if (navswitch_push_event_p (NAVSWITCH_WEST))
            ir_serial_transmit (1);

        if (navswitch_push_event_p (NAVSWITCH_EAST))
            ir_serial_transmit (2);

        ret = ir_serial_receive (&data);
        if (ret == IR_SERIAL_OK)
        {
            if (data == 1)
                count--;
            else if (data == 2)
                count++;
            else
                count = 0;
            show_count (count);
        }
        else if (ret < 0)
        {
            show_err (-ret);
        }
    }

    return 0;
}
Esempio n. 2
0
static void navswitch_task (__unused__ void *data)
{
    navswitch_update ();

    if (navswitch_push_event_p (NAVSWITCH_PUSH))
    {
        mmelody_play (melody, 0);            
    }
    if (navswitch_push_event_p (NAVSWITCH_NORTH))
        mmelody_play (melody, tune1);            
    if (navswitch_push_event_p (NAVSWITCH_SOUTH))
        mmelody_play (melody, tune2);            
}
Esempio n. 3
0
int main (void)
{
    snake_t snake;
    int tick = 0;

    system_init ();

    snake.dir = DIR_N;
    snake.pos.x = TINYGL_WIDTH / 2;
    snake.pos.y = TINYGL_HEIGHT - 1;

    tinygl_init (LOOP_RATE);

    navswitch_init ();

    pacer_init (LOOP_RATE);

    tinygl_draw_point (snake.pos, 1);

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

        navswitch_update ();

        tick = tick + 1;
        if (tick > LOOP_RATE / SNAKE_SPEED)
        {   
            tick = 0;
            snake = snake_move (snake);
        }

        if (navswitch_push_event_p (NAVSWITCH_WEST))
        {
            snake = snake_turn_left (snake);
        }

        if (navswitch_push_event_p (NAVSWITCH_EAST))
        {
            snake = snake_turn_right (snake);
        }

  
        tinygl_update ();
    }

    return 0;
}
Esempio n. 4
0
static void navswitch_task (__unused__ void *data)
{
    navswitch_update ();
    
    if (navswitch_push_event_p (NAVSWITCH_NORTH))
        things_monster_move (0, -1);
    if (navswitch_push_event_p (NAVSWITCH_SOUTH))
        things_monster_move (0, 1);
    if (navswitch_push_event_p (NAVSWITCH_EAST))
        things_monster_move (1, 0);
    if (navswitch_push_event_p (NAVSWITCH_WEST))
        things_monster_move (-1, 0);
    
    /* Pause/resume things running around.  */
    if (navswitch_push_event_p (NAVSWITCH_PUSH))
    {
        switch (game_state)
        {
        case GAME_WAIT:
            game_state = GAME_RUNNING;
            srand (timer_get ());
            tinygl_clear ();
            things_create ();
            duration = 0;
            led_set (LED1, 1);
            break;
            
        case GAME_RUNNING:
            game_state = GAME_PAUSED;
            led_set (LED1, 0);
            break;

        case GAME_PAUSED:
            game_state = GAME_RUNNING;
            led_set (LED1, 1);
            break;
        }
    }
    
    if (game_state == GAME_RUNNING && things_killed_p ())
    {
        char buffer[6];
        
        game_state = GAME_WAIT;
        led_set (LED1, 0);
        sprintf (buffer, "%d", duration);
        tinygl_text (buffer);
    }
}
Esempio n. 5
0
int main (void)
{
    int freq = 1;
    unsigned int count = 0;
    unsigned int period = LOOP_RATE / freq;

    system_init ();

    pacer_init (LOOP_RATE);
    led_init ();
    navswitch_init ();


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

        navswitch_update ();

        if (navswitch_push_event_p (NAVSWITCH_SOUTH))
        {
            freq -= LED_RATE_INC;
            if (freq < LED_RATE_MIN)
                freq = LED_RATE_MIN;

            period = LOOP_RATE / freq;
        }

        if (navswitch_push_event_p (NAVSWITCH_NORTH))
        {
            freq += LED_RATE_INC;
            if (freq > LED_RATE_MAX)
                freq = LED_RATE_MAX;

            period = LOOP_RATE / freq;
        }

        led_set (LED1, count < period / 2);
        count++;
        if (count >= period)
            count = 0;

    }

    return 0;
}
Esempio n. 6
0
static void navswitch_task (__unused__ void *data)
{
    navswitch_update ();
    
    if (navswitch_push_event_p (NAVSWITCH_PUSH))
    {
        if (this_state == STATE_UNKNOWN)
        {
            this_state = STATE_FIRST;
            tinygl_text ("1");
        }
    }
}
Esempio n. 7
0
int main (void)
{
    uint8_t size = 0;
    code_t codeseq[CODESEQ_LEN_MAX];
    uint8_t count = 0;

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

    navswitch_init ();
    ir_init ();

    pacer_init (LOOP_RATE);

    show_num ('W', count);

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

        tinygl_update ();

        navswitch_update ();

        if (navswitch_push_event_p (NAVSWITCH_PUSH))
        {
            transmit (codeseq, size);
            show_char ('T');
        }

        if (ir_rx_get ())
        {
            size = capture (codeseq, CODESEQ_LEN_MAX);
            show_num (size == 0 ? 'E' : 'R', size);
            count++;
//            size = capture (codeseq, 9);
//            show_char ('0' + size);
        }
    }

    return 0;
}
Esempio n. 8
0
int main (void)
{
    uint16_t navswitch_tick = 0;
    uint16_t count = 0;

    system_init ();

    navswitch_init ();

    tinygl_init (LOOP_RATE);
    tinygl_font_set (&font5x7_1);

    pacer_init (LOOP_RATE);

    tinygl_draw_char ('*', tinygl_point (0, 0));
    
    while (1)
    {
        pacer_wait ();

        tinygl_update ();

        count++;

        navswitch_tick++;
        if (navswitch_tick >= LOOP_RATE / NAVSWITCH_RATE)
        {
            navswitch_tick = 0;

            navswitch_update ();

            if (navswitch_push_event_p (NAVSWITCH_PUSH))
            {
                char c;

                c = (rand () % 26) + 'A';

                tinygl_draw_char (c, tinygl_point (0, 0));

                /* Reseed the pseudorandom number generator based on the
                   number of iterations of the paced loop.  */
                srand (count);
            }
        }
    }
    return 0;
}
Esempio n. 9
0
int main (void)
{
    uint16_t things_move_tick = 0;
    uint16_t navswitch_tick = 0;
    uint16_t monster_flash_tick = 0;
    bool running = 0;
    bool game_over = 1;
    int duration = 0;

    system_init ();
    navswitch_init ();
    led_init ();
    led_set (LED1, 0);

    tinygl_init (LOOP_RATE);
    tinygl_font_set (&font3x5_1);
    tinygl_text_mode_set (TINYGL_TEXT_MODE_SCROLL);
    tinygl_text_dir_set (TINYGL_TEXT_DIR_ROTATE);

    pacer_init (LOOP_RATE);

    tinygl_text ("GOBBLE6: PUSH TO START");

    while (1)
    {
        uint8_t col;

        /* Refresh things.  */
        for (col = 0; col < TINYGL_WIDTH; col++)
        {
            pacer_wait ();

            tinygl_update ();
        }

        /* Poll the navswitch and update monster position.  */
        navswitch_tick++;
        if (navswitch_tick >= LOOP_RATE / NAVSWITCH_RATE)
        {
            navswitch_tick = 0;

            navswitch_update ();

            if (navswitch_push_event_p (NAVSWITCH_NORTH))
                things_monster_move (0, -1);
            if (navswitch_push_event_p (NAVSWITCH_SOUTH))
                things_monster_move (0, 1);
            if (navswitch_push_event_p (NAVSWITCH_EAST))
                things_monster_move (1, 0);
            if (navswitch_push_event_p (NAVSWITCH_WEST))
                things_monster_move (-1, 0);
            
            /* Pause/resume things running around.  */
            if (navswitch_push_event_p (NAVSWITCH_PUSH))
            {
                if (! running && game_over)
                {
                    srand (timer_get ());
                    tinygl_clear ();
                    things_create ();

                    duration = 0;
                    game_over = 0;
                }

                running = !running;
                led_set (LED1, running);
            }

            if (running && things_killed_p ())
            {
                char buffer[6];
                
                running = 0;
                game_over = 1;
                led_set (LED1, 0);
                sprintf (buffer, "%d", duration);
                tinygl_text (buffer);
            }
        }

        /* Move the things.  */
        things_move_tick++;
        if (things_move_tick >= LOOP_RATE / MOVE_RATE)
        {
            things_move_tick = 0;
            
            if (running)
            {
                duration++;
                things_move ();
            }
        }

        /* Flash the monster.  */
        monster_flash_tick++;
        if (monster_flash_tick >= LOOP_RATE / MONSTER_FLASH_RATE / 2)
        {
            monster_flash_tick = 0;
            if (running)
                things_monster_toggle ();
        }
    }
    return 0;
}
Esempio n. 10
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;
}
Esempio n. 11
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();
}