RoomElement hitMonster(RoomElement element)
{
  //erase the old monster image (using blank map tile)
  TV.bitmap(element.x, element.y, map_bitmap);
  TV.bitmap(element.x, element.y + 8, map_bitmap);

  element.state = STATE_HIDDEN;

  //add heart element
  addRoomElement(ITEM_HEART, element.x, element.y, STATE_VISIBLE, COUNTER_START);

  return element;
}
void screens::updateDiversity(char active_receiver, uint8_t rssiA, uint8_t rssiB){
    #define RSSI_BAR_SIZE 100
    uint8_t rssi_scaled=map(rssiA, 1, 100, 1, RSSI_BAR_SIZE);
    // clear last bar
    TV.draw_rect(25+rssi_scaled, 6+4*MENU_Y_SIZE, RSSI_BAR_SIZE-rssi_scaled, 8 , BLACK, BLACK);
    //  draw new bar
    TV.draw_rect(25, 6+4*MENU_Y_SIZE, rssi_scaled, 8 , WHITE, (active_receiver==useReceiverA ? WHITE:BLACK));

    // read rssi B
    rssi_scaled=map(rssiB, 1, 100, 1, RSSI_BAR_SIZE);
    // clear last bar
    TV.draw_rect(25+rssi_scaled, 6+5*MENU_Y_SIZE, RSSI_BAR_SIZE-rssi_scaled, 8 , BLACK, BLACK);
    //  draw new bar
    TV.draw_rect(25, 6+5*MENU_Y_SIZE, rssi_scaled, 8 , WHITE, (active_receiver==useReceiverB ? WHITE:BLACK));

}
Exemple #3
0
void drawLogo(char start)
{
  //draw hearts
  char x_offset = 48;
  for (char i=start; i < (start+4); i++)
  {
      //draw logo element
      TV.bitmap(x_offset, 16, logo_bitmap + (SIZEOF_LOGO_RECORD * i));
   
    x_offset += 8;
  }   
}
void screens::diversity(uint8_t diversity_mode) {
    reset();
    drawTitleBox("DIVERSITY");
    TV.printPGM(10, 5+1*MENU_Y_SIZE, PSTR("Auto"));
    TV.printPGM(10, 5+2*MENU_Y_SIZE, PSTR("Receiver A"));
    TV.printPGM(10, 5+3*MENU_Y_SIZE, PSTR("Receiver B"));
    // RSSI Strength
    TV.draw_line(0,3+4*MENU_Y_SIZE, TV_X_MAX, 3+4*MENU_Y_SIZE, WHITE);
    TV.printPGM(10, 6+4*MENU_Y_SIZE, PSTR("A:"));
    TV.draw_line(0,3+5*MENU_Y_SIZE, TV_X_MAX, 3+5*MENU_Y_SIZE, WHITE);
    TV.printPGM(10, 6+5*MENU_Y_SIZE, PSTR("B:"));

    TV.draw_rect(0,3+(diversity_mode+1)*MENU_Y_SIZE,127,12,  WHITE, INVERT);
}
void screens::mainMenu(uint8_t menu_id) {
    reset(); // start from fresh screen.
    drawTitleBox("MODE SELECTION");

    TV.printPGM(10, 5+1*MENU_Y_SIZE, PSTR("Auto Search"));
    TV.printPGM(10, 5+2*MENU_Y_SIZE, PSTR("Band Scanner"));
    TV.printPGM(10, 5+3*MENU_Y_SIZE, PSTR("Manual Mode"));
#ifdef USE_DIVERSITY
    TV.printPGM(10, 5+4*MENU_Y_SIZE, PSTR("Diversity"));
#endif
    TV.printPGM(10, 5+5*MENU_Y_SIZE, PSTR("Save Setup"));
    // selection by inverted box

    TV.draw_rect(0,3+(menu_id+1)*MENU_Y_SIZE,127,12,  WHITE, INVERT);
}
void display_update(unsigned int add_to_score)
{
   score += add_to_score; 
   TV.print(0, 88, score);
}
void screens::seekMode(uint8_t state) {
    last_channel = -1;
    reset(); // start from fresh screen.
    if (state == STATE_MANUAL)
    {
        drawTitleBox("MANUAL MODE");
    }
    else if(state == STATE_SEEK)
    {
        drawTitleBox("AUTO SEEK MODE");
    }
    TV.draw_line(0,1*TV_Y_GRID,TV_X_MAX,1*TV_Y_GRID,WHITE);
    TV.printPGM(5,TV_Y_OFFSET+1*TV_Y_GRID,  PSTR("BAND: "));
    TV.draw_line(0,2*TV_Y_GRID,TV_X_MAX,2*TV_Y_GRID,WHITE);
    TV.printPGM(5 ,TV_Y_OFFSET-1+2*TV_Y_GRID,  PSTR("1 2 3 4 5 6 7 8"));
    TV.draw_line(0,3*TV_Y_GRID,TV_X_MAX,3*TV_Y_GRID,WHITE);
    TV.printPGM(5,TV_Y_OFFSET+3*TV_Y_GRID,  PSTR("FREQ:     GHz"));
    TV.draw_line(0,4*TV_Y_GRID,TV_X_MAX,4*TV_Y_GRID,WHITE);
    TV.select_font(font4x6);
    TV.printPGM(5,TV_Y_OFFSET+4*TV_Y_GRID,  PSTR("RSSI:"));
    TV.draw_line(0,5*TV_Y_GRID-4,TV_X_MAX,5*TV_Y_GRID-4,WHITE);
    // frame for tune graph
    TV.draw_rect(0,TV_ROWS - TV_SCANNER_OFFSET,TV_X_MAX,13,  WHITE); // lower frame
    TV.print(2, (TV_ROWS - TV_SCANNER_OFFSET + 2), "5645");
    TV.print(57, (TV_ROWS - TV_SCANNER_OFFSET + 2), "5800");
    TV.print(111, (TV_ROWS - TV_SCANNER_OFFSET + 2), "5945");

}
void screens::drawTitleBox(const char *title) {
    TV.draw_rect(0,0,127,95,  WHITE);
    TV.print(((127-strlen(title)*8)/2), 3,  title);
    TV.draw_rect(0,0,127,14,  WHITE,INVERT);
}
void screens::bandScanMode(uint8_t state) {
    reset(); // start from fresh screen.
    best_rssi = 0;
    if(state==STATE_SCAN)
    {
        drawTitleBox("BAND SCANNER");
    }
    else
    {
        drawTitleBox("RSSI SETUP");
    }
    TV.select_font(font8x8);
    if(state==STATE_SCAN)
    {
        TV.select_font(font4x6);
        TV.draw_line(50,1*TV_Y_GRID,50, 1*TV_Y_GRID+9,WHITE);
        TV.print(2, SCANNER_LIST_Y_POS, "BEST:");
    }
    else
    {
        TV.select_font(font4x6);
        TV.print(10, SCANNER_LIST_Y_POS, "RSSI Min:     RSSI Max:   ");
    }
    TV.draw_rect(0,1*TV_Y_GRID,TV_X_MAX,9,  WHITE); // list frame
    TV.draw_rect(0,TV_ROWS - TV_SCANNER_OFFSET,TV_X_MAX,13,  WHITE); // lower frame
    TV.select_font(font4x6);
    TV.print(2, (TV_ROWS - TV_SCANNER_OFFSET + 2), "5645");
    TV.print(57, (TV_ROWS - TV_SCANNER_OFFSET + 2), "5800");
    TV.print(111, (TV_ROWS - TV_SCANNER_OFFSET + 2), "5945");
}
char screens::begin() {
    return TV.begin(TV_FORMAT, TV_COLS, TV_ROWS);
}
void screens::updateSave(const char * msg) {
    TV.select_font(font4x6);
    TV.print(((127-strlen(msg)*4)/2), 14+5*MENU_Y_SIZE, msg);
}
void screens::save(uint8_t mode, uint8_t channelIndex, uint16_t channelFrequency) {
    reset();
    drawTitleBox("SAVE SETTINGS");
    TV.printPGM(10, 5+1*MENU_Y_SIZE, PSTR("Mode:"));
    switch (mode)
    {
        case STATE_SCAN: // Band Scanner
            TV.printPGM(50,5+1*MENU_Y_SIZE,  PSTR("Scanner"));
        break;
        case STATE_MANUAL: // manual mode
            TV.printPGM(50,5+1*MENU_Y_SIZE,  PSTR("Manual"));
        break;
        case STATE_SEEK: // seek mode
            TV.printPGM(50,5+1*MENU_Y_SIZE,  PSTR("Search"));
        break;
    }
    TV.printPGM(10, 5+2*MENU_Y_SIZE, PSTR("Band:"));
    // print band
    if(channelIndex > 31)
    {
        TV.printPGM(50,5+2*MENU_Y_SIZE,  PSTR("C/Race   "));
    }
    else if(channelIndex > 23)
    {
        TV.printPGM(50,5+2*MENU_Y_SIZE,  PSTR("F/Airwave"));
    }
    else if (channelIndex > 15)
    {
        TV.printPGM(50,5+2*MENU_Y_SIZE,  PSTR("E        "));
    }
    else if (channelIndex > 7)
    {
        TV.printPGM(50,5+2*MENU_Y_SIZE,  PSTR("B        "));
    }
    else
    {
        TV.printPGM(50,5+2*MENU_Y_SIZE,  PSTR("A        "));
    }
    TV.printPGM(10, 5+3*MENU_Y_SIZE, PSTR("Chan:"));
    uint8_t active_channel = channelIndex%CHANNEL_BAND_SIZE+1; // get channel inside band
    TV.print(50,5+3*MENU_Y_SIZE,active_channel,DEC);
    TV.printPGM(10, 5+4*MENU_Y_SIZE, PSTR("FREQ:     GHz"));
    TV.print(50,5+4*MENU_Y_SIZE, channelFrequency);
    TV.printPGM(10, 5+5*MENU_Y_SIZE, PSTR("--- SAVED ---"));
}
void screens::updateBandScanMode(bool in_setup, uint8_t channel, uint8_t rssi, uint8_t channelName, uint16_t channelFrequency, uint16_t rssi_setup_min_a, uint16_t rssi_setup_max_a) {
    // force tune on new scan start to get right RSSI value
    static uint8_t writePos=SCANNER_LIST_X_POS;
    // channel marker
    if(channel != last_channel) // only updated on changes
    {
        // clear last square
        TV.draw_rect(1, (TV_ROWS - TV_SCANNER_OFFSET + 8),125,SCANNER_MARKER_SIZE,  BLACK, BLACK);
        // draw next
        TV.draw_rect((channel * 3)+5, (TV_ROWS - TV_SCANNER_OFFSET + 8),SCANNER_MARKER_SIZE,SCANNER_MARKER_SIZE,  WHITE, WHITE);
    }
    // print bar for spectrum

    uint8_t rssi_scaled=map(rssi, 1, 100, 5, SCANNER_BAR_SIZE);
    // clear last bar
    TV.draw_rect((channel * 3)+4, (TV_ROWS - TV_SCANNER_OFFSET - SCANNER_BAR_SIZE)-5, 2, SCANNER_BAR_SIZE+5 , BLACK, BLACK);
    //  draw new bar
    TV.draw_rect((channel * 3)+4, (TV_ROWS - TV_SCANNER_OFFSET - rssi_scaled), 2, rssi_scaled , WHITE, WHITE);
    // print channelname

    if(!in_setup) {
        if (rssi > RSSI_SEEK_TRESHOLD) {
            if(best_rssi < rssi) {
                best_rssi = rssi;
                TV.print(22, SCANNER_LIST_Y_POS, channelName, HEX);
                TV.print(32, SCANNER_LIST_Y_POS, channelFrequency);
            }
            else {
                if(writePos+10>TV_COLS-2)
                { // keep writing on the screen
                    writePos=SCANNER_LIST_X_POS;
                }
                TV.draw_rect(writePos, SCANNER_LIST_Y_POS, 8, 6,  BLACK, BLACK);
                TV.print(writePos, SCANNER_LIST_Y_POS, channelName, HEX);
                writePos += 10;
            }
            TV.draw_rect((channel * 3) - 5, (TV_ROWS - TV_SCANNER_OFFSET - rssi_scaled) - 5, 8, 7,  BLACK, BLACK);
            TV.print((channel * 3) - 4, (TV_ROWS - TV_SCANNER_OFFSET - rssi_scaled) - 5, channelName, HEX);
        }
    }
    else {
            TV.print(50, SCANNER_LIST_Y_POS, "   ");
            TV.print(50, SCANNER_LIST_Y_POS, rssi_setup_min_a , DEC);

            TV.print(110, SCANNER_LIST_Y_POS, "   ");
            TV.print(110, SCANNER_LIST_Y_POS, rssi_setup_max_a , DEC);
    }

    last_channel = channel;
}
RoomElement moveMonster(RoomElement element)
{
  //draw new monster bitmap
  if (element.state > STATE_HIDDEN)
  {
    //erase the old monster image (using blank map tile)
    TV.bitmap(element.x, element.y, map_bitmap);
    TV.bitmap(element.x, element.y + 8, map_bitmap);

    element.step++;
    if (element.step > 2) element.step = 1;

    switch (element.state)
    {
       case STATE_VISIBLE:
           element.state = changeMonsterDirection();
           break;

       case STATE_MOVE_UP:
           element.state = STATE_VISIBLE;
           if (element.y > 4)
           {
             if (checkMapRoomMove(element.x, element.y - 4) == 0)
             {
                if (checkMapRoomMove(element.x + 4, element.y - 4) == 0)
                {
                  element.y -= STEP_LENGTH;
                   element.state = STATE_MOVE_UP;
                }
             }
           }
           break;

       case STATE_MOVE_DOWN:
           element.state = STATE_VISIBLE;
           if (element.y < 48)
           {
             if (checkMapRoomMove(element.x, element.y + 16) == 0)
             {
                if (checkMapRoomMove(element.x + 4, element.y + 16) == 0)
                {
                  element.y += STEP_LENGTH;
                  element.state = STATE_MOVE_DOWN;
                }
             }
           }
           break;

       case STATE_MOVE_LEFT:
           element.state = STATE_VISIBLE;
           if (element.x > 4)
           {
             if (checkMapRoomMove(element.x - 4, element.y) == 0)
             {
                if (checkMapRoomMove(element.x - 4, element.y + 12) == 0)
                {
                    element.x -= STEP_LENGTH;
                    element.state = STATE_MOVE_LEFT;
                }
             }
           }
           break;

       case STATE_MOVE_RIGHT:
           element.state = STATE_VISIBLE;
           if (element.x < 80)
           {
             if (checkMapRoomMove(element.x + 12, element.y) == 0)
             {
                if (checkMapRoomMove(element.x + 12, element.y + 12) == 0)
                {
                  element.x += STEP_LENGTH;
                  element.state = STATE_MOVE_RIGHT;
                }
             }
           }
           break;
    }

    overlaybitmap(element.x, element.y, monster_bitmap + ( element.type * SIZEOF_MONSTER_RECORD));
    overlaybitmap(element.x, element.y+8, monster_bitmap + ((element.type + element.step) * SIZEOF_MONSTER_RECORD));

    //decrement counter, if active
    if (element.counter > 0) element.counter--;
  }
  return element;
}
void screens::reset() {
    TV.clear_screen();
    TV.select_font(font8x8);
}
void moveElf(unsigned char facing)
{
  //erase the old elf image (using blank map tile)
  TV.bitmap(elf.x, elf.y, map_bitmap);
  TV.bitmap(elf.x, elf.y + 8, map_bitmap);

  //if it is a new facing, then reset the step
  if (facing != elf.facing)
  {
     elf.step = 1;
  } else {
     elf.step++;
     if (elf.step > 2) elf.step = 1;
  }

  elf.facing = facing;

  switch (facing)
  {
     case FACING_DOWN:
         if (elf.y < 48)
         {
             if (checkMapRoomMove(elf.x, elf.y + 16) == 0)
                 if (checkMapRoomMove(elf.x+4, elf.y + 16) == 0) elf.y += STEP_LENGTH;
         } else {
             scrollMap(SCROLL_DOWN);
             elf.x = 36;
             elf.y = 8;
             elf.facing = FACING_DOWN;
         }
         break;

     case FACING_UP:
         if (elf.y > 4)
         {
             if (checkMapRoomMove(elf.x, elf.y - 4) == 0)
                 if (checkMapRoomMove(elf.x + 4, elf.y - 4) == 0) elf.y -= STEP_LENGTH;
         } else {
             scrollMap(SCROLL_UP);
             elf.x = 36;
             elf.y = 32;
             elf.facing = FACING_UP;
         }
         break;

     case FACING_LEFT:
         if (elf.x > 4)
         {
             if (checkMapRoomMove(elf.x - 4, elf.y) == 0)
                 if (checkMapRoomMove(elf.x - 4, elf.y + 12) == 0) elf.x -= STEP_LENGTH;
         } else {
             scrollMap(SCROLL_LEFT);
             elf.x = 64;
             elf.y = 24;
             elf.facing = FACING_LEFT;
         }
         break;

     case FACING_RIGHT:
         if (elf.x < 80)
         {
             if (checkMapRoomMove(elf.x + 12, elf.y) == 0)
                 if (checkMapRoomMove(elf.x + 12, elf.y + 12) == 0) elf.x += STEP_LENGTH;
         } else {
             scrollMap(SCROLL_RIGHT);
             elf.x = 16;
             elf.y = 24;
             elf.facing = FACING_RIGHT;
         }
         break;
  }

  //draw new elf bitmap
  overlaybitmap(elf.x, elf.y, elf_bitmap + ( elf.facing * SIZEOF_ELF_RECORD));
  overlaybitmap(elf.x, elf.y+8, elf_bitmap + ((elf.facing + elf.step) * SIZEOF_ELF_RECORD));
}
void screens::updateSeekMode(uint8_t state, uint8_t channelIndex, uint8_t channel, uint8_t rssi, uint16_t channelFrequency, bool locked) {
    // display refresh handler
    TV.select_font(font8x8);
    if(channelIndex != last_channel) // only updated on changes
    {
        // show current used channel of bank
        if(channelIndex > 31)
        {
            TV.printPGM(50,TV_Y_OFFSET+1*TV_Y_GRID,  PSTR("C/Race   "));
        }
        else if(channelIndex > 23)
        {
            TV.printPGM(50,TV_Y_OFFSET+1*TV_Y_GRID,  PSTR("F/Airwave"));
        }
        else if (channelIndex > 15)
        {
            TV.printPGM(50,TV_Y_OFFSET+1*TV_Y_GRID,  PSTR("E        "));
        }
        else if (channelIndex > 7)
        {
            TV.printPGM(50,TV_Y_OFFSET+1*TV_Y_GRID,  PSTR("B        "));
        }
        else
        {
            TV.printPGM(50,TV_Y_OFFSET+1*TV_Y_GRID,  PSTR("A        "));
        }
        // show channel inside band
        uint8_t active_channel = channelIndex%CHANNEL_BAND_SIZE; // get channel inside band

        TV.draw_rect(1 ,TV_Y_OFFSET-2+2*TV_Y_GRID,125,12,  BLACK, BLACK); // mark current channel
        TV.printPGM(5 ,TV_Y_OFFSET-1+2*TV_Y_GRID,  PSTR("1 2 3 4 5 6 7 8"));
        // set new marker
        TV.draw_rect(active_channel*16+2 ,TV_Y_OFFSET-2+2*TV_Y_GRID,12,12,  WHITE, INVERT); // mark current channel

        // clear last square
        TV.draw_rect(1, (TV_ROWS - TV_SCANNER_OFFSET + 8),125,SCANNER_MARKER_SIZE,  BLACK, BLACK);
        // draw next
        TV.draw_rect((channel * 3)+5, (TV_ROWS - TV_SCANNER_OFFSET + 8),SCANNER_MARKER_SIZE,SCANNER_MARKER_SIZE,  WHITE, WHITE);

        // show frequence
        TV.print(50,TV_Y_OFFSET+3*TV_Y_GRID, channelFrequency);
    }
    // show signal strength
    #define RSSI_BAR_SIZE 100
    uint8_t rssi_scaled=map(rssi, 1, 100, 1, RSSI_BAR_SIZE);
    // clear last bar
    TV.draw_rect(25, TV_Y_OFFSET+4*TV_Y_GRID, RSSI_BAR_SIZE,4 , BLACK, BLACK);
    //  draw new bar
    TV.draw_rect(25, TV_Y_OFFSET+4*TV_Y_GRID, rssi_scaled, 4 , WHITE, WHITE);
    // print bar for spectrum

    #define SCANNER_BAR_MINI_SIZE 14
    rssi_scaled=map(rssi, 1, 100, 1, SCANNER_BAR_MINI_SIZE);
    // clear last bar
    TV.draw_rect((channel * 3)+4, (TV_ROWS - TV_SCANNER_OFFSET - SCANNER_BAR_MINI_SIZE), 2, SCANNER_BAR_MINI_SIZE , BLACK, BLACK);
    //  draw new bar
    TV.draw_rect((channel * 3)+4, (TV_ROWS - TV_SCANNER_OFFSET - rssi_scaled), 2, rssi_scaled , WHITE, WHITE);
    // handling for seek mode after screen and RSSI has been fully processed
    if(state == STATE_SEEK)
    { // SEEK MODE
        if(last_channel != channelIndex) {
            // fix title flicker
            TV.draw_rect(0,0,127,14, WHITE,BLACK);
            if(locked) {
                TV.printPGM(((127-14*8)/2), TV_Y_OFFSET,  PSTR("AUTO MODE LOCK"));
            }
            else
            {
                TV.printPGM(((127-14*8)/2), TV_Y_OFFSET,  PSTR("AUTO MODE SEEK"));
            }
            TV.draw_rect(0,0,127,14,  WHITE,INVERT);
        }
    }

    last_channel = channelIndex;
}