int get_menuSelection(int numItems, int selectedItem){ print_menuSelection(selectedItem, numItems); update_LCD(); cli(); rotary = 0; btn_drehenc_pushed = false; sei(); while(!btn_drehenc_pushed){ if(rotary != 0){ cli(); selectedItem += rotary; rotary = 0; sei(); selectedItem = selectedItem % (numItems+1); if(selectedItem < 0){ selectedItem += numItems+1; } print_menuSelection(selectedItem, numItems); update_LCD(); } goodNight(); check_light(); } cli(); btn_drehenc_pushed = false; sei(); return selectedItem; }
void set_year(){ cli(); btn_drehenc_pushed = false; sei(); while(!btn_drehenc_pushed){ if(rotary != 0){ year += rotary; cli(); rotary = 0; sei(); if (year < 0) { year = 9999; } if(year > 9999){ year -= 10000; } for(int x = 0; x<128; x++){ for(int y = 30; y<40; y++) reset_pixel(x,y); } for(int x = 0; x<90; x++){ for(int y = YPOS_YEAR; y<YPOS_YEAR + 17; y++){ reset_pixel(x,y); } } print_year(); print_symbol(8, HERZ_KLEIN_WIDTH, herzKleinOffenSymb, get_yearXPos() + get_yearWidth() / 2 - 4, YPOS_YEAR - 10); update_LCD(); } goodNight(); check_light(); } goodNight(); check_light(); }
void set_month(){ cli(); btn_drehenc_pushed = false; sei(); while(!btn_drehenc_pushed){ if(rotary != 0){ month += rotary; cli(); rotary = 0; sei(); month = month % 12; if (month < 0) { month += 12; } if(day > pgm_read_byte(&daysPerMonth[month])){ day = pgm_read_byte(&daysPerMonth[month]); } for(int x = 0; x<128; x++){ for(int y = 0; y<10; y++) reset_pixel(x,y); } print_date(POS_DATE_SET); print_symbol(8, HERZ_KLEIN_WIDTH, herzKleinOffenSymb, get_dateXPos() + get_dayWidth() + get_monthWidth() / 2 - 4, POS_DATE_SET - 10); update_LCD(); } goodNight(); check_light(); } }
void set_timeParameter(int *timeParameter, int maxTime, bool timeType){ //timeParameter = {minute, hour, alarmMinute, alarmHour} while(!btn_drehenc_pushed) { if(rotary!=0) { cli(); *timeParameter += rotary; rotary = 0; *timeParameter = *timeParameter % maxTime; if(*timeParameter<0){ *timeParameter += maxTime; } seconds = 0; sei(); for(int x = timeXPos; x < timeXPos + hourWidth + minuteWidth + 2*SPACE_TO_DOTS + TIMEDOT_WIDTH; x++){ for(int y = 0; y < timeYPos + BIG_NUMBER_HEIGHT; y++) reset_pixel(x,y); } print_time(timeType); if(maxTime == 60) print_symbol(8,HERZ_KLEIN_WIDTH,herzKleinOffenSymb,timeXPos+hourWidth + 2*SPACE_TO_DOTS + TIMEDOT_WIDTH + minuteWidth/2-4, 2); else print_symbol(8,HERZ_KLEIN_WIDTH,herzKleinOffenSymb,timeXPos+hourWidth/2-4, 2); update_LCD(); } goodNight(); check_light(); } cli(); btn_drehenc_pushed = false; sei(); }
void funcionalidad_izquierda() { if (boton_seleccionado == IZQUIERDA) { cursor--; update_LCD(mensaje_buffer,1,cursor+1); // Escribo sin llamar la funcion, unico caso. } }
void print_stdDisplay(){ clear_pixelMatrix(); print_time(TIME_TYPE); print_date(POS_DATE_STD); if(alarm){ print_alarmLogo(); } update_LCD(); }
void funcionalidad_derecha() { if (boton_seleccionado == DERECHA) { //la segunda parte evita que te puedas mover a posiciones vacias sin tener letras atras if ((cursor < MAX_LENGTH_MESSAGE-1) && (mensaje_buffer[cursor+1] != '\0')) { cursor++; update_LCD(mensaje_buffer,1,cursor+1); // Escribo sin llamar la funcion, unico caso. } } }
void show_mainMenu(){ int item = 0; bool stayOpened = true; //wird benötigt um Rückgabewert aus Menu2 zu speichern while((item<4) && (stayOpened == true)){ print_menuItems("Weckzeit", "Uhrzeit", "Datum", ". . ."); update_LCD(); item = get_menuSelection(4, item); switch (item) { case 0: set_alarm(); break; case 1: set_time(TIME_TYPE); break; case 2: set_date(); break; case 3: stayOpened = show_mainMenu2(); break;//STAY OPENED ÜBERFLÜSSIG (?) case 4: print_stdDisplay(); break; default: print_stdDisplay(); break; } } }
void boombox(){ boot_amp(); clear_LCD(); clear_pixelMatrix(); uint8_t weckerSymb[72]; for(int i=0; i<72; i++){ weckerSymb[i] = pgm_read_byte(¬e[0][i]); } print_symbol(16,9,weckerSymb,55,24); print_symbol(16,17, hakenSymb,108,46); print_symbol(16,16, herzSymb, 92, 2+3*15); update_LCD(); while(!btn_drehenc_pushed){ goodNight(); check_light(); } shutdown_amp(); }
void funcionalidad_borrar_cancelar() { if (boton_seleccionado == BORRAR) { if (flag_escribiendo) { conteo_salto = 0; flag_escribiendo = 0; matrix_aux[boton_actual] = 0; boton_actual = 'e'; //empty boton_seleccionado = 'e'; //empty } else cursor--; mensaje_buffer[cursor] = ' '; // borrar caracter del LCD update_LCD(mensaje_buffer,1,cursor+1); // Escribo sin llamar la funcion, unico caso. } }
void update_time() { //update_timeXPos();//Alten Zeit löschen for(int x = timeXPos; x<128; x++) { for(int y = timeYPos; y<timeYPos+BIG_NUMBER_HEIGHT; y++) { reset_pixel(x,y); } } minute += timeUpdate; timeUpdate = 0; if(minute > 59) { minute = minute % 60; hour++; } if(hour > 23) { hour = 0; increment_date(); } print_time(TIME_TYPE); update_LCD(); }
bool show_mainMenu2(){ int item = 1; while((item > 0) && (item<4)){ print_menuItems(". . .","Snoozedauer", "Lautstärke", "Boombox"); update_LCD(); item = get_menuSelection(4, item); switch (item) { case 0: break; //"..." ausgewählt -> in Menü1 zurückkehren case 1: set_snoozeDuration(); break; case 2: set_audio(); break; case 3: boombox(); break; case 4: print_stdDisplay(); break; default: print_stdDisplay(); break; } } if(item == 0){ return true; } else { return false; } }
void escribir_buffer() { mensaje_buffer[cursor] = get_charmap(boton_actual,matrix_aux[boton_actual]); update_LCD(mensaje_buffer,1,cursor+1); conteo_salto = 0; }
void set_audio(){ btn_drehenc_pushed = false; int item = 0; clear_pixelMatrix(); clear_LCD(); print_symbol(16,17, hakenSymb,108,46); int warte_ASCII [strlen("Bitte warten")]; convertString("Bitte warten", warte_ASCII); print_ASCIIString(20,16, warte_ASCII, sizeof(warte_ASCII)/sizeof(warte_ASCII[0])); update_LCD(); mp3Player_onoff();//On play_pause(); _delay_ms(1000); boot_amp(); //Speaker-Symbol aus EEPROM holen uint8_t speakerSymb[SPEAKER_WIDTH]; for(int i=0; i<SPEAKER_WIDTH; i++){ speakerSymb[i] = pgm_read_byte(&speaker[0][i]); } clear_pixelMatrix(); clear_LCD(); print_symbol(16,17, hakenSymb,108,46); print_symbol(24,31,speakerSymb,(128-31)/2,(64-24)/2); rotary = 0; while(item!=1){ while(!btn_drehenc_pushed){ item+=rotary; item=item%2; if(item<0) item+=2; rotary = 0; if(item == 0){ //ggf. offenes Herz entfernen for(int x = 64-HERZ_KLEIN_WIDTH/2; x<64-HERZ_KLEIN_WIDTH/2+2; x++){ for(int y = 2; y<11; y++) reset_pixel(x,y); } print_symbol(8,HERZ_KLEIN_WIDTH,herzKleinSymb,64-4, 2);//kleines Herz über Speaker malen for(int x = 92; x<92+16; x++){//Großes Herz am Haken entfernen for(int y = 2+3*15; y<64; y++) reset_pixel(x,y); } } else { print_symbol(16,16, herzSymb, 92, 2+3*15);//Großes Herz am Haken malen for(int x = 64-8; x<64+8; x++){//kleines Herz über Speaker entfernen for(int y = 2; y<11; y++) reset_pixel(x,y); } } update_LCD(); goodNight(); check_light(); } btn_drehenc_pushed = false; for(int x = 64-8; x<64+8; x++){ for(int y = 2; y<11; y++) reset_pixel(x,y); } if(item==0){ print_symbol(8,HERZ_KLEIN_WIDTH,herzKleinOffenSymb,64-HERZ_KLEIN_WIDTH/2, 2); update_LCD(); btn_drehenc_pushed = false; while(!btn_drehenc_pushed){ goodNight(); if(rotary>0){ volume(UP); rotary = 0; } else { volume(DOWN); rotary = 0; } check_light(); } btn_drehenc_pushed = false; } } clear_pixelMatrix(); clear_LCD(); print_ASCIIString(20,16, warte_ASCII, sizeof(warte_ASCII)/sizeof(warte_ASCII[0])); update_LCD(); shutdown_amp(); mp3Player_onoff(); }
void wakeUp_User(){ mp3Player_onoff(); if(snoozeCounter == 0){ next_song(); } play_pause(); _delay_ms(1000);//warten bis mp3Player an ist boot_amp(); bool user_awake = false; LCD_LED = 1; LED_AUSTRALIA = 1; LED_NORWAY = 1; int secondsStart = seconds; while((!btn_light_pushed) && (rotary == 0) && (!btn_drehenc_pushed)){//Könnte auch von Sekundenzähler aufgewacht sein goodNight(); if(check_TimeUpdate()); update_time(); if(seconds == secondsStart + 30){ LCD_LED = 0; LED_AUSTRALIA = 0; LED_NORWAY = 0; } } LCD_LED = 0; LED_AUSTRALIA = 0; LED_NORWAY = 0; if(snoozeCounter==0){ if(btn_light_pushed){ //while(!btn_light_pushed){_delay_ms(100);} start_btnPress(); while((PINB & (1<<PINB1)) && (btn_press_duration<BTN_PRESS_LONG)){_delay_ms(50);} stop_btnPress(); if(btn_press_duration>=BTN_PRESS_LONG){ user_awake = true; } else { reset_alarmLogo(); print_snoozeLogo(); update_LCD(); snooze_alarm(); snoozeCounter = 1; } } else { reset_alarmLogo(); print_snoozeLogo(); update_LCD(); snooze_alarm(); snoozeCounter = 1; } } else { while(!user_awake){ goodNight(); if(check_TimeUpdate()) update_time(); start_btnPress(); while((PINB & (1<<PINB1)) && (btn_press_duration<BTN_PRESS_LONG)){_delay_ms(50);} stop_btnPress(); if(btn_press_duration>=BTN_PRESS_LONG){ user_awake = true; alarm = OFF; reset_alarmLogo(); reset_snoozeLogo(); snoozeCounter = 0; alarm_hour = saved_alarm_h; alarm_minute = saved_alarm_m; } } } play_pause();//Pause shutdown_amp(); mp3Player_onoff(); }
void set_time(bool timeType){ int *hou = &hour; int *min = &minute; update_timeXPos(hour, minute); if (timeType == ALARM_TYPE){ hou = &alarm_hour; min = &alarm_minute; update_timeXPos(alarm_hour, alarm_minute); } int item = 0; int old_selectedItem = 1; cli(); btn_drehenc_pushed = false; sei(); clear_pixelMatrix(); print_time(timeType); print_symbol(16,17, hakenSymb,108,46); print_symbol(8,HERZ_KLEIN_WIDTH,herzKleinSymb,timeXPos+get_timeWidth(alarm_hour)/2-4, 2); update_LCD(); while(item != 2){ while(!btn_drehenc_pushed){ if(rotary != 0){ item += rotary; cli(); rotary = 0; sei(); item = item % 3; if(item<0){ item += 3; } switch (old_selectedItem){ case 0: for(int x = 0; x<128; x++){ for(int y = 2; y<10; y++) reset_pixel(x,y); } break; case 1: for(int x = 0; x<128; x++){ for(int y = 2; y<10; y++) reset_pixel(x,y); }break; case 2: for(int x = 92; x<102; x++){ for(int y = 2+3*15+5; y<2+3*15+8+5; y++) reset_pixel(x,y); }break; } switch (item) { case 0: print_symbol(8,HERZ_KLEIN_WIDTH,herzKleinSymb,timeXPos+hourWidth/2-4, 2); break; case 1: print_symbol(8,HERZ_KLEIN_WIDTH,herzKleinSymb,timeXPos+hourWidth+2*SPACE_TO_DOTS+ TIMEDOT_WIDTH + minuteWidth/2-4, 2); break; case 2: print_symbol(8,HERZ_KLEIN_WIDTH,herzKleinSymb, 92, 2+3*15+5);break; } old_selectedItem = item; update_LCD(); } goodNight(); check_light(); } cli(); btn_drehenc_pushed = false; sei(); switch (item) { case 0: { print_symbol(8,HERZ_KLEIN_WIDTH,herzKleinOffenSymb,timeXPos+hourWidth/2-4, 2); update_LCD(); set_timeParameter(hou, 24, timeType); print_symbol(8,HERZ_KLEIN_WIDTH,herzKleinSymb,timeXPos+hourWidth/2-4, 2); break; } case 1: { print_symbol(8,HERZ_KLEIN_WIDTH,herzKleinOffenSymb,timeXPos+hourWidth+2*SPACE_TO_DOTS+ TIMEDOT_WIDTH + minuteWidth/2-4, 2); update_LCD(); set_timeParameter(min, 60, timeType); print_symbol(8,HERZ_KLEIN_WIDTH,herzKleinSymb,timeXPos+hourWidth+2*SPACE_TO_DOTS+ TIMEDOT_WIDTH + minuteWidth/2-4, 2); break; } case 2: { seconds = 0; cli(); TCNT2 = 0; timeAdvance = 0; timeUpdate = 0; sei(); break; } } update_LCD(); } }
void set_date(){ clear_pixelMatrix(); print_date(POS_DATE_SET); print_year(); print_symbol(16,17, hakenSymb,108,46); print_symbol(8, HERZ_KLEIN_WIDTH, herzKleinSymb, get_dateXPos() + get_dayWidth() / 2 - 4, POS_DATE_SET - 10); update_LCD(); int old_selectedItem = 0; int item = 0; while (item != 3){ cli(); btn_drehenc_pushed = false; sei(); while(!btn_drehenc_pushed){ if(rotary != 0){ item += rotary; cli(); rotary = 0; sei(); item = item % 4; if(item<0){ item += 4; } switch (old_selectedItem){ case 0: for(int x = 0; x<128; x++){ for(int y = 0; y<10; y++) reset_pixel(x,y); } break; case 1: for(int x = 0; x<128; x++){ for(int y = 0; y<10; y++) reset_pixel(x,y); }break; case 2: for(int x = 0; x<128; x++){ for(int y = 30; y<40; y++) reset_pixel(x,y); }break; case 3: for(int x = 94; x<104; x++){ for(int y = 2+3*15+5; y<2+3*15+5+8; y++) reset_pixel(x,y); }break; } switch (item) { case 0: print_symbol(8, HERZ_KLEIN_WIDTH, herzKleinSymb, get_dateXPos() + get_dayWidth() / 2 - 4, POS_DATE_SET - 10); break; //-4 = halbe Länge Herz case 1: print_symbol(8, HERZ_KLEIN_WIDTH, herzKleinSymb, get_dateXPos() + get_dayWidth() + get_monthWidth() / 2 - 4, POS_DATE_SET - 10); break; case 2: print_symbol(8, HERZ_KLEIN_WIDTH, herzKleinSymb, get_yearXPos() + get_yearWidth() / 2 - 4, YPOS_YEAR - 10);break; case 3: print_symbol(8, HERZ_KLEIN_WIDTH, herzKleinSymb, 94, 2+3*15+5);break; } old_selectedItem = item; update_LCD(); } goodNight(); check_light(); } cli(); btn_drehenc_pushed = false; sei(); switch (item) { case 0: { print_symbol(8, HERZ_KLEIN_WIDTH, herzKleinOffenSymb, get_dateXPos() + get_dayWidth() / 2 - 4, POS_DATE_SET - 10); update_LCD(); set_day(); print_symbol(8, HERZ_KLEIN_WIDTH, herzKleinSymb, get_dateXPos() + get_dayWidth() / 2 - 4, POS_DATE_SET - 10); break; } case 1:{ print_symbol(8, HERZ_KLEIN_WIDTH, herzKleinOffenSymb, get_dateXPos() + get_dayWidth() + get_monthWidth() / 2 - 4, POS_DATE_SET - 10); update_LCD(); set_month(); print_symbol(8, HERZ_KLEIN_WIDTH, herzKleinSymb, get_dateXPos() + get_dayWidth() + get_monthWidth() / 2 - 4, POS_DATE_SET - 10); break; } case 2: { print_symbol(8, HERZ_KLEIN_WIDTH, herzKleinOffenSymb, get_yearXPos() + get_yearWidth() / 2 - 4, YPOS_YEAR - 10); update_LCD(); set_year(); print_symbol(8, HERZ_KLEIN_WIDTH, herzKleinSymb, get_yearXPos() + get_yearWidth() / 2 - 4, YPOS_YEAR - 10); break; } default: break; } update_LCD(); } }
void inicializar_sistema() { static uint8_t valor = 0; conteo_funcionalidad++; if(flag_inicializacion == 0) { matrix_aux[1] = 1; flag_inicializacion = 1; } if (conteo_funcionalidad == 3) { conteo_funcionalidad = 0; //usamos el boton shift de forma temporal como contador para que el usuario seleccione su opcion if (boton_seleccionado == SHIFT) { if (state == MODO) { if (matrix_aux[1] > 2) matrix_aux[1] = 0; switch(++matrix_aux[1]) { case 1: { char palabra[] = "DELETREO "; int i; for(i=0;i<16;i++) mensaje_buffer[i] = palabra[i]; break; } case 2: { char palabra[] = "CIRCULAR "; int i; for(i=0;i<16;i++) mensaje_buffer[i] = palabra[i]; break; } case 3: { char palabra[] = "PING - PONG "; int i; for(i=0;i<16;i++) mensaje_buffer[i] = palabra[i]; break; } } valor = matrix_aux[1]; update_LCD(mensaje_buffer,1,16); } else { if ((valor > 4) && (matrix_aux[1] > 4)) matrix_aux[1] = 1; valor = matrix_aux[1]; mensaje_buffer[0] = get_charmap(1,++matrix_aux[1]); update_LCD(mensaje_buffer,1,1); } } if (boton_seleccionado == ENTER) { switch (state){ case VELOCIDAD: { speed = valor; matrix_aux[1] = 1; flag_cartel = 0; update_LCD(" ",1,1); break; } case INTENSIDAD: { intensity = valor; matrix_aux[1] = 0; flag_cartel = 0; update_LCD(" ",1,1); break; } case MODO: { mode = valor; matrix_aux[1] = 0; int i; for(i = 0; i<16; i++) mensaje_buffer[i] = ' '; flag_cartel = 0; update_LCD(" ",1,1); // Init para integrado MAX7219 Init_MAX7219(); break; } } state++; update_LCD(" ",1,16); } boton_seleccionado = 'e'; } }
void set_snoozeDuration(){ btn_drehenc_pushed = false; int item = 0; clear_pixelMatrix(); clear_LCD(); print_symbol(16,17, hakenSymb,108,46); while(item!=1){ int width = pgm_read_byte(&bigNumberWidth[snoozeDuration%10]); if(snoozeDuration>9){ width += pgm_read_byte(&bigNumberWidth[snoozeDuration/10]); } printSnoozetime(); while(!btn_drehenc_pushed){ item+=rotary; item=item%2; if(item<0) item+=2; rotary = 0; if(item == 0){ print_symbol(8,HERZ_KLEIN_WIDTH,herzKleinSymb,64-4, 2); for(int x = 92; x<92+16; x++){ for(int y = 2+3*15; y<64; y++) reset_pixel(x,y); } } else { print_symbol(16,16, herzSymb, 92, 2+3*15); for(int x = 64-8; x<64+8; x++){ for(int y = 2; y<11; y++) reset_pixel(x,y); } } update_LCD(); goodNight(); check_light(); } btn_drehenc_pushed = false; for(int x = 64-8; x<64+8; x++){ for(int y = 2; y<11; y++) reset_pixel(x,y); } if(item==0){ print_symbol(8,HERZ_KLEIN_WIDTH,herzKleinOffenSymb,64-HERZ_KLEIN_WIDTH/2, 2); update_LCD(); while(!btn_drehenc_pushed){ if(rotary!=0){ for(int x = 64-width/2; x<64+width/2;x++){ for(int y = timeYPos; y<timeYPos+BIG_NUMBER_HEIGHT; y++) reset_pixel(x,y); } snoozeDuration+=rotary; snoozeDuration=snoozeDuration%99; if(snoozeDuration<0) snoozeDuration+=99; rotary = 0; } printSnoozetime(); update_LCD(); goodNight(); check_light(); } btn_drehenc_pushed = false; } } }