Beispiel #1
0
static void set_battery(BatteryChargeState state) {
	// Set battery percent layer, account for bug where state.charge_percent never gets above 90
	if(state.is_plugged && !state.is_charging && state.charge_percent == 90)
		snprintf(percent_str, sizeof(percent_str), "100%%");
	else
		snprintf(percent_str, sizeof(percent_str), "%d%%", (int)state.charge_percent);
	text_layer_set_text(percent_layer, percent_str);

	// Set battery fill layer
	layer_set_frame(
		inverter_layer_get_layer(battfill_layer),
		GRect(8, 136, state.charge_percent/5, 16)
	);

	// Show or hide charging icon
	if(state.is_plugged)
		layer_set_hidden(bitmap_layer_get_layer(charge_layer), false);
	else
		layer_set_hidden(bitmap_layer_get_layer(charge_layer), true);

	// Show or hide battery indicator
	if(state.is_plugged || state.charge_percent <= 20)
		show_battery();
	else
		hide_battery();
}
Beispiel #2
0
struct wmplugin_data *wmplugin_exec(int mesg_count, union cwiid_mesg mesg[])
{
	int i;
	uint8_t button;
	struct cwiid_btn_message *btn_mesg;

	uint8_t led_state = (Led1 ? CWIID_LED1_ON : 0)
	                  | (Led2 ? CWIID_LED2_ON : 0)
	                  | (Led3 ? CWIID_LED3_ON : 0)
	                  | (Led4 ? CWIID_LED4_ON : 0);

	if(Battery != 0) {		
		btn_mesg = NULL;
		for (i=0; i < mesg_count; i++) {
			if (mesg[i].type == CWIID_MESG_BTN) {
				btn_mesg = &mesg[i].btn_mesg;
				button = mesg[i].btn_mesg.buttons;
			}
		}

		if (!btn_mesg) {
			return NULL;
		}

		if(button == Button) {
			show_battery();
		} 
		else {
			cwiid_command(wiimote, CWIID_CMD_LED, led_state);
		}
	}
	
	return &data;
}
Beispiel #3
0
/********************************** 功能说明 ***********************************
*  显示时间
*******************************************************************************/
void	show_std_clock( void )
{
	uint32_t	now = get_Now();

	ShowClock( 0x0600u, &now );
	show_battery( 0x0009u );
}
Beispiel #4
0
/********************************** 功能说明 **********************************
*  显示时间
*******************************************************************************/
void	Show_std_clock( void )
{
	uint32_t	now = get_Now();

	ShowClock( 0x0318u, &now );
	ShowWDay ( 0x011Au, &now );
	show_battery( 0x0020u );
}
Beispiel #5
0
/* Check time elapsed after one frame, hold up
 * the program if not enough tim has elapsed */
