// Display the atlas statusbar int main(int argc, char **argv) { // Enable multi threading XInitThreads(); // Initialize gtk toolkit gtk_init(&argc, &argv); // Setup widgets set_style(); // Display widgets display_frame(); display_tags(1); display_date(attrList); display_battery(); display_wifi(); display_volume(); display_brightness(); signal(SIGUSR1, widget_updater); // Run the gtk loop gtk_main(); return 0; }
/** * @brief Volume control from the Menu. * * This function uses the Alsa API to get and set * the volume for the master channel. * The use inputs a two digit number to set the volume, * or presses the 'F' and 'B' buttons to adjust the * value incrementally. * * The volume control behaves differently from the menu, * so menu flag is set to FALSE. * * @param Void. * @return Void. */ void volume(void){ static long output = 50; int count = 0; char button_read = FALSE; // Local snapshot of Global 'Button' int state_read = SUBMENU_SELECT; get_volume(&output); display_volume(output); set_menu(FALSE); while(alive && state_read == SUBMENU_SELECT){ if(count == 0){ display_volume(output); } pthread_mutex_lock(&button_Mutex); pthread_cond_wait(&button_Signal, &button_Mutex); // Wait for press button_read = button; // Read the button pressed pthread_mutex_unlock(&button_Mutex); get_volume(&output); if(count == 0){ display_volume(output); } pthread_mutex_lock(&state_Mutex); state_read = state; pthread_mutex_unlock(&state_Mutex); if(state_read == EMERGENCY || alive == FALSE){ set_menu(FALSE); // in display.c break; // Get out if there's an emergency } /* Button has been pressed. Now what? */ switch(button_read){ case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': if(count == 0){ reset_buffers(); } if(++count <= 2){ insert_char(button_read); } if(count == 2){ output = (long)atoi(input_buffer); SetAlsaVolume(output); reset_buffers(); count = 0; } break; case 'D': if(count){ count--; delete_char(); } break; case 'B': // Down if(--output >= 0){ SetAlsaVolume(output); printd("output: %lu\n",output); } else{ output = 0; printd("output: MIN\n"); } break; case 'F': // Up if(++output < 100){ SetAlsaVolume(output); printd("output: %lu\n",output); } else{ output = 99; printd("output: MAX\n"); } break; /* Accept, Cancel or Enter * The ACE case ;) */ case 'A': case 'C': case 'E': pthread_mutex_lock(&state_Mutex); reset_buffers(); state = MENU_SELECT; // Go back to menu state_read = state; pthread_mutex_unlock(&state_Mutex); set_menu(TRUE); break; default: break; } } return; }
void GUI_Thread (void const *argument) { /** This GUI makes the assumes that, during operation, the SD card will not be removed and the contects of the SD card will not be changed. It also assumes that all of mp3 files are on the top dir and there's subdirs are not supported. */ osEvent sig; uint32_t spin_delay = 0, lcd_timeout = 0; // get the list of mp3s len = get_files("", &cur_fp); // see if there's at least one song if (cur_fp != NULL) { // if so, display the song display_stats(); } else { // otherwise display an error msg and quit LCD_write_str("<No Songs Found>", LCD_DDRAM_LINE1_ADDR); LCD_write_str("MP3 Halted :( ", LCD_DDRAM_LINE2_ADDR); return; } while(1) { // check if the player is done playing sig = osSignalWait(GUI_SIG_NEXT, 0); if ( (sig.status == osEventSignal) && (sig.value.signals & GUI_SIG_NEXT) ) { if (cur_fp->next != NULL) { ++count; cur_fp = cur_fp->next; display_stats(); if (GUI_Status == GUI_STATUS_PLAYING) { PLAYER_PLAY(cur_fp->fname); cur_song = cur_fp->fname; } } else { sta_stop(); GUI_Status = GUI_STATUS_STOPPED; } // emulate a button press so the screen would light up btn_pressed = 1; } /* light up the screen if any of the buttons were pressed */ if (btn_pressed) { // light up the screen PWM1->_2_CMPB = LCD_PWM_HIGH; // reset timeout lcd_timeout = 0; btn_pressed = 0; if(vol_btn_pressed){ display_volume(); vol_displayed = 1; vol_btn_pressed = 0; }else{ display_stats(); vol_displayed = 0; } } // assume lcd_timeout is longer than vol_timeout else if (lcd_timeout == VOL_DELAY) { // switch to song screen // Also default display to song if(vol_displayed){ display_stats(); vol_displayed = 0; } } else if (lcd_timeout == DELAY_MUL) { // timeout, so we dimm the screen PWM1->_2_CMPB = LCD_PWM_LOW; } ++lcd_timeout; // will take a while before uint32_t rolls over /* spin animation */ if (GUI_Status == GUI_STATUS_PLAYING) { if (spin_delay == SPIN_SPD) { spin_index = (spin_index + 1) % 4; spin_delay = 0; } else { ++spin_delay; } } if(!vol_displayed){ display_song(); LCD_write_nstr_f((char*)&spin_str[spin_index], 1, LCD_DDRAM_LINE1_ADDR+LCD_MAX_WIDTH-1); } osDelay(GUI_DELAY); } }