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.cpp Source File

keypad.cpp

00001 #include "keypad.h"
00002 
00003 Keypad::Keypad(PinName row3, PinName row2, PinName row1, PinName row0,
00004                PinName col3, PinName col2, PinName col1, PinName col0,
00005                int debounce_ms):
00006         _row0(row0), _row1(row1), _row2(row2), _row3(row3),
00007         _cols(col0, col1, col2, col3) {
00008     _debounce = debounce_ms;
00009     _setupRiseTrigger();
00010 }
00011 
00012 void Keypad::Start(void) {
00013     _cols = 0x0F;
00014 }
00015 
00016 void Keypad::Stop(void) {
00017     _cols = 0x00;
00018 }
00019 
00020 void Keypad::CallAfterInput(uint32_t (*fptr)(uint32_t index)) {
00021     _input.attach(fptr);
00022 }
00023 
00024 void Keypad::_callback(int row, InterruptIn &therow) {
00025     wait_ms(_debounce);
00026     if (therow != 1)
00027         return;
00028 
00029     int c = -1;
00030     _cols = _cols & 0x0E;
00031     if (therow == 0)
00032         c = 0;
00033     else {
00034         _cols = _cols & 0x0D;
00035         if (therow == 0)
00036             c = 1;
00037         else {
00038             _cols = _cols & 0x0B;
00039             if (therow == 0)
00040                 c = 2;
00041             else
00042                 c = 3;
00043         }
00044     }
00045     _input.call(row * 4 + c);
00046     Start(); // Re-energize all columns
00047 }
00048 
00049 void Keypad::_cbRow0Rise(void) {
00050     _callback(0, _row0);
00051 }
00052 void Keypad::_cbRow1Rise(void) {
00053     _callback(1, _row1);
00054 }
00055 void Keypad::_cbRow2Rise(void) {
00056     _callback(2, _row2);
00057 }
00058 void Keypad::_cbRow3Rise(void) {
00059     _callback(3, _row3);
00060 }
00061 
00062 void Keypad::_setupRiseTrigger(void) {
00063     _row0.rise(this, &Keypad::_cbRow0Rise);
00064     _row1.rise(this, &Keypad::_cbRow1Rise);
00065     _row2.rise(this, &Keypad::_cbRow2Rise);
00066     _row3.rise(this, &Keypad::_cbRow3Rise);
00067 }