ELEC2645 (2018/19) / Mbed 2 deprecated el17zl

Dependencies:   mbed

Fork of el17zl by Zhenwen Liao

Menu/Menu.cpp

Committer:
franklzw
Date:
2019-05-02
Revision:
14:a6a59d1e6dd5
Parent:
11:f5d0ea7e4b74
Child:
16:27c284d8b01b

File content as of revision 14:a6a59d1e6dd5:

#include "Menu.h"

Menu::Menu()
{

}

Menu::~Menu()
{

}

void Menu::init(int bj0,int bjoy0)
{
    _x = bj0;
    _y = bjoy0;

}

void Menu::print(N5110 &lcd,Gamepad &pad)
{   
    lcd.clear();
    lcd.printString("Use Joystick",0,0);
    lcd.printString("to select",0,1);
    lcd.printString("A: Level 1",0,2);
    lcd.printString("B: Level 2",0,3);
    lcd.printString("C: Level 3",0,4);
    lcd.printString("D: Restart  ",0,5);
    int temp = _x*8+19;
    lcd.drawCircle(69,temp,3,FILL_BLACK);
    lcd.refresh();
    wait(0.2);
}

void Menu::update(Gamepad &pad) // process the reading of the joystick
{
     float p = pad.get_angle();  
     Direction d = pad.get_direction();
    switch(d){
        case N :
        _x = _x - 1;
        break;
        case S :
        _x = _x +1;
        break;
        case CENTRE :
        _x = _x;
        break;
        }
    if( _x<=0) {
        _x = 0;
    }
    if( _x>=3) {
        _x = 3;
        }
    if (pad.check_event(Gamepad::JOY_PRESSED)) {
        _y = 1;
        pad.tone(1500.0,0.1);
    } else {
        _y = 0;
    }
}

Vector2D Menu::get_level()
{
    Vector2D p = {_x,_y};
    return p;
}

void Menu::set_level(Vector2D p)
{
    _x = p.x;
    _y = p.y;
}