ELEC2645 (2019/20) / Mbed 2 deprecated el18loc_final

Dependencies:   mbed

Front/Front.cpp

Committer:
lukeocarwright
Date:
2020-05-05
Revision:
8:f305ea78b2b1
Parent:
7:33cb5f2db1ee
Child:
13:27300c533dd1

File content as of revision 8:f305ea78b2b1:

#include "mbed.h"
#include "Front.h"
//objects

const int fader[35][5] =   {
    { 1,1,1,1,1 },
    { 0,0,1,0,0 },
    { 0,0,1,0,0 },
    { 0,0,1,0,0 },
    { 0,0,1,0,0 },
    { 1,1,1,0,0 },
    { 0,0,1,0,0 },
    { 0,0,1,0,0 },
    { 0,0,1,0,0 },
    { 0,0,1,0,0 },
    { 1,1,1,0,0 },
    { 0,0,1,0,0 },
    { 0,0,1,0,0 },
    { 0,0,1,0,0 },
    { 0,0,1,0,0 },
    { 1,1,1,0,0 },
    { 0,0,1,0,0 },
    { 0,0,1,0,0 },
    { 0,0,1,0,0 },
    { 0,0,1,0,0 },
    { 1,1,1,0,0 },
    { 0,0,1,0,0 },
    { 0,0,1,0,0 },
    { 0,0,1,0,0 },
    { 0,0,1,0,0 },
    { 1,1,1,0,0 },
    { 0,0,1,0,0 },
    { 0,0,1,0,0 },
    { 0,0,1,0,0 },
    { 0,0,1,0,0 },
    { 1,1,1,0,0 },
    { 0,0,1,0,0 },
    { 0,0,1,0,0 },
    { 0,0,1,0,0 },
    { 1,1,1,1,1 },
};

const int sin_wav[6][28] =   {//sub 1
    { 0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0 },
    { 0,1,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,1,1,0,0 },
    { 1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0 },
    { 0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1 },
    { 0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0 },
    { 0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0 },
};
const int tri_wav[6][28] =   {//sub 2
    { 0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0 },
    { 0,0,1,0,1,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,1,0,1,0,0,0 },
    { 0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,1,0,0 },
    { 1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0 },
    { 0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,1 },
    { 0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0 },
};
const int square_wav[6][28] =   {//sub 3
    { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
    { 1,1,1,1,1,0,0,0,1,1,1,1,1,0,0,0,1,1,1,1,1,0,0,0,1,1,1,1 },
    { 0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0 },
    { 0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0 },
    { 0,0,0,0,1,1,1,1,1,0,0,0,1,1,1,1,1,0,0,0,1,1,1,1,1,0,0,0 },
    { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
};
//constructor/destructor
Front::Front()
{
}
Front::~Front()
{
}
//PUBLIC------------------------------------------------------------------------

void Front::frontrun(N5110 &lcd, Gamepad &pad, int submenu)
{
    frontsetup(lcd, pad, submenu);
    menuflag=1;
    while (menuflag==1) {
        if (pad.start_pressed())  { //go back menu
            // printf("start pressed\n");
            printf("Waveforms Sub selected\n"); //debug
            wait_ms(200); //debounce
            menuflag=0; //sets flag
        }
    }
}


//PRIVATE-----------------------------------------------------------------------

void Front::frontsetup(N5110 &lcd, Gamepad &pad, int submenu)
{
    a=17; //range from 1->35
    d=17;
    s=17;
    r=17;
    lcd.clear();
    lcd.printString("A D S R",3,5);
    printfader(lcd,3,3);
    printfader(lcd,15,3);
    printfader(lcd,27,3);
    printfader(lcd,39,3);
    lcd.drawRect(50,3,30,8,FILL_TRANSPARENT);
    printwav(lcd,submenu);
    printsliders(lcd,a,d,s,r);
    lcd.refresh();
    
}
void Front::printsliders(N5110 &lcd, int a, int d, int s, int r)
{
    lcd.drawRect(3,37-a,5,2,FILL_BLACK);
    lcd.drawRect(15,37-d,5,2,FILL_BLACK); 
    lcd.drawRect(27,37-s,5,2,FILL_BLACK); 
    lcd.drawRect(39,37-r,5,2,FILL_BLACK);     
}
void Front::printfader(N5110 &lcd, int x, int y)
{
    // x origin, y origin, rows, cols, sprite
    lcd.drawSprite(x,y,35,5,(int *)fader);
}

void Front::printwav(N5110 &lcd, int submenu)
{
    if (submenu==1) {
        // x origin, y origin, rows, cols, sprite
        lcd.drawSprite(51,4,6,28,(int *)sin_wav);
    }
    if (submenu==2) {
        // x origin, y origin, rows, cols, sprite
        lcd.drawSprite(51,4,6,28,(int *)tri_wav);
    }
    if (submenu==3) {
        // x origin, y origin, rows, cols, sprite
        lcd.drawSprite(51,4,6,28,(int *)square_wav);
    }
}