void handle_deinit(void) { app_timer_cancel(g_timer); APP_LOG(APP_LOG_LEVEL_DEBUG, "SHUTDOWN:"); APP_LOG(APP_LOG_LEVEL_DEBUG, " pre: %u bytes used", (unsigned) heap_bytes_used()); free(g_holomesh); APP_LOG(APP_LOG_LEVEL_DEBUG, " holomesh cleaned up: %u bytes remaining", (unsigned) heap_bytes_used()); gbitmap_destroy(frameBufferBitmap); gbitmap_destroy(logoBitmap); APP_LOG(APP_LOG_LEVEL_DEBUG, " bitmaps cleaned up: %u bytes remaining", (unsigned) heap_bytes_used()); fonts_unload_custom_font(g_font_sw_symbol); fonts_unload_custom_font(g_font_sw); APP_LOG(APP_LOG_LEVEL_DEBUG, " fonts cleaned up: %u bytes remaining", (unsigned) heap_bytes_used()); text_layer_destroy(timeLayer); text_layer_destroy(dateLayer); text_layer_destroy(textLayer); text_layer_destroy(textLayerSym); text_layer_destroy(infoTextLayer); bitmap_layer_destroy(frameBufferLayer); bitmap_layer_destroy(logoLayer); APP_LOG(APP_LOG_LEVEL_DEBUG, " layers cleaned up: %u bytes remaining", (unsigned) heap_bytes_used()); window_destroy(my_window); APP_LOG(APP_LOG_LEVEL_DEBUG, "FINAL SHUTDOWN: %u bytes used", (unsigned) heap_bytes_used()); }
static void update_time(struct tm *tick_time, bool first_update) { int hour = tick_time->tm_hour; int minute = tick_time->tm_min; APP_LOG(APP_LOG_LEVEL_DEBUG, "update_time(%d:%d)", (int)hour, (int)minute); APP_LOG(APP_LOG_LEVEL_DEBUG, "MEMORY USAGE = %d bytes", (int)heap_bytes_used()); int formatted_hour = clock_is_24h_style() ? hour : hour % 12; update_layer_digit(layout.hour_tens, formatted_hour / 10, first_update); update_layer_digit(layout.hour_ones, formatted_hour % 10, first_update); update_layer_digit(layout.minute_tens, minute / 10, first_update); update_layer_digit(layout.minute_ones, minute % 10, first_update); }
void display_pinteract_dots_history(int16_t history_pi_code_in){ APP_LOG(APP_LOG_LEVEL_ERROR, "window start : heap size: used %d , free %d", heap_bytes_used(), heap_bytes_free()); history_pi_code = history_pi_code_in; day_offset = 1; // WHENEVER we access the main dash, we just want to clean everything up // window_stack_pop_all(false); // psleep(100); // NEEDED so OS clears prev window and frees RAM // get the points goal from the config file s_dots_history_window = window_create(); window_set_window_handlers(s_dots_history_window, (WindowHandlers){ .load = window_load, .unload = window_unload });
static void window_unload(Window* window){ // we sure to destroy the moving graphics!!! // Destroy all the graphics layer_destroy(s_dots_layer); text_layer_destroy(s_title_layer); // text_layer_destroy(s_dates_layer); // text_layer_destroy(s_day_layer); text_layer_destroy(s_axis_y_label_layer); for(int16_t i = 0; i < 7; i++){ text_layer_destroy(s_wday_layers[i]); } APP_LOG(APP_LOG_LEVEL_ERROR, "window unload : heap size: used %d , free %d", heap_bytes_used(), heap_bytes_free()); // psleep(100); }
static void window_load(Window* window){ // NOTE!!, we are essentially trying to immitate Misfit and jawbone, // so white text on black background Layer* window_layer = window_get_root_layer(window); GRect window_bounds = layer_get_bounds(window_layer); window_set_background_color(window, GColorBlack); time_t init_t = time(NULL); // run the tick handler once to update everything struct tm *tick_time = localtime( &init_t ); num_bars = 7; axis_x = window_bounds.size.w -1; bar_w = ((window_bounds.size.w*23/24 )/num_bars); // pinteract 11 & 1 mid_y = window_bounds.size.h/2 + 5; step_h = (window_bounds.size.h*10/12)/5; // add title layer s_title_layer = text_layer_create(GRect(5,1,window_bounds.size.w-5,21)); text_layer_set_text_alignment(s_title_layer, GTextAlignmentLeft); text_layer_set_font(s_title_layer,fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); text_layer_set_background_color(s_title_layer, GColorBlack); text_layer_set_text_color(s_title_layer, GColorWhite); layer_add_child(window_layer, text_layer_get_layer(s_title_layer)); // add the y axis label s_axis_y_label_layer = text_layer_create(GRect(axis_x-41,mid_y-21,40,21)); text_layer_set_text_alignment(s_axis_y_label_layer, GTextAlignmentRight); text_layer_set_font(s_axis_y_label_layer,fonts_get_system_font(FONT_KEY_GOTHIC_18)); text_layer_set_background_color(s_axis_y_label_layer, GColorBlack); text_layer_set_text_color(s_axis_y_label_layer, GColorWhite); layer_add_child(window_layer, text_layer_get_layer(s_axis_y_label_layer)); set_title_dates_y_axis_label(); char* weekday[7]; weekday[0] = "Su"; weekday[1] = "Mo"; weekday[2] = "Tu"; weekday[3] = "We"; weekday[4] = "Th"; weekday[5] = "Fr"; weekday[6] = "Sa"; for(int8_t i = 0; i < num_bars; i++){ s_wday_layers[i] = text_layer_create(GRect( (num_bars-1-i)*bar_w + 5 , window_bounds.size.h-18,20,18) ); text_layer_set_text_alignment(s_wday_layers[i], GTextAlignmentCenter); text_layer_set_font(s_wday_layers[i],fonts_get_system_font(FONT_KEY_GOTHIC_18)); text_layer_set_background_color(s_wday_layers[i], GColorBlack); text_layer_set_text_color(s_wday_layers[i], GColorWhite); text_layer_set_text(s_wday_layers[i], weekday[ (tick_time->tm_wday -i -1+7)%7 ]); layer_add_child(window_layer, text_layer_get_layer(s_wday_layers[i])); } // ADD THE MOVING GRAPHICS MUST BE AT TOP OF LAYER STACK s_dots_layer = layer_create(window_bounds); layer_set_update_proc(s_dots_layer, dots_layer_update_proc); // layer_set_background_color(s_points_layer, GColorBlack); layer_add_child(window_layer, s_dots_layer); layer_mark_dirty(s_dots_layer); APP_LOG(APP_LOG_LEVEL_ERROR, "window load : heap size: used %d , free %d", heap_bytes_used(), heap_bytes_free()); }
//Hippo Command, I put my pants on backwards! void handle_init(void) { APP_LOG(APP_LOG_LEVEL_DEBUG, "INIT MEMORY: %u bytes used, %u bytes free", (unsigned) heap_bytes_used(), (unsigned) heap_bytes_free()); // TODO: restore this once done profiling #ifndef LOCK_SHIP srand(time(NULL)); load_holomesh(rand() % c_craft_info_count); #else load_holomesh(LOCK_SHIP); #endif APP_LOG(APP_LOG_LEVEL_DEBUG, "UI MEMORY: %u bytes used, %u bytes free", (unsigned) heap_bytes_used(), (unsigned) heap_bytes_free()); my_window = window_create(); window_set_background_color(my_window, GColorBlack); GRect logoRect = GRect(0, 12, c_viewportWidth, c_viewportWidth); logoLayer = bitmap_layer_create(logoRect); bitmap_layer_set_bitmap(logoLayer, logoBitmap); layer_add_child(window_get_root_layer(my_window), bitmap_layer_get_layer(logoLayer)); // Fonts g_font_sw = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_14)); g_font_sw_symbol = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_SYMBOL_14)); g_font_time = fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD); g_font_info = fonts_get_system_font(FONT_KEY_GOTHIC_14); // Paint layer frameBufferLayer = bitmap_layer_create(GRect(0, 0, c_viewportWidth, c_viewportHeight)); layer_add_child(window_get_root_layer(my_window), bitmap_layer_get_layer(frameBufferLayer)); frameBufferBitmap = gbitmap_create_blank_with_palette( GSize(c_viewportWidth, c_viewportHeight), GBitmapFormat2BitPalette, c_palette, false); bitmap_layer_set_bitmap(frameBufferLayer, frameBufferBitmap); bitmap_layer_set_compositing_mode(frameBufferLayer, GCompOpSet); paint(); GRect layerSize = GRect(0, 0, c_viewportWidth, c_viewportHeight); // Two small text layers textLayer = text_layer_create(layerSize); text_layer_set_background_color(textLayer, GColorClear); text_layer_set_text_color(textLayer, GColorYellow); text_layer_set_font(textLayer, g_font_sw); layer_add_child(window_get_root_layer(my_window), text_layer_get_layer(textLayer)); //Jet Force Push-up, you silly-billy. textLayerSym = text_layer_create(layerSize); text_layer_set_background_color(textLayerSym, GColorClear); text_layer_set_text_color(textLayerSym, GColorYellow); text_layer_set_font(textLayerSym, g_font_sw_symbol); layer_set_hidden(text_layer_get_layer(textLayerSym), true); layer_add_child(window_get_root_layer(my_window), text_layer_get_layer(textLayerSym)); //Hippo Command, I also put my watch on backwards! // Info text layer infoTextLayer = text_layer_create(layerSize); text_layer_set_background_color(infoTextLayer, GColorClear); text_layer_set_text_color(infoTextLayer, GColorYellow); text_layer_set_font(infoTextLayer, g_font_info); layer_add_child(window_get_root_layer(my_window), text_layer_get_layer(infoTextLayer)); // Time GSize timeSize = graphics_text_layout_get_content_size( "00:00 AM", g_font_time, layerSize, 0, GTextAlignmentLeft); GRect timeRect = { GPoint(DT_EDGE_PAD, c_viewportHeight - timeSize.h), GSize(c_viewportWidth, timeSize.h) }; timeLayer = text_layer_create(timeRect); text_layer_set_background_color(timeLayer, GColorClear); text_layer_set_text_color(timeLayer, GColorYellow); text_layer_set_font(timeLayer, g_font_time); //text_layer_set_text(timeLayer, "23:45 AM"); layer_add_child(window_get_root_layer(my_window), text_layer_get_layer(timeLayer)); // Date dateLayer = text_layer_create(layerSize); text_layer_set_background_color(dateLayer, GColorClear); text_layer_set_text_color(dateLayer, GColorYellow); text_layer_set_font(dateLayer, g_font_info); layer_add_child(window_get_root_layer(my_window), text_layer_get_layer(dateLayer)); time_t t = time(NULL); update_time_display(localtime(&t)); update_date_display(localtime(&t)); update_title_and_info(); APP_LOG(APP_LOG_LEVEL_DEBUG, "FINAL MEMORY: %u bytes used, %u bytes free", (unsigned) heap_bytes_used(), (unsigned) heap_bytes_free()); window_stack_push(my_window, true); tick_timer_service_subscribe(SECOND_UNIT | MINUTE_UNIT, tick_handler); g_timer = app_timer_register(c_refreshTimer, animation_timer_trigger, NULL); accel_data_service_subscribe(c_accelSampleCount, accel_data_handler); accel_service_set_sampling_rate(ACCEL_SAMPLING_25HZ); }