Demo to control 4 LEDs
Dependencies: BSP_DISCO_F469NI mbed
Diff: Widgets/Switch.h
- Revision:
- 1:a6d179a9ffbb
- Parent:
- 0:e06404fdff2f
--- a/Widgets/Switch.h Wed Oct 11 22:26:45 2017 +0000 +++ b/Widgets/Switch.h Tue Oct 31 14:39:54 2017 +0000 @@ -24,25 +24,35 @@ class Switch : public Widget { public: + /* Fade Widget's color when pressed */ 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) ()) : + /* Initial state of Switch is "OFF" */ + Switch(const uint16_t x, const uint16_t y, const 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) {} + fBool(NULL), state(false) {} + Switch(const uint16_t x, const uint16_t y, const color_t clr, + void (*func) (bool)) : + Widget(x, y, DIMX, DIMY, clr), b1(x, y, clr & FADEMASK, "ON"), + b2(x + Button::DIMX + 4, y, clr, "OFF"), funcOne(NULL), funcTwo(NULL), + fBool(func), state(false) {} - virtual ~Switch() {funcTwo();} + virtual ~Switch(); virtual void draw(color_t clr); virtual uint16_t update(); private: + /* Switch consists of two Buttons */ Button b1; Button b2; void (*funcOne) (); void (*funcTwo) (); + void (*fBool) (bool); bool state; };