Xbeat beta code as published by Andre Moehl ( http://mbed.org/users/hoppel/ ) With a slightly modified serial port definition
button.h@0:badcd0d61c7b, 2011-02-04 (annotated)
- Committer:
- n0p
- Date:
- Fri Feb 04 08:31:00 2011 +0000
- Revision:
- 0:badcd0d61c7b
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
n0p | 0:badcd0d61c7b | 1 | /* |
n0p | 0:badcd0d61c7b | 2 | * |
n0p | 0:badcd0d61c7b | 3 | * This program is free software; you can redistribute it and/or modify |
n0p | 0:badcd0d61c7b | 4 | * it under the terms of the GNU General Public License as published by |
n0p | 0:badcd0d61c7b | 5 | * the Free Software Foundation; either version 3 of the License, or |
n0p | 0:badcd0d61c7b | 6 | * (at your option) any later version. |
n0p | 0:badcd0d61c7b | 7 | * |
n0p | 0:badcd0d61c7b | 8 | * This program is distributed in the hope that it will be useful, |
n0p | 0:badcd0d61c7b | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
n0p | 0:badcd0d61c7b | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
n0p | 0:badcd0d61c7b | 11 | * GNU General Public License for more details. |
n0p | 0:badcd0d61c7b | 12 | * |
n0p | 0:badcd0d61c7b | 13 | * You should have received a copy of the GNU General Public License |
n0p | 0:badcd0d61c7b | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
n0p | 0:badcd0d61c7b | 15 | * |
n0p | 0:badcd0d61c7b | 16 | * @file button.h |
n0p | 0:badcd0d61c7b | 17 | * @author Andre Moehl |
n0p | 0:badcd0d61c7b | 18 | * @date 01/2011 |
n0p | 0:badcd0d61c7b | 19 | * @brief Button Class definition |
n0p | 0:badcd0d61c7b | 20 | */ |
n0p | 0:badcd0d61c7b | 21 | |
n0p | 0:badcd0d61c7b | 22 | |
n0p | 0:badcd0d61c7b | 23 | /** |
n0p | 0:badcd0d61c7b | 24 | * Usage: |
n0p | 0:badcd0d61c7b | 25 | * |
n0p | 0:badcd0d61c7b | 26 | * #include "button.h" |
n0p | 0:badcd0d61c7b | 27 | * |
n0p | 0:badcd0d61c7b | 28 | * void main() |
n0p | 0:badcd0d61c7b | 29 | * { |
n0p | 0:badcd0d61c7b | 30 | * Button button(p10); |
n0p | 0:badcd0d61c7b | 31 | * int state=0; |
n0p | 0:badcd0d61c7b | 32 | * |
n0p | 0:badcd0d61c7b | 33 | * while(1) |
n0p | 0:badcd0d61c7b | 34 | * { |
n0p | 0:badcd0d61c7b | 35 | * if(button) do_something(); |
n0p | 0:badcd0d61c7b | 36 | * } |
n0p | 0:badcd0d61c7b | 37 | * } |
n0p | 0:badcd0d61c7b | 38 | */ |
n0p | 0:badcd0d61c7b | 39 | |
n0p | 0:badcd0d61c7b | 40 | #ifndef __BUTTON_H |
n0p | 0:badcd0d61c7b | 41 | #define __BUTTON_H |
n0p | 0:badcd0d61c7b | 42 | |
n0p | 0:badcd0d61c7b | 43 | /*--- Includes ------------------------*/ |
n0p | 0:badcd0d61c7b | 44 | #include "mbed.h" |
n0p | 0:badcd0d61c7b | 45 | |
n0p | 0:badcd0d61c7b | 46 | /*--- Class Declaration----------------*/ |
n0p | 0:badcd0d61c7b | 47 | |
n0p | 0:badcd0d61c7b | 48 | /** |
n0p | 0:badcd0d61c7b | 49 | Class Button - derived from Class DigitalIn |
n0p | 0:badcd0d61c7b | 50 | */ |
n0p | 0:badcd0d61c7b | 51 | class Button: public DigitalIn |
n0p | 0:badcd0d61c7b | 52 | { |
n0p | 0:badcd0d61c7b | 53 | public: |
n0p | 0:badcd0d61c7b | 54 | /** @brief Contructor |
n0p | 0:badcd0d61c7b | 55 | * @parameter pin button pin |
n0p | 0:badcd0d61c7b | 56 | * @parameter name for Pin |
n0p | 0:badcd0d61c7b | 57 | */ |
n0p | 0:badcd0d61c7b | 58 | Button(PinName pin, const char *name = NULL); |
n0p | 0:badcd0d61c7b | 59 | |
n0p | 0:badcd0d61c7b | 60 | /** @brief returns the Button state as integer */ |
n0p | 0:badcd0d61c7b | 61 | int read(void); |
n0p | 0:badcd0d61c7b | 62 | |
n0p | 0:badcd0d61c7b | 63 | /** @brief overwrites the int operator for easy use*/ |
n0p | 0:badcd0d61c7b | 64 | operator int(); |
n0p | 0:badcd0d61c7b | 65 | |
n0p | 0:badcd0d61c7b | 66 | /** @brief Sets the Debounce Time |
n0p | 0:badcd0d61c7b | 67 | * @parameter i debounce time in microseconds */ |
n0p | 0:badcd0d61c7b | 68 | void set_debounce_us(int i); |
n0p | 0:badcd0d61c7b | 69 | /** @brief Sets the Oscillations to count until Button is debounced |
n0p | 0:badcd0d61c7b | 70 | * @parameter i Number of Samples */ |
n0p | 0:badcd0d61c7b | 71 | void set_samples(int i); |
n0p | 0:badcd0d61c7b | 72 | |
n0p | 0:badcd0d61c7b | 73 | protected: |
n0p | 0:badcd0d61c7b | 74 | void _callback(void); |
n0p | 0:badcd0d61c7b | 75 | Ticker _ticker; |
n0p | 0:badcd0d61c7b | 76 | int _counter; |
n0p | 0:badcd0d61c7b | 77 | int _samples; |
n0p | 0:badcd0d61c7b | 78 | int _shadow; |
n0p | 0:badcd0d61c7b | 79 | }; |
n0p | 0:badcd0d61c7b | 80 | |
n0p | 0:badcd0d61c7b | 81 | #endif |