Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: 201_test-UI 200_yotsuba_21
ui.cpp
- Committer:
- piroro4560
- Date:
- 2021-03-03
- Revision:
- 1:ed6249618fd3
- Parent:
- 0:2623196cd444
- Child:
- 2:a5e8e6156172
File content as of revision 1:ed6249618fd3:
#include "ui.h"
UI::UI()
:   lcd(PB_9, PB_8),
    b0_(PC_3),
    tgl1(PA_9),
    tgl2(PB_10),
    tgl3(PB_5),
    buzz(PC_7)
{
    team = 0;//初期化
    algorithm = 0;
    displayst = 0;
    mode = 0;
    name1 = name2 = NULL;
    for (int i = 0; i < 4; i++) b[i] = b_[i] = 0;
    UIthread.start(callback(this,&UI::display));
}
void UI::updatebt()
{
    b0 = b0_ * 100;
    for(int i = 0; i < 4; i++){
        if((b0 > 10*(2*i + 3)) && (b0 < 10*(2*i + 5))) b[i] = 1;
        else b[i] = 0;
    }
    if(b[0] && (!b_[0])){
        team = !team;
        buzz.beep(1760.0,0.2);
    }
    if(b[1] && (!b_[1])){
        ++algorithm %= 5;
        buzz.beep(1760.0,0.4);
    }
    if(b[2] && (!b_[2])){
        ++displayst %= 4;
        buzz.beep(1760.0,0.6);
    }
    if(b[3] && (!b_[3])){
        start = !start;
        buzz.beep(1760.0,0.6);
    }
    for(int i = 0; i < 4; i++) b_[i] = b[i];
    mode = (4*!tgl1)+(2*!tgl2)+(!tgl3);
}
void UI::change(char *valname1_, char *valname2_, double *dispvalue_)
{
    name1 = valname1_;
    name2 = valname2_;
    dispvalue[0] = dispvalue_[0];
    dispvalue[1] = dispvalue_[1];
}
//void UI::display(char *valname1, char *valname2, double *dispvalue)
void UI::display()
{
    while(1) {
        updatebt();
        ThisThread::sleep_for(10ms);
        lcd.clear();
        
        lcd.setCursor(0,0);
        lcd.print(algorithm);//algo
        
        lcd.setCursor(0,0);
        lcd.print(algorithm);//algo
        lcd.setCursor(1,0);
        lcd.print(displayst);
        lcd.setCursor(2,0);
        lcd.print(name1);//
        lcd.setCursor(5,0);
        lcd.print(dispvalue[0]);
        /*
        lcd.print(b[0]);
        lcd.setCursor(6,0);
        lcd.print(b[1]);
        lcd.setCursor(7,0);
        lcd.print(b[2]);
        */
        lcd.setCursor(0,1);
        lcd.print(team);//team
        lcd.setCursor(1,1);
        lcd.print(mode);
        lcd.setCursor(2,1);
        lcd.print(name2);//
        lcd.setCursor(5,1);
        lcd.print(dispvalue[1]);
//        lcd.print(b0);
        ThisThread::sleep_for(40);
    }
}
void UI::returnchar(char *buf)
{
    for(int i = 0; i < 4; i++)
    {
        buf[i] = name1[i];
    }
}