![](/media/cache/profiles/eaa6b3305e7ecaf165c780ff4c56708d.jpg.50x50_q85.jpg)
Demo to control 4 LEDs
Dependencies: BSP_DISCO_F469NI mbed
Widgets/Button.cpp@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 | * Button.cpp |
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 | #include "Button.h" |
Faberge | 0:e06404fdff2f | 19 | |
Faberge | 0:e06404fdff2f | 20 | Button :: ~Button() |
Faberge | 0:e06404fdff2f | 21 | { |
Faberge | 0:e06404fdff2f | 22 | if (funcTwo != NULL) |
Faberge | 0:e06404fdff2f | 23 | funcTwo(); |
Faberge | 1:a6d179a9ffbb | 24 | if (fBool != NULL) |
Faberge | 1:a6d179a9ffbb | 25 | fBool(false); |
Faberge | 0:e06404fdff2f | 26 | } |
Faberge | 0:e06404fdff2f | 27 | |
Faberge | 0:e06404fdff2f | 28 | void Button :: draw(color_t clr) |
Faberge | 0:e06404fdff2f | 29 | { |
Faberge | 0:e06404fdff2f | 30 | LCD.setTextColor(clr); |
Faberge | 0:e06404fdff2f | 31 | LCD.fillRect(xPos, yPos, xDim, yDim); |
Faberge | 0:e06404fdff2f | 32 | |
Faberge | 0:e06404fdff2f | 33 | uint16_t len = strlen(str); |
Faberge | 0:e06404fdff2f | 34 | if (len != 0) |
Faberge | 0:e06404fdff2f | 35 | { |
Faberge | 0:e06404fdff2f | 36 | LCD.setBackColor(clr); |
Faberge | 0:e06404fdff2f | 37 | LCD.setTextColor(textColor); |
Faberge | 0:e06404fdff2f | 38 | LCD.setFont(&Font24); |
Faberge | 0:e06404fdff2f | 39 | |
Faberge | 0:e06404fdff2f | 40 | uint16_t x = xPos + (xDim - (Font24.Width) * len) / 2 + 1; |
Faberge | 0:e06404fdff2f | 41 | uint16_t y = yPos + (yDim - (Font24.Height)) / 2; |
Faberge | 0:e06404fdff2f | 42 | |
Faberge | 0:e06404fdff2f | 43 | LCD.displayStringAt(x, y, str); |
Faberge | 0:e06404fdff2f | 44 | } |
Faberge | 0:e06404fdff2f | 45 | } |
Faberge | 0:e06404fdff2f | 46 | |
Faberge | 0:e06404fdff2f | 47 | uint16_t Button :: update() |
Faberge | 0:e06404fdff2f | 48 | { |
Faberge | 0:e06404fdff2f | 49 | if ((state == false) && isTouched()) |
Faberge | 0:e06404fdff2f | 50 | { |
Faberge | 0:e06404fdff2f | 51 | state = true; |
Faberge | 0:e06404fdff2f | 52 | draw(backColor & FADEMASK); |
Faberge | 0:e06404fdff2f | 53 | if (funcOne != NULL) |
Faberge | 0:e06404fdff2f | 54 | funcOne(); |
Faberge | 1:a6d179a9ffbb | 55 | if (fBool != NULL) |
Faberge | 1:a6d179a9ffbb | 56 | fBool(state); |
Faberge | 0:e06404fdff2f | 57 | } |
Faberge | 0:e06404fdff2f | 58 | if ((state == true) && !isTouched()) |
Faberge | 0:e06404fdff2f | 59 | { |
Faberge | 0:e06404fdff2f | 60 | state = false; |
Faberge | 0:e06404fdff2f | 61 | draw(backColor); |
Faberge | 0:e06404fdff2f | 62 | if (funcTwo != NULL) |
Faberge | 0:e06404fdff2f | 63 | funcTwo(); |
Faberge | 1:a6d179a9ffbb | 64 | if (fBool != NULL) |
Faberge | 1:a6d179a9ffbb | 65 | fBool(state); |
Faberge | 0:e06404fdff2f | 66 | } |
Faberge | 0:e06404fdff2f | 67 | |
Faberge | 0:e06404fdff2f | 68 | return state; |
Faberge | 0:e06404fdff2f | 69 | } |