223 lines
5.6 KiB
C++
223 lines
5.6 KiB
C++
|
|
// 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){
|
|
unsigned long temp32 = 0;
|
|
temp32=copy_EEPROM(address);
|
|
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);
|
|
}
|
|
}
|
|
|
|
void display_print_Model()
|
|
{
|
|
unsigned int address_model;
|
|
display_print(MSG_MODEL);
|
|
lcd.print(F(": "));
|
|
if (system_num_models>0)
|
|
{
|
|
address_model = EEI2C_ADDR_MODELS + 80*system_sel_model;
|
|
display_model_EEPROM(address_model);
|
|
}
|
|
else lcd.print(F(" Vacio"));
|
|
}
|
|
|
|
// 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){
|
|
unsigned int t_bat=0;
|
|
unsigned int num=10;
|
|
display_print(MSG_BATTERY); //MSG_BATTERY
|
|
for(int i=1; i<=num; i++) {delay(10); t_bat=t_bat+analogRead(bat);}
|
|
t_bat=t_bat/num;
|
|
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();
|
|
display_print(MSG_VDOSSIER_V); //MSG_VDOSSIER_V
|
|
lcd.print(CODE_MAYOR_VERSION,DEC);
|
|
lcd.print(".");
|
|
lcd.print(CODE_MINOR_VERSION,DEC);
|
|
lcd.setCursor(0,1);
|
|
display_print(MSG_READY); //MSG_READY
|
|
}
|
|
|
|
void display_time(unsigned long time_temp)
|
|
{
|
|
time_temp;
|
|
int hours=(int)time_temp/3600;
|
|
int minutes = time_temp%3600;
|
|
int seconds = minutes%60;
|
|
minutes = (int)minutes/60;
|
|
if (hours<10) lcd.print("0");
|
|
lcd.print(hours);
|
|
lcd.print(":");
|
|
if (minutes<10) lcd.print("0");
|
|
lcd.print(minutes);
|
|
lcd.print(":");
|
|
if (seconds<10) lcd.print("0");
|
|
lcd.print(seconds);
|
|
}
|
|
|
|
void display_print(const prog_char* str) {
|
|
char c;
|
|
if (!str) return;
|
|
while ((c = pgm_read_byte(str))) {
|
|
lcd.print(c);
|
|
str++;
|
|
}
|
|
}
|
|
|
|
// prints screen title
|
|
void display_printTitle(const prog_char* str){
|
|
lcd.clear();
|
|
lcd.print(">");
|
|
display_print(str);
|
|
lcd.setCursor(0,1);
|
|
}
|
|
|
|
void display_printEnumeration(byte num, const prog_char* str){
|
|
lcd.print(num, 10);
|
|
lcd.print(".");
|
|
display_print(str);
|
|
}
|
|
|
|
// prints resetting message
|
|
void display_printResetting(){
|
|
lcd.clear();
|
|
display_print(MSG_RESETTING);//MSG_RESETTING
|
|
delay(500);
|
|
}
|
|
|
|
// prints a boolean value
|
|
void display_printBoolean(boolean value) {
|
|
lcd.print(" (");
|
|
if (value) display_print(MSG_YES); else display_print(MSG_NO); //MSG_YES y MSG_NO
|
|
lcd.print(")");
|
|
}
|
|
|
|
void display_WiFlyResetting(byte *baudrate){
|
|
lcd.clear();
|
|
display_print(MSG_RESETTING); //MSG_RESETTING/*0*/
|
|
if (udp.reset())
|
|
{
|
|
lcd.setCursor(0,1);
|
|
display_print(MSG_RESET); //MSG_RESET/*1*/
|
|
*baudrate = 0;
|
|
Serial.begin(vel[*baudrate]);
|
|
}
|
|
else
|
|
{
|
|
lcd.setCursor(0,1);
|
|
display_print(MSG_FAIL); //MSG_FAIL/*2*/
|
|
}
|
|
delay(2000);
|
|
}
|
|
|
|
void display_WiFlyConnecting(byte *baudrate){
|
|
lcd.clear();
|
|
display_print(MSG_CONNECTING); //MSG_CONNECTING/*3*/
|
|
lcd.setCursor(0,1);
|
|
display_print(MSG_BAUD); //MSG_BAUD/*4*/
|
|
lcd.print(vel[*baudrate]);
|
|
udp.begin(ssid, pass, ip_host, remote_Port, local_Port);
|
|
if (udp.join())
|
|
{
|
|
delay(2000);
|
|
lcd.clear();
|
|
display_print(MSG_CONNECT); //MSG_CONNECT/*5*/
|
|
lcd.setCursor(0,1);
|
|
lcd.print(udp.ip());
|
|
delay(2000);
|
|
}
|
|
else
|
|
{
|
|
lcd.clear();
|
|
display_print(MSG_FAIL_CONNECT); //MSG_FAIL_CONNECT/*6*/
|
|
delay(2000);
|
|
}
|
|
}
|
|
|