libreria teclado

Dependents:   Tarea3_Teclado Tarea3_Teclado_Mejoras Tarea3_Teclado_sonido IngresoHORA ... more

Fork of keypad by Leonardo Restrepo

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers keypad.h Source File

keypad.h

00001 /* mbed Keypad library, using user-defined interrupt callback
00002  * Copyright (c) 2012 Yoong Hor Meng
00003  *
00004  * Permission is hereby granted, free of charge, to any person obtaining a copy
00005  * of this software and associated documentation files (the "Software"), to deal
00006  * in the Software without restriction, including without limitation the rights
00007  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00008  * copies of the Software, and to permit persons to whom the Software is
00009  * furnished to do so, subject to the following conditions:
00010  *
00011  * The above copyright notice and this permission notice shall be included in
00012  * all copies or substantial portions of the Software.
00013  *
00014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00017  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00018  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00019  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00020  * THE SOFTWARE
00021  */
00022 
00023 #ifndef KEYPAD_H
00024 #define KEYPAD_H
00025 
00026 #include "mbed.h"
00027 #include "FPointer.h"
00028 
00029 /**
00030  * An interrupt-based interface to 4x4 keypad.
00031  *
00032  * On each key pressed on a keypad, the index of the key is passed to a
00033  * user-defined function. User is free to define what to be done with the
00034  * input.
00035  *
00036  * This library makes use of
00037  * @see http://mbed.org/cookbook/FPointer by Andy Kirkham
00038  *
00039  * Example:
00040  * @code
00041  * #include "mbed.h"
00042  * #include "keypad.h"
00043  * 
00044  * // Define your own keypad values
00045  * char Keytable[] = { '1', '2', '3', 'A',
00046  *                     '4', '5', '6', 'B',
00047  *                     '7', '8', '9', 'C',
00048  *                     '*', '0', '#', 'D'
00049  *                   };
00050  * 
00051  * uint32_t cbAfterInput(uint32_t index) {
00052  *     printf("Index:%d => Key:%c\n", key, Keytable[index]);
00053  *     return 0;
00054  * }
00055  * 
00056  * int main() {
00057  *     Keypad keypad(p25, p26, p27, p28, p21, p22, p23, p24);
00058  *     keypad.CallAfterInput(&cbAfterInput);
00059  *     keypad.Start();
00060  * 
00061  *     while (1) {
00062  *         wait_ms(100);
00063  *     }
00064  * }
00065  * @endcode
00066  */
00067 class Keypad {
00068 public:
00069     /** Create a Keypad interface
00070      *
00071      *  @param row<3..0>     Row data lines
00072      *  @param col<3..0>     Column data lines
00073      *  @param debounce_ms   Debounce in ms (Default to 20ms)
00074      */
00075     Keypad(PinName row3, PinName row2, PinName row1, PinName row0,
00076            PinName col3, PinName col2, PinName col1, PinName col0,
00077            int debounce_ms = 20);
00078 
00079     /** Start the keypad interrupt routines
00080      */
00081     void Start(void);
00082 
00083     /** Stop the keypad interrupt routines
00084      */
00085     void Stop(void);
00086 
00087     /** User-defined function that to be called when a key is pressed
00088      *  @param fptr           A function pointer takes a uint32_t and
00089      *                        returns uint32_t
00090      */
00091     void CallAfterInput(uint32_t (*fptr)(uint32_t));
00092 
00093 protected:
00094     InterruptIn      _row0;
00095     InterruptIn      _row1;
00096     InterruptIn      _row2;
00097     InterruptIn      _row3;
00098     BusOut           _cols;
00099     int              _debounce;
00100     FPointer         _input; // Called after each input
00101 
00102     void _callback(int row, InterruptIn &therow);
00103     void _cbRow0Rise(void);
00104     void _cbRow1Rise(void);
00105     void _cbRow2Rise(void);
00106     void _cbRow3Rise(void);
00107     void _setupRiseTrigger(void);
00108     void _dummy(void) { };
00109 };
00110 
00111 #endif // KEYPAD_H