Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problemas librería Keypad.c
16-06-2018, 05:26 PM,
#1
Problemas librería Keypad.c
hola qué tal 
tengo problemas con la librería keypad.c
que está en github para p8
la verdad es que no se bien como se declaran ciertas partes, porque al compilar me dice que tengo muchos parámetros
dejo copiado el código que tengo 
y los errores

acá es la parte donde se declaran los pines que uno desea ocupar
y supongo que es donde tengo todo malo...

Code:
//private function
void Keypad_initializePins(){
u8 c,r;
for (r=0; r<keypad_rows; r++){
for (c=0; c<keypad_columns; c++){
pinmode(columnPins[c],OUTPUT);
digitalwrite(columnPins[c],HIGH);
}
}
//configure row pin modes and states
for(r=21;r<25;r++){
pinmode(rowPins[r],INPUT);
digitalwrite(rowPins[r],HIGH);
}
}
// Initialization of Allows custom keymap. pin configuration and keypad size
void Keypad_init(char *keypadmap, u8 *rowp, u8 *colp, u8 rows, u8 cols){
userKeymap = keypadmap;
rowPins = rowp;
columnPins = colp;
keypad_rows = rows;
keypad_columns = cols;        
lastUpdate = 0;
debounceTime = 50;
holdTime = 1000;

//    keypadEventListener = 0;
currentKey = NO_KEY;
state = IDLE;
Keypad_initializePins();
}

acá
fuente original

keypad.c


y este es el código que estoy implementando.
Code:
#include <digitalw.c>
#include <millis.c>
#include "keypad.h"
//--------------------
// Consts and Defines
//--------------------
//const char NO_KEY = '\0';
//#define KEY_RELEASED NO_KEY
// this is a macro that converts 2D arrays to pou8ers:
#define makeKeymap(x) ((char *)x)
void Keypad_transitionTo(KeypadState newState);
void Keypad_initializePins();
void Keypad_init(char *keypadmap, u8 *rowp, u8 *colp, u8 rows, u8 cols);
void Keypad_setDebounceTime( unsigned int debounce);
void Keypad_setHoldTime( unsigned int hold);
//-------------------
// Library variables
//-------------------
u8 keypad_rows;
u8 keypad_columns;
char *userKeymap;
u8 *rowPins;
u8 *columnPins;
KeypadState state;
char currentKey;
unsigned long lastUpdate;
unsigned int debounceTime;
unsigned int holdTime;
const u8 rows = 4;
const u8 cols = 4;

//-----------------
// Funtions
//-----------------
// create keypad matrix
char keypadmap[4][4] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
u8 *rowp[4] = {24, 23, 22, 21}; //connect to the row pinouts of the keypad
u8 *colp [4]= {28, 27, 26, 25};
KeypadState Keypad_getState(){
return state;
}
void Keypad_setDebounceTime(unsigned int debounce){
debounceTime = debounce;
}
void Keypad_setHoldTime(unsigned int hold){
holdTime = hold;
}
//void Keypad_addEventListener(void (*listener)(char)){
//    keypadEventListener = listener;
//}
//private function
void Keypad_transitionTo(KeypadState newState){
if (state!=newState){
state = newState;
//        if (keypadEventListener!=NULL){
//            keypadEventListener(currentKey);
//        }
}
}
//private function
void Keypad_initializePins(){
u8 c,r;
for (r=0; r<keypad_rows; r++){
for (c=0; c<keypad_columns; c++){
pinmode(columnPins[c],OUTPUT);
digitalwrite(columnPins[c],HIGH);
}
}
//configure row pin modes and states
for(r=21;r<25;r++){
pinmode(rowPins[r],INPUT);
digitalwrite(rowPins[r],HIGH);
}
}
// Initialization of Allows custom keymap. pin configuration and keypad size
void Keypad_init(char *keypadmap, u8 *rowp, u8 *colp, u8 rows, u8 cols){
userKeymap = keypadmap;
rowPins = rowp;
columnPins = colp;
keypad_rows = rows;
keypad_columns = cols;        
lastUpdate = 0;
debounceTime = 50;
holdTime = 1000;

//    keypadEventListener = 0;
currentKey = NO_KEY;
state = IDLE;
Keypad_initializePins();
}
// Returns the keykode of the pressed key, or NO_KEY if no key is pressed
char Keypad_getKey(){
char key = NO_KEY; // Assume that no key is pressed, this is the default return for getKey()
u8 c,r;    
for (c=0; c<keypad_columns; c++){
digitalwrite(columnPins[c],LOW);    // Activate the current column.
for (r=0; r<keypad_rows; r++){    // Scan all the rows for a key press.
//  The user pressed a button for more then debounceTime microseconds.
if (currentKey == userKeymap[c+(r*keypad_columns)]){
// Button hold
if (((millis()-lastUpdate) >= holdTime) && (digitalread(rowPins[r])) == LOW){
Keypad_transitionTo(HOLD);


}
// Button release
if (((millis()-lastUpdate) >= debounceTime) && digitalread(rowPins[r]) == HIGH){
Keypad_transitionTo(RELEASED);
currentKey = NO_KEY;
}
}
// Button pressed event.  The user pressed a button.
else if (((millis()-lastUpdate) >= debounceTime) && digitalread(rowPins[r]) == LOW){
digitalwrite(columnPins[c],HIGH);    // De-activate the current column.
key = userKeymap[c+(r*keypad_columns)];
lastUpdate = millis();
goto EVALUATE_KEY;             // Save resources and do not attempt to parse two keys at a time
}
}
digitalwrite(columnPins[c],HIGH);    // De-activate the current column.
}
EVALUATE_KEY:
    //if (key != NO_KEY && key != currentKey ){ //Error: keeps repeating keys in the same column
if (key != NO_KEY && key != currentKey && state!=PRESSED){ //Correction for simultaneous pressed keys on the same row
        // if(state ==HOLD && key != currentKey) //try to disable several keys pressed at the same time
        //     return NO_KEY;
    
currentKey = key;
Keypad_transitionTo(PRESSED);        
return currentKey;
    }
    
    else{
return NO_KEY;
    }
}

deseo poder tener esta librería activa para pinguino 18F4550 
saludos, gracias por la ayuda ! 
Cz.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)