![](/media/cache/profiles/eaa6b3305e7ecaf165c780ff4c56708d.jpg.50x50_q85.jpg)
Demo to control 4 LEDs
Dependencies: BSP_DISCO_F469NI mbed
Diff: Widgets/Switch.h
- Revision:
- 0:e06404fdff2f
- Child:
- 1:a6d179a9ffbb
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Widgets/Switch.h Wed Oct 11 22:26:45 2017 +0000 @@ -0,0 +1,50 @@ +/* + * Switch.h + * + * Copyright 2017 Faberge@TsarTeam + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#ifndef SWITCH_H +#define SWITCH_H + +#include "Widget.h" +#include "Button.h" + +class Switch : public Widget +{ + public: + static const uint32_t FADEMASK = 0xFF666666; + static const uint16_t DIMX = (Button::DIMX) * 2 + 4; + static const uint16_t DIMY = Button::DIMY; + + Switch(uint16_t x, uint16_t y, color_t clr, void (fOne) (), void (fTwo) ()) : + Widget(x, y, DIMX, DIMY, clr), b1(x, y, clr & FADEMASK, "ON"), + b2(x + Button::DIMX + 4, y, clr, "OFF"), funcOne(fOne), funcTwo(fTwo), + state(false) {} + + virtual ~Switch() {funcTwo();} + virtual void draw(color_t clr); + virtual uint16_t update(); + + private: + Button b1; + Button b2; + + void (*funcOne) (); + void (*funcTwo) (); + + bool state; +}; + +#endif \ No newline at end of file