Demo to control 4 LEDs
Dependencies: BSP_DISCO_F469NI mbed
Widgets/Switch.h@2:e6fc24fbd86c, 2017-10-31 (annotated)
- Committer:
- Faberge
- Date:
- Tue Oct 31 14:46:28 2017 +0000
- Revision:
- 2:e6fc24fbd86c
- Parent:
- 1:a6d179a9ffbb
Update
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Faberge | 0:e06404fdff2f | 1 | /* |
Faberge | 0:e06404fdff2f | 2 | * Switch.h |
Faberge | 0:e06404fdff2f | 3 | * |
Faberge | 0:e06404fdff2f | 4 | * Copyright 2017 Faberge@TsarTeam |
Faberge | 0:e06404fdff2f | 5 | * |
Faberge | 0:e06404fdff2f | 6 | * This program is free software; you can redistribute it and/or modify |
Faberge | 0:e06404fdff2f | 7 | * it under the terms of the GNU General Public License as published by |
Faberge | 0:e06404fdff2f | 8 | * the Free Software Foundation; either version 2 of the License, or |
Faberge | 0:e06404fdff2f | 9 | * (at your option) any later version. |
Faberge | 0:e06404fdff2f | 10 | * |
Faberge | 0:e06404fdff2f | 11 | * This program is distributed in the hope that it will be useful, |
Faberge | 0:e06404fdff2f | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
Faberge | 0:e06404fdff2f | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Faberge | 0:e06404fdff2f | 14 | * GNU General Public License for more details. |
Faberge | 0:e06404fdff2f | 15 | * |
Faberge | 0:e06404fdff2f | 16 | */ |
Faberge | 0:e06404fdff2f | 17 | |
Faberge | 0:e06404fdff2f | 18 | #ifndef SWITCH_H |
Faberge | 0:e06404fdff2f | 19 | #define SWITCH_H |
Faberge | 0:e06404fdff2f | 20 | |
Faberge | 0:e06404fdff2f | 21 | #include "Widget.h" |
Faberge | 0:e06404fdff2f | 22 | #include "Button.h" |
Faberge | 0:e06404fdff2f | 23 | |
Faberge | 0:e06404fdff2f | 24 | class Switch : public Widget |
Faberge | 0:e06404fdff2f | 25 | { |
Faberge | 0:e06404fdff2f | 26 | public: |
Faberge | 1:a6d179a9ffbb | 27 | /* Fade Widget's color when pressed */ |
Faberge | 0:e06404fdff2f | 28 | static const uint32_t FADEMASK = 0xFF666666; |
Faberge | 0:e06404fdff2f | 29 | static const uint16_t DIMX = (Button::DIMX) * 2 + 4; |
Faberge | 0:e06404fdff2f | 30 | static const uint16_t DIMY = Button::DIMY; |
Faberge | 0:e06404fdff2f | 31 | |
Faberge | 1:a6d179a9ffbb | 32 | /* Initial state of Switch is "OFF" */ |
Faberge | 1:a6d179a9ffbb | 33 | Switch(const uint16_t x, const uint16_t y, const color_t clr, |
Faberge | 1:a6d179a9ffbb | 34 | void (*fOne) (), void (*fTwo) ()) : |
Faberge | 0:e06404fdff2f | 35 | Widget(x, y, DIMX, DIMY, clr), b1(x, y, clr & FADEMASK, "ON"), |
Faberge | 0:e06404fdff2f | 36 | b2(x + Button::DIMX + 4, y, clr, "OFF"), funcOne(fOne), funcTwo(fTwo), |
Faberge | 1:a6d179a9ffbb | 37 | fBool(NULL), state(false) {} |
Faberge | 1:a6d179a9ffbb | 38 | Switch(const uint16_t x, const uint16_t y, const color_t clr, |
Faberge | 1:a6d179a9ffbb | 39 | void (*func) (bool)) : |
Faberge | 1:a6d179a9ffbb | 40 | Widget(x, y, DIMX, DIMY, clr), b1(x, y, clr & FADEMASK, "ON"), |
Faberge | 1:a6d179a9ffbb | 41 | b2(x + Button::DIMX + 4, y, clr, "OFF"), funcOne(NULL), funcTwo(NULL), |
Faberge | 1:a6d179a9ffbb | 42 | fBool(func), state(false) {} |
Faberge | 0:e06404fdff2f | 43 | |
Faberge | 1:a6d179a9ffbb | 44 | virtual ~Switch(); |
Faberge | 0:e06404fdff2f | 45 | virtual void draw(color_t clr); |
Faberge | 0:e06404fdff2f | 46 | virtual uint16_t update(); |
Faberge | 0:e06404fdff2f | 47 | |
Faberge | 0:e06404fdff2f | 48 | private: |
Faberge | 1:a6d179a9ffbb | 49 | /* Switch consists of two Buttons */ |
Faberge | 0:e06404fdff2f | 50 | Button b1; |
Faberge | 0:e06404fdff2f | 51 | Button b2; |
Faberge | 0:e06404fdff2f | 52 | |
Faberge | 0:e06404fdff2f | 53 | void (*funcOne) (); |
Faberge | 0:e06404fdff2f | 54 | void (*funcTwo) (); |
Faberge | 1:a6d179a9ffbb | 55 | void (*fBool) (bool); |
Faberge | 0:e06404fdff2f | 56 | |
Faberge | 0:e06404fdff2f | 57 | bool state; |
Faberge | 0:e06404fdff2f | 58 | }; |
Faberge | 0:e06404fdff2f | 59 | |
Faberge | 0:e06404fdff2f | 60 | #endif |