fini

Dependencies:   F746_GUI mbed

main.cpp

Committer:
MikamiUitOpen
Date:
2016-04-12
Revision:
4:4f73a3054a67
Parent:
3:e92615be71c7
Child:
6:ea30227e7db0

File content as of revision 4:4f73a3054a67:

//--------------------------------------------------------------------------------
//  GuiBase とその派生クラスのデモプログラム
//  Demo program for GuiBase class and its derivertive classes
//
//      GuiBase, Button, ButtonGroup, Label, NumericLabel, BlinkLabel, SeekBar
//
//  2016/04/12, Copyright (c) 2016 MIKAMI, Naoki
//--------------------------------------------------------------------------------

#include "NumericLabel.hpp"
#include "BlinkLabel.hpp"
#include "ButtonGroup.hpp"
#include "SeekBar.hpp"

using namespace Mikami;

Ticker timer;
NumericLabel<float> obj2(10, 116, Label::LEFT, Font16, LCD_COLOR_YELLOW);

void TimerIsr()
{
    static int sec = 0;
    obj2.Draw("%6.1f [s]", (float)(sec++)/10.0f);
}

int main()
{
    Label obj10(240, 4, "Dome: GUI parts, 2016/04/12", Label::CENTER, Font16);
    Label obj11(240, 24, "Label, NumericLabel, BlinkLabel, Button, ButtonGroup, SeekBar",
                Label::CENTER);

    Button button1(10, 50, 50, 40, "1");
    Button button2(62, 50, 50, 40, "2");

    const int NUMBER_BUTTONS = 4;
    const string STR1[NUMBER_BUTTONS] = {"Button1", "Button2", "Button3", "Button4"};
    ButtonGroup bGroup1(160, 50, 66, 40,  NUMBER_BUTTONS, STR1, 5, 5, 3, 1,
                        Font12, LCD_COLOR_WHITE, 0xFF003538, 0xFFB70068, 0xFFFF7FFF);
    NumericLabel<int> bTouch(234, 108, Label::LEFT, Font16, LCD_COLOR_MAGENTA);

    // Control status of bGroup1
    const string STR2[3] = {"0", "1", "2"};
    ButtonGroup bGroup2(160, 150, 66, 40,  3, STR2, 5, 5, 3);
    
    // Switching buttons to control barH active or inactive
    const string STR3[3] = {"ON", "OFF"};
    ButtonGroup bGroup3(10, 150, 66, 40,  2, STR3, 0, 0, 2);
    bGroup3.TouchedColor(0);

    Button doNotTouch(250, 220, 120, 40, "Don't Touch", Font12,
                      GuiBase::ENUM_TEXT, GuiBase::ENUM_BACK,
                      LCD_COLOR_DARKGREEN, LCD_COLOR_RED);

    // Using default value for argument (Horisontal)
    SeekBar barH(20, 250, 200, -5, 5, 0, "-5", "", "5");
    NumericLabel<float> numLabel1(80, 205, "%5.1f", barH.GetValue());
    NumericLabel<int> numLabel2(130, 205, "%3d", (int)barH.GetValue());
    NumericLabel<int> numLabel3(160, 205);
    
    // SeekBar (vertical)
    SeekBar barV(440, 100, 150, -5, 5, 2, SeekBar::Vertical, LCD_COLOR_GREEN);
    NumericLabel<float> numLabel4(440, 70, "%4.1f", barV.GetValue(), Label::CENTER);

    timer.attach(&TimerIsr, 0.1f);

    while (true)
    {
        if (button1.Touched()) button2.Draw();
        if (button2.Touched()) button1.Draw();

        int num;
        if (bGroup1.GetTouchedNumber(num))
            bTouch.Draw("Button%d touched", num+1);

        if (bGroup2.GetTouchedNumber(num))
        switch (num)
        {
            case 0: button1.Activate();
                    bGroup1.Activate(1);
                    bGroup1.DrawAll();
                    break;
            case 1: button1.Inactivate();
                    bGroup1.Inactivate(1);
                    break;
            case 2: for (int n=0; n<4; n++) bGroup1.Erase(n);
                    break;
        }

        if (barH.Slide())
        {
            numLabel1.Draw("%5.1f", barH.GetValue());
            int8_t x = (int8_t)barH.GetValue();
            numLabel2.Draw("%3d", x);

            numLabel3.Draw("%3d", barH.GetIntValue());            
        }        

        if (barV.Slide()) { numLabel4.Draw("%4.1f", barV.GetValue()); }
        
        // If "doNotTouch" button touched, trapped into endless loop
        if (doNotTouch.Touched())
            BlinkLabel warning(250, 200, "You must reset", Label::LEFT, Font16);
            
        // SeekBar active inactive switching
        if (bGroup3.Touched(0))
        {
            barH.Activate();
            barV.Activate();
        }
        if (bGroup3.Touched(1))
        {
            barH.Inactivate();
            barV.Inactivate();
        }

        wait(0.02f);
    }
}