196 lines
4.8 KiB
Arduino
196 lines
4.8 KiB
Arduino
|
|
||
|
// Scans keyboard buttons
|
||
|
void keyboard_scan() {
|
||
|
|
||
|
unsigned long time = millis();
|
||
|
|
||
|
if (flagHoldKey) {
|
||
|
system_beep(100);
|
||
|
while(!digitalRead(bot[0]) || !digitalRead(bot[1]) || !digitalRead(bot[2]) || !digitalRead(bot[3])) {}
|
||
|
flagHoldKey = false;
|
||
|
lastKey = NO_KEY;
|
||
|
} else if (!digitalRead(bot[0])) {
|
||
|
while(!digitalRead(bot[0]) && (millis()-time) <= KEY_HOLD_TIME){
|
||
|
if (millis()-time >= KEY_DEBOUNCE_TIME) lastKey = KEY_A;
|
||
|
//if (millis()-time >= KEY_HOLD_TIME) { lastKey = KEY_AH; flagHoldKey = true; }
|
||
|
}
|
||
|
} else if (!digitalRead(bot[1])) {
|
||
|
while(!digitalRead(bot[1]) && (millis()-time) <= KEY_HOLD_TIME){
|
||
|
if (millis()-time >= KEY_DEBOUNCE_TIME) lastKey = KEY_B;
|
||
|
//if (millis()-time >= KEY_HOLD_TIME) { lastKey = KEY_BH; flagHoldKey = true; }
|
||
|
}
|
||
|
} else if (!digitalRead(bot[2])) {
|
||
|
while(!digitalRead(bot[2]) && (millis()-time) <= KEY_HOLD_TIME){
|
||
|
if (millis()-time >= KEY_DEBOUNCE_TIME) lastKey = KEY_C;
|
||
|
//if (millis()-time >= KEY_HOLD_TIME) { lastKey = KEY_CH; flagHoldKey = true; }
|
||
|
}
|
||
|
} else if (!digitalRead(bot[3])) {
|
||
|
while(!digitalRead(bot[3]) && (millis()-time) <= KEY_HOLD_TIME){
|
||
|
if (millis()-time >= KEY_DEBOUNCE_TIME) lastKey = KEY_D;
|
||
|
//if (millis()-time >= KEY_HOLD_TIME) { lastKey = KEY_DH; flagHoldKey = true; }
|
||
|
}
|
||
|
} else {
|
||
|
flagHoldKey = false;
|
||
|
lastKey = NO_KEY;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Waits until any key is pressed
|
||
|
void keyboard_waitForAnyKey(){
|
||
|
do{ keyboard_scan(); } while (lastKey==NO_KEY);
|
||
|
}
|
||
|
|
||
|
void keyboard_IR(boolean *print_ir){
|
||
|
do{ keyboard_scan();
|
||
|
if (irrecv.decode(&results)) { //recepcion IR
|
||
|
irrecv.resume(); // Receive the next value
|
||
|
*print_ir = true;
|
||
|
}
|
||
|
} while ((lastKey==NO_KEY)&&(!(*print_ir)));
|
||
|
}
|
||
|
|
||
|
unsigned long display_printEEPROM(unsigned int address){
|
||
|
uint8_t temp=0;
|
||
|
unsigned long temp32 = 0;
|
||
|
int i=0;
|
||
|
temp = readEEPROM(eeprom, address + i);
|
||
|
while ((temp!=0x0D)&&(i<16)) {
|
||
|
temp32 = (temp32<<8) + temp;
|
||
|
i++;
|
||
|
temp = readEEPROM(eeprom, address + i);
|
||
|
}
|
||
|
lcd.print(temp32,HEX) ;
|
||
|
return(temp32);
|
||
|
}
|
||
|
|
||
|
void display_model_EEPROM(unsigned int address){
|
||
|
uint8_t temp=0;
|
||
|
int i=0;
|
||
|
temp = readEEPROM(eeprom, address + i);
|
||
|
while ((temp!=0x0D)&&(i<16)) {
|
||
|
lcd.print((char)temp) ;
|
||
|
i++;
|
||
|
temp = readEEPROM(eeprom, address + i);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Waits until no key is pressed
|
||
|
void keyboard_waitForNokey(){
|
||
|
do{ keyboard_scan(); } while (lastKey!=NO_KEY);
|
||
|
}
|
||
|
|
||
|
// Beeps buzzer a time in ms
|
||
|
void system_beep(int time){
|
||
|
if (system_useSpeaker){
|
||
|
digitalWrite(PINS_BUZZER,HIGH);
|
||
|
delay(time);
|
||
|
digitalWrite(PINS_BUZZER,LOW);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void level_bat(int batmin,int batmax){
|
||
|
volatile int t_bat=0;
|
||
|
lcd.print(MSG_BATTERY_LEVEL);
|
||
|
for(int i=1; i<=10; i++) t_bat=t_bat+analogRead(bat);
|
||
|
t_bat=t_bat/10;
|
||
|
volatile int level=((float)(((float)t_bat-batmin)/(batmax-batmin))*100.0);
|
||
|
if (level<100) lcd.print("0");
|
||
|
else if (level<10) lcd.print("00");
|
||
|
lcd.print(level);
|
||
|
lcd.print("%");
|
||
|
}
|
||
|
|
||
|
// Toggle the backlight status (on/off)
|
||
|
void backlight_toggle(){
|
||
|
|
||
|
system_useBacklight = !system_useBacklight;
|
||
|
lcd.shiftWrite(LCD_L, !system_useBacklight);
|
||
|
}
|
||
|
|
||
|
void display_vdossier(){
|
||
|
lcd.clear();
|
||
|
lcd.print(MSG_VDOSSIER_V);
|
||
|
lcd.print(CODE_MAYOR_VERSION,DEC);
|
||
|
lcd.print(".");
|
||
|
lcd.print(CODE_MINOR_VERSION,DEC);
|
||
|
lcd.setCursor(0,1);
|
||
|
lcd.print(MSG_READY);
|
||
|
}
|
||
|
|
||
|
// prints screen title
|
||
|
void display_printTitle(char *title){
|
||
|
lcd.clear();
|
||
|
lcd.print(">");
|
||
|
lcd.print(title);
|
||
|
lcd.setCursor(0,1);
|
||
|
}
|
||
|
|
||
|
void display_printEnumeration(byte num, char *msg){
|
||
|
lcd.print(num, 10);
|
||
|
lcd.print(".");
|
||
|
lcd.print(msg);
|
||
|
}
|
||
|
|
||
|
// prints resetting message
|
||
|
void display_printResetting(){
|
||
|
lcd.clear();
|
||
|
lcd.print(MSG_RESETTING);
|
||
|
delay(500);
|
||
|
}
|
||
|
|
||
|
// prints aborting message
|
||
|
void display_printAborting(){
|
||
|
lcd.clear();
|
||
|
lcd.print(MSG_ABORTING);
|
||
|
}
|
||
|
|
||
|
// prints a boolean value
|
||
|
void display_printBoolean(boolean value) {
|
||
|
lcd.print(" (");
|
||
|
if (value) lcd.print(MSG_YES); else lcd.print(MSG_NO);
|
||
|
lcd.print(")");
|
||
|
}
|
||
|
|
||
|
void display_WiFlyResetting(long *baudrate){
|
||
|
lcd.clear();
|
||
|
lcd.print("Reseteando...");
|
||
|
if (udp.reset())
|
||
|
{
|
||
|
lcd.setCursor(0,1);
|
||
|
lcd.print("WiFly Reseteado");
|
||
|
*baudrate = 9600;
|
||
|
Serial.begin(*baudrate);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
lcd.setCursor(0,1);
|
||
|
lcd.print("Fallo reseteando");
|
||
|
}
|
||
|
delay(2000);
|
||
|
}
|
||
|
|
||
|
void display_WiFlyConnecting(long *baudrate){
|
||
|
lcd.clear();
|
||
|
lcd.print("Conectando...");
|
||
|
lcd.setCursor(0,1);
|
||
|
lcd.print("Baud:");
|
||
|
lcd.print(*baudrate);
|
||
|
udp.begin(ssid, pass, ip_host, remote_Port, local_Port);
|
||
|
if (udp.join())
|
||
|
{
|
||
|
delay(2000);
|
||
|
lcd.clear();
|
||
|
lcd.print("Conectado");
|
||
|
lcd.setCursor(0,1);
|
||
|
lcd.print(udp.ip());
|
||
|
delay(2000);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
lcd.clear();
|
||
|
lcd.print("Sin conexion");
|
||
|
delay(2000);
|
||
|
}
|
||
|
}
|
||
|
|