void adjust_to_framerate() {
// EMSCRIPTEN had its own ways to run frames at certain FPS
#ifndef EMSCRIPTEN 

    char title_buf[100];

    current_ticks = get_timestamp_micro();
    uint64_t ticks_elapsed = current_ticks - last_ticks;
    uint64_t estimated_ticks = last_ticks + (uint64_t)(1000 * (1000/framerate));
    uint64_t framerate_ticks = ticks_elapsed * framerate;
    
    // If too fast we sleep for a certain amount of time
    // sleep might go over the time we want to wait
    // so attempt to come out of sleep early and use 
    // cpu cycles to wait for the rest of the time
    if (limiter && framerate_ticks < 1000000) {        
	    uint64_t delay_time = 1000000/framerate - ticks_elapsed;
	    if (delay_time >= 5000) {
		    //casting uint64_t into uint32_t, not really safe
		    // but we will never be delaying for more than 1000ms which is well in range
 		    SDL_Delay( (uint32_t) ((delay_time - 200)/1000));        
	    }	
        while(get_timestamp_micro() < estimated_ticks)
  		    ;;
        }   

    current_ticks = get_timestamp_micro();
    count = (count + 1) % 60;
    if (count == 0) {
	//printf("speed %u\n", current_ticks - last_ticks);
        float fps = 1000000.0 / (current_ticks - last_ticks);
        //printf("Gameboy fps:%.2f\n",fps);
        SDL_WM_SetCaption(title_buf,"");
        
        #ifdef THREE_DS
        int fps_i = (int)fps;
        if (fps_i > 35) {
            show_fps(fps);
            forgiveness_frame = 1;
        } else if (forgiveness_frame) { // Benefit of the doubt
            forgiveness_frame = 0;
        } else { // Beyond the forgiveness threshold, framerate is low
            show_fps(fps);
        }

        show_battery();
        show_fps_limiter();
        #endif
    }
    last_ticks = current_ticks;
#endif
}
Beispiel #6
0
static void init(void) {
	window = window_create();
	window_stack_push(window, true);
	window_set_background_color(window, GColorBlack);
	Layer *root_layer = window_get_root_layer(window);
	GRect frame = layer_get_frame(root_layer);

	// Init fonts and images
	font			=	fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_16));
	font_tiny		=	fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_10));
	battery_outline	=	gbitmap_create_with_resource(RESOURCE_ID_BATTERY_OUTLINE);
	battery_charge	=	gbitmap_create_with_resource(RESOURCE_ID_BATTERY_CHARGE);

	// Init layer for display
	display_layer = layer_create(frame);
	layer_set_update_proc(display_layer, &display_layer_update_callback);
	layer_add_child(root_layer, display_layer);

	// Init layer for text
	date_layer = text_layer_create(frame);
	layer_set_frame(text_layer_get_layer(date_layer), GRect(0, 130, 144, 168-130));
	layer_set_bounds(text_layer_get_layer(date_layer), GRect(0, 0, 144, 168-130));
	text_layer_set_text_alignment(date_layer, GTextAlignmentCenter);
	text_layer_set_font(date_layer, font);
	layer_add_child(root_layer, text_layer_get_layer(date_layer));

	// Init layer for battery image
	battery_layer = bitmap_layer_create(frame);
	bitmap_layer_set_background_color(battery_layer, GColorClear);
	layer_set_frame(bitmap_layer_get_layer(battery_layer), GRect(4, 134, 30, 20));
	layer_set_bounds(bitmap_layer_get_layer(battery_layer), GRect(0, 0, 30, 20));
	bitmap_layer_set_bitmap(battery_layer, battery_outline);
	layer_add_child(root_layer, bitmap_layer_get_layer(battery_layer));

	// Init layer for charge image
	charge_layer = bitmap_layer_create(frame);
	bitmap_layer_set_background_color(charge_layer, GColorClear);
	layer_set_frame(bitmap_layer_get_layer(charge_layer), GRect(8, 136, 20, 16));
	layer_set_bounds(bitmap_layer_get_layer(charge_layer), GRect(0, 0, 20, 16));
	bitmap_layer_set_bitmap(charge_layer, battery_charge);
	layer_add_child(root_layer, bitmap_layer_get_layer(charge_layer));

	// Init battery fill layer
	battfill_layer = inverter_layer_create(frame);
	layer_set_frame(inverter_layer_get_layer(battfill_layer), GRect(8, 136, 0, 16));
	layer_add_child(root_layer, inverter_layer_get_layer(battfill_layer));

	// Init layer for battery percentage
	percent_layer = text_layer_create(frame);
	layer_set_frame(text_layer_get_layer(percent_layer), GRect(4, 154, 30, 14));
	layer_set_bounds(text_layer_get_layer(percent_layer), GRect(0, 0, 30, 14));
	text_layer_set_text_alignment(percent_layer, GTextAlignmentCenter);
	text_layer_set_font(percent_layer, font_tiny);
	layer_add_child(root_layer, text_layer_get_layer(percent_layer));

	battery_state_service_subscribe(set_battery);
	set_battery(battery_state_service_peek());
	show_battery();

	tick_timer_service_subscribe(SECOND_UNIT, &handle_second_tick);
}