void set_status(int new_status_display) { status_display = new_status_display; layer_mark_dirty(&status_layer); }
static void down_click_handler(ClickRecognizerRef recognizer, void *context) { if (++current_gcompop >= num_gcompops) { current_gcompop = 0; } layer_mark_dirty(layer); }
static void down_click_handler(ClickRecognizerRef recognizer, void *context) { stats_display = true; layer_mark_dirty(window_get_root_layer(window)); }
static void set_title_dates_y_axis_label(){ switch(history_pi_code){ case 1: text_layer_set_text(s_title_layer, "Steps"); text_layer_set_text(s_axis_y_label_layer, "Goal"); max_steps = 0; // min_kcal = 100000; for(int16_t i = 0; i < num_bars; i++ ){ uint16_t comp_steps = get_daily_acti().steps[i+day_offset]; int32_t steps = comp_steps*comp_steps; APP_LOG(APP_LOG_LEVEL_ERROR, "steps1: %d",(int) steps); if(steps > max_steps){max_steps = steps;} } // max_steps = (max_steps/100)*100; // round to nearest hundred APP_LOG(APP_LOG_LEVEL_ERROR, "max_steps: %d",(int) max_steps); if(((max_steps*5)/6) < get_config_general().pts_goal ){ APP_LOG(APP_LOG_LEVEL_ERROR, "<"); steps_goal_line_y = mid_y - step_h*1; }else{ APP_LOG(APP_LOG_LEVEL_ERROR, ">"); steps_goal_line_y = mid_y + 2*step_h - ((4*step_h*get_config_general().pts_goal)/max_steps); } APP_LOG(APP_LOG_LEVEL_ERROR, "steps_goal_line_y: %d",(int) steps_goal_line_y); layer_set_frame((Layer *)s_axis_y_label_layer, GRect(axis_x-52,steps_goal_line_y-23,50,21)); break; #ifdef PBL_COLOR case 2: text_layer_set_text(s_title_layer, "Activity Calories"); max_kcal = 0; // min_kcal = 100000; for(int16_t i = 0; i < num_bars; i++ ){ int8_t comp_kcal = get_daily_acti().kcal[i+day_offset]; int32_t kcal = comp_kcal*comp_kcal; if(kcal > max_kcal){max_kcal = kcal;} // if(kcal < min_kcal){min_kcal = kcal;} } max_kcal = ((max_kcal/100) +1)*100; // add max kcal layer static char kcal_buf[6]; snprintf(kcal_buf,sizeof(kcal_buf),"%d",(int)max_kcal); text_layer_set_text(s_axis_y_label_layer, kcal_buf); layer_set_frame((Layer *)s_axis_y_label_layer, GRect(axis_x-52,20,50,21)); break; case 11: text_layer_set_text(s_title_layer, "Mood"); text_layer_set_text(s_axis_y_label_layer, ""); layer_set_frame((Layer *)s_axis_y_label_layer, GRect(axis_x-52,mid_y-23,50,21)); break; case 140: max_sleep_min = 0; int16_t avg_sleep_min = 0; int16_t num_non_zero_sleep_min = 0; // min_kcal = 100000; for(int16_t i = 0; i < num_bars; i++ ){ int16_t sleep_min = get_pinteract_state().pi_140[i+day_offset]; if(sleep_min > 0){ avg_sleep_min += sleep_min; num_non_zero_sleep_min += 1; } if(sleep_min > max_sleep_min){max_sleep_min = sleep_min;} // if(kcal < min_kcal){min_kcal = kcal;} } max_sleep_min = (max_sleep_min/60 +1)*60; avg_sleep_min /= num_non_zero_sleep_min; static char sleep_title_buf[20]; snprintf(sleep_title_buf,sizeof(sleep_title_buf),"Average Sleep %d:%.2d", (int)(avg_sleep_min/60), (int)(avg_sleep_min%60) ); text_layer_set_text(s_title_layer, sleep_title_buf); static char sleep_min_buf[6]; snprintf(sleep_min_buf,sizeof(sleep_min_buf),"%d hrs",(int)(max_sleep_min/60)); layer_set_frame((Layer *)s_axis_y_label_layer, GRect(axis_x-52,20,50,21)); text_layer_set_text(s_axis_y_label_layer, sleep_min_buf); break; case 141: text_layer_set_text(s_title_layer, "Sleep Quality"); text_layer_set_text(s_axis_y_label_layer, ""); layer_set_frame((Layer *)s_axis_y_label_layer, GRect(axis_x-52,mid_y-23,50,21)); break; #endif } layer_mark_dirty((Layer *)s_axis_y_label_layer); layer_mark_dirty((Layer *)s_title_layer); }
void qr_layer_set_data(QRLayer* layer, char* data) { QRData* qr_data = (QRData*) layer_get_data(layer); qr_data->width = EncodeData(QR_LEVEL_L, 0, data, 0, qr_data->str); layer_mark_dirty(qr_layer_get_layer(layer)); }
void action_bar_layer_set_background_color(ActionBarLayer *action_bar, GColor background_color) { action_bar->background_color=background_color; layer_mark_dirty ((Layer*)action_bar); }
static void handle_init() { SlidingTextData *data = (SlidingTextData*)malloc(sizeof(SlidingTextData)); s_data = data; data->render_state.next_hours = 0; data->render_state.next_minutes = 0; data->render_state.demo_time.secs = 0; data->render_state.demo_time.mins = 0; data->render_state.demo_time.hour = 0; data->s_main_window = window_create(); window_set_background_color(data->s_main_window, GColorWhite); data->helvetica30_bold = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_HELVETICA_BOLD_30)); data->helvetica20_light = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_HELVETICA_LIGHT_20)); Layer *s_window_layer = window_get_root_layer(data->s_main_window); GRect layer_frame = layer_get_frame(s_window_layer); const int16_t width = layer_frame.size.w; //////// if (persist_read_int(KEY_SKIN_SELECT)) { skin_select = persist_read_int(KEY_SKIN_SELECT); if (skin_select == 100) activeSkin = RESOURCE_ID_CHARLIEBROWN_COLOR_IMAGE; if (skin_select == 101) activeSkin = RESOURCE_ID_FLASHY_COLOR_IMAGE; if (skin_select == 102) activeSkin = RESOURCE_ID_SQUIGGLE_COLOR_IMAGE; if (skin_select == 103) activeSkin = RESOURCE_ID_ZEBRA_COLOR_IMAGE; if (skin_select == 104) activeSkin = RESOURCE_ID_SUPERBOX_COLOR_IMAGE; if (skin_select == 105) activeSkin = RESOURCE_ID_LEOPARD_COLOR_IMAGE; } s_squiggle_bitmap = gbitmap_create_with_resource(activeSkin); s_bitmap_layer = bitmap_layer_create(layer_frame); bitmap_layer_set_bitmap(s_bitmap_layer, s_squiggle_bitmap); layer_add_child(s_window_layer, bitmap_layer_get_layer(s_bitmap_layer)); s_path1 = gpath_create(&PATH_INFO1); s_path1_layer = layer_create(layer_frame); layer_set_update_proc(s_path1_layer, layer1_update_proc); layer_add_child(s_window_layer, s_path1_layer); s_path2 = gpath_create(&PATH_INFO2); s_path2_layer = layer_create(layer_frame); layer_set_update_proc(s_path2_layer, layer2_update_proc); layer_add_child(s_window_layer, s_path2_layer); //////// init_sliding_row(data, &data->rows[1], GRect(8, 135, width, 30), data->helvetica20_light, 3); layer_add_child(s_window_layer, text_layer_get_layer(data->rows[1].label)); init_sliding_row(data, &data->rows[0], GRect(8, 100, width, 40), data->helvetica30_bold, 6); layer_add_child(s_window_layer, text_layer_get_layer(data->rows[0].label)); init_sliding_row(data, &data->rows[2], GRect(8, 170, width, 0), data->helvetica20_light, 0); layer_add_child(s_window_layer, text_layer_get_layer(data->rows[2].label)); GFont norm14 = fonts_get_system_font(FONT_KEY_GOTHIC_14); data->demo_label = text_layer_create(GRect(0, -3, 100, 20)); text_layer_set_background_color(data->demo_label, GColorWhite); text_layer_set_text_color(data->demo_label, GColorBlack); text_layer_set_font(data->demo_label, norm14); text_layer_set_text(data->demo_label, "demo mode"); layer_add_child(s_window_layer, text_layer_get_layer(data->demo_label)); layer_set_hidden(text_layer_get_layer(data->demo_label), true); layer_mark_dirty(s_window_layer); make_animation(); tick_timer_service_subscribe(MINUTE_UNIT, handle_minute_tick); const bool animated = true; window_stack_push(data->s_main_window, animated); //////// app_message_register_inbox_received(inbox_received_handler); app_message_open(app_message_inbox_size_maximum(), app_message_outbox_size_maximum()); }
void communication_in_received_callback(DictionaryIterator *iter, void *context) { Tuple *tuple = dict_read_first(iter); #define SIZE_OF_A_FRIEND 9 //char friend[100]; //int8_t live_max_name = -1; uint16_t time0; int16_t xpos = 0, ypos = 0; while (tuple) { switch (tuple->key) { case MSG_LIVE_NAME0: //vibes_short_pulse(); strncpy(s_live.friends[0].name, tuple->value->cstring, 10); break; case MSG_LIVE_NAME1: strncpy(s_live.friends[1].name, tuple->value->cstring, 10); break; case MSG_LIVE_NAME2: strncpy(s_live.friends[2].name, tuple->value->cstring, 10); break; case MSG_LIVE_NAME3: strncpy(s_live.friends[3].name, tuple->value->cstring, 10); break; case MSG_LIVE_NAME4: strncpy(s_live.friends[4].name, tuple->value->cstring, 10); break; case MSG_LIVE_SHORT: nb_tuple_live++; //strcpy(s_data.friends, ""); s_live.nb = tuple->value->data[0]; if (s_live.nb > NUM_LIVE_FRIENDS) { s_live.nb = NUM_LIVE_FRIENDS; } for (int i = 0; i < s_live.nb; i++) { /*if (strcmp(s_live.friends[i].name, "") != 0) { // we already know the name live_max_name = i; }*/ if (tuple->value->data[1 + i * SIZE_OF_A_FRIEND + 1] >= 128) { s_live.friends[i].xpos = -1 * (tuple->value->data[1 + i * SIZE_OF_A_FRIEND + 0] + 256 * (tuple->value->data[1 + i * SIZE_OF_A_FRIEND + 1] - 128)); } else { s_live.friends[i].xpos = tuple->value->data[1 + i * SIZE_OF_A_FRIEND + 0] + 256 * tuple->value->data[1 + i * SIZE_OF_A_FRIEND + 1]; } if (tuple->value->data[1 + i * SIZE_OF_A_FRIEND + 3] >= 128) { s_live.friends[i].ypos = -1 * (tuple->value->data[1 + i * SIZE_OF_A_FRIEND + 2] + 256 * (tuple->value->data[1 + i * SIZE_OF_A_FRIEND + 3] - 128)); } else { s_live.friends[i].ypos = tuple->value->data[1 + i * SIZE_OF_A_FRIEND + 2] + 256 * tuple->value->data[1 + i * SIZE_OF_A_FRIEND + 3]; } s_live.friends[i].distance = (tuple->value->data[1 + i * SIZE_OF_A_FRIEND + 4] + 256 * tuple->value->data[1 + i * SIZE_OF_A_FRIEND + 5]) * 10; // in m s_live.friends[i].bearing = 360 * tuple->value->data[1 + i * SIZE_OF_A_FRIEND + 6] / 256; s_live.friends[i].lastviewed = tuple->value->data[1 + i * SIZE_OF_A_FRIEND + 7] + 256 * tuple->value->data[1 + i * SIZE_OF_A_FRIEND + 8]; // in seconds /* if (i < 3) { snprintf(friend, sizeof(friend), "%d/%d %s %.0f(m)\n" //"%d|%d\n" "b:%u lv:%d(s)\n", i, s_live.nb, s_live.friends[i].name, s_live.friends[i].distance, //s_live.friends[i].xpos, s_live.friends[i].ypos, s_live.friends[i].bearing, s_live.friends[i].lastviewed ); strcat(s_data.friends, friend); } */ } screen_live_menu_update(); if (s_data.page_number == PAGE_MAP) { layer_mark_dirty(s_data.page_map); } //if (live_max_name != s_live.nb) { // send_ask_name(live_max_name); //} break; case MSG_LOCATION_DATA: case MSG_LOCATION_DATA_V2: case MSG_LOCATION_DATA_V3: nb_tuple_altitude++; if (tuple->key == MSG_LOCATION_DATA) { //APP_LOG(APP_LOG_LEVEL_DEBUG, "MSG_LOCATION_DATA"); change_units((tuple->value->data[0] & 0b00000001) >> 0, false); change_state((tuple->value->data[0] & 0b00000010) >> 1); s_data.debug = (tuple->value->data[0] & 0b00000100) >> 2; s_data.live = (tuple->value->data[0] & 0b00001000) >> 3; s_data.refresh_code = (tuple->value->data[0] & 0b00110000) >> 4; } if (tuple->key >= MSG_LOCATION_DATA_V2) { //APP_LOG(APP_LOG_LEVEL_DEBUG, "MSG_LOCATION_DATA_v2"); change_units((tuple->value->data[0] & 0b00000111) >> 0, false); change_state((tuple->value->data[0] & 0b00001000) >> 3); s_data.debug = (tuple->value->data[0] & 0b00010000) >> 4; s_data.live = (tuple->value->data[0] & 0b00100000) >> 5; s_data.refresh_code = (tuple->value->data[0] & 0b11000000) >> 6; } // if (tuple->key == MSG_LOCATION_DATA_V2) { // APP_LOG(APP_LOG_LEVEL_DEBUG, "MSG_LOCATION_DATA_v2"); // } // if (tuple->key == MSG_LOCATION_DATA_V3) { // APP_LOG(APP_LOG_LEVEL_DEBUG, "MSG_LOCATION_DATA_v3"); // } s_gpsdata.accuracy = tuple->value->data[1]; s_gpsdata.distance100 = (tuple->value->data[2] + 256 * tuple->value->data[3]); // in 0.01km or 0.01miles time0 = s_gpsdata.time; s_gpsdata.time = tuple->value->data[BYTE_TIME1] + 256 * tuple->value->data[BYTE_TIME2]; if (s_gpsdata.time != 0) { if (s_gpsdata.units == UNITS_RUNNING_IMPERIAL || s_gpsdata.units == UNITS_RUNNING_METRIC) { // pace: min per mile_or_km if (s_gpsdata.distance100 > 0) { s_gpsdata.avgspeed100 = 100 * 100 / 60 * s_gpsdata.time / s_gpsdata.distance100; // min per mile_or_km } else { s_gpsdata.avgspeed100 = 0; } } else { s_gpsdata.avgspeed100 = 3600 * s_gpsdata.distance100 / s_gpsdata.time; // 0.01km/h or 0.01mph } } else { s_gpsdata.avgspeed100 = 0; } //APP_LOG(APP_LOG_LEVEL_DEBUG, "dist=%ld, time=%d, avg=%ld", s_gpsdata.distance100, s_gpsdata.time, s_gpsdata.avgspeed100); s_gpsdata.speed100 = ((tuple->value->data[BYTE_SPEED1] + 256 * tuple->value->data[BYTE_SPEED2])) * 10; s_gpsdata.maxspeed100 = ((tuple->value->data[BYTE_MAXSPEED1] + 256 * tuple->value->data[BYTE_MAXSPEED2])) * 10; s_gpsdata.altitude = tuple->value->data[6] + 256 * tuple->value->data[7]; if (tuple->value->data[9] >= 128) { s_gpsdata.ascent = -1 * (tuple->value->data[8] + 256 * (tuple->value->data[9] - 128)); } else { s_gpsdata.ascent = tuple->value->data[8] + 256 * tuple->value->data[9]; } if (tuple->value->data[11] >= 128) { s_gpsdata.ascentrate = -1 * (tuple->value->data[10] + 256 * (tuple->value->data[11] - 128)); } else { s_gpsdata.ascentrate = tuple->value->data[10] + 256 * tuple->value->data[11]; } if (tuple->value->data[BYTE_SLOPE] >= 128) { s_gpsdata.slope = -1 * (tuple->value->data[BYTE_SLOPE] - 128); } else { s_gpsdata.slope = tuple->value->data[BYTE_SLOPE]; } if (tuple->value->data[14] >= 128) { xpos = -1 * (tuple->value->data[13] + 256 * (tuple->value->data[14] - 128)); } else { xpos = tuple->value->data[13] + 256 * tuple->value->data[14]; } if (tuple->value->data[16] >= 128) { ypos = -1 * (tuple->value->data[15] + 256 * (tuple->value->data[16] - 128)); } else { ypos = tuple->value->data[15] + 256 * tuple->value->data[16]; } if ((xpos == 0 && ypos == 0) || (time0 > s_gpsdata.time)) { // ignore old values (can happen if gps is stopped/restarted) #if DEBUG if (s_data.debug) { APP_LOG(APP_LOG_LEVEL_DEBUG, "==> time0=%d t=%d xpos=%d ypos=%d", time0, s_gpsdata.time, xpos, ypos); //vibes_short_pulse(); } #endif xpos = s_gpsdata.xpos; ypos = s_gpsdata.ypos; } s_gpsdata.xpos = xpos; s_gpsdata.ypos = ypos; s_gpsdata.bearing = 360 * tuple->value->data[BYTE_BEARING] / 256; s_gpsdata.heartrate = tuple->value->data[BYTE_HEARTRATE]; if (tuple->key >= MSG_LOCATION_DATA_V3) { s_gpsdata.cadence = tuple->value->data[BYTE_CADENCE]; } else { s_gpsdata.cadence = tuple->value->data[BYTE_HEARTRATE]; // no specific field until MSG_LOCATION_DATA_V3 } snprintf(s_data.accuracy, sizeof(s_data.accuracy), "%d", s_gpsdata.accuracy); snprintf(s_data.distance, sizeof(s_data.distance), "%ld.%ld", s_gpsdata.distance100 / 100, s_gpsdata.distance100 % 100 / 10); copy_speed(s_data.avgspeed, sizeof(s_data.avgspeed), s_gpsdata.avgspeed100); snprintf(s_data.altitude, sizeof(s_data.altitude), "%u", s_gpsdata.altitude); snprintf(s_data.ascent, sizeof(s_data.ascent), "%d", s_gpsdata.ascent); snprintf(s_data.ascentrate, sizeof(s_data.ascentrate), "%d", s_gpsdata.ascentrate); snprintf(s_data.slope, sizeof(s_data.slope), "%d", s_gpsdata.slope); snprintf(s_data.bearing, sizeof(s_data.bearing), "%d", s_gpsdata.bearing); if (s_gpsdata.heartrate != 255) { snprintf(s_data.heartrate, sizeof(s_data.heartrate), "%d", s_gpsdata.heartrate); } else { strcpy(s_data.heartrate, "-"); } if (s_gpsdata.cadence != 255) { snprintf(s_data.cadence, sizeof(s_data.cadence), "%d", s_gpsdata.cadence); } else { strcpy(s_data.cadence, "-"); } if (s_gpsdata.time / 3600 > 0) { snprintf(s_data.elapsedtime,sizeof(s_data.elapsedtime),"%d:%.2d:%.2d", s_gpsdata.time / 3600, (s_gpsdata.time / 60) % 60, s_gpsdata.time % 60); } else { snprintf(s_data.elapsedtime,sizeof(s_data.elapsedtime),"%d:%.2d", (s_gpsdata.time / 60) % 60, s_gpsdata.time % 60); } //APP_LOG(APP_LOG_LEVEL_DEBUG, "t:%d => %s", s_gpsdata.time, s_data.elapsedtime); screen_speed_show_speed(false); // reset data (instant speed...) after X if no data is received if (reset_data_timer) { //APP_LOG(APP_LOG_LEVEL_DEBUG, "app_timer_cancel()"); app_timer_cancel(reset_data_timer); } // s_data.refresh_code == 3 => _refresh_interval [5;+inf reset_data_timer = app_timer_register(s_data.refresh_code == 3 ? 60000 : 20000, reset_data_timer_callback, NULL); #if DEBUG ftoa(s_gpsdata.distance, tmp, 10, 1); snprintf(s_data.debug1, sizeof(s_data.debug1), "#%d us:%d|%d A:%u\n" "alt:%u asc:%d\n" "pos:%d|%d #%u\n" //"%d|%d|%d\n" "s:%d b:%u\n" "D:%s km T:%u\n" "%d avg:%d\n", s_gpsdata.nb_received++, s_gpsdata.units, s_data.state, s_gpsdata.accuracy, s_gpsdata.altitude, s_gpsdata.ascent, //s_gpsdata.ascentrate, s_gpsdata.slope, s_gpsdata.xpos, s_gpsdata.ypos, nb_points, //s_data.debug, s_data.live, s_data.refresh_code, map_scale,s_gpsdata.bearing, tmp, s_gpsdata.time, (int) s_gpsdata.speed, (int) s_gpsdata.avgspeed ); #endif screen_map_update_location(); if (s_data.page_number == PAGE_SPEED || s_data.page_number == PAGE_HEARTRATE) { layer_mark_dirty(s_data.page_speed); } if (s_data.page_number == PAGE_ALTITUDE) { layer_mark_dirty(s_data.page_altitude); } if (s_data.page_number == PAGE_LIVE_TRACKING) { layer_mark_dirty((Layer *) s_data.page_live_tracking); } #if DEBUG if (s_data.page_number == PAGE_DEBUG1) { layer_mark_dirty(s_data.page_debug1); } if (s_data.page_number == PAGE_DEBUG2) { layer_mark_dirty(s_data.page_debug2); } #endif break; case MSG_SENSOR_TEMPERATURE: s_gpsdata.temperature10 = tuple->value->int16; snprintf(s_data.temperature, sizeof(s_data.temperature), "%d.%d", s_gpsdata.temperature10 / 10, s_gpsdata.temperature10 % 10); break; case STATE_CHANGED: nb_tuple_state++; //vibes_short_pulse(); change_state(tuple->value->uint8); break; case MSG_VERSION_ANDROID: //vibes_short_pulse(); s_data.android_version = tuple->value->int32; break; case MSG_BATTERY_LEVEL: //APP_LOG(APP_LOG_LEVEL_DEBUG, "MSG_BATTERY_LEVEL:%ld", tuple->value->int32); s_data.phone_battery_level = tuple->value->int32; break; }
static void tick_handler(struct tm *tick_time, TimeUnits units_changed) { layer_mark_dirty(hand_layer); }
void bluetooth_connection_handler(bool connected){ if(bluetooth_connected != connected){ bluetooth_connected = connected; layer_mark_dirty(layer); } }
void communication_in_dropped_callback(AppMessageResult reason, void *context) { // incoming message dropped #if DEBUG if (reason != APP_MSG_OK) { //vibes_short_pulse(); nb_sync_error_callback++; } //char debug1[16]; char debug2[16]; switch (reason) { case APP_MSG_OK: // All good, operation was successful. strncpy(debug2, "OK", 16); break; case APP_MSG_SEND_TIMEOUT: // The other end did not confirm receiving the sent data with an (n)ack in time. strncpy(debug2, "NOC", 16); break; case APP_MSG_SEND_REJECTED: // The other end rejected the sent data, with a "nack" reply. strncpy(debug2, "NAC", 16); break; case APP_MSG_NOT_CONNECTED: // The other end was not connected. strncpy(debug2, "NCO", 16); break; case APP_MSG_APP_NOT_RUNNING: // The local application was not running. strncpy(debug2, "NOR", 16); break; case APP_MSG_INVALID_ARGS: // The function was called with invalid arguments. strncpy(debug2, "INV", 16); break; case APP_MSG_BUSY: // There are pending (in or outbound) messages that need to be processed first before new ones can be received or sent. strncpy(debug2, "BUS", 16); break; case APP_MSG_BUFFER_OVERFLOW: // The buffer was too small to contain the incoming message. strncpy(debug2, "OVE", 16); break; case APP_MSG_ALREADY_RELEASED: // The resource had already been released. strncpy(debug2, "ALR", 16); break; case APP_MSG_CALLBACK_ALREADY_REGISTERED: // The callback node was already registered, or its ListNode has not been initialized. strncpy(debug2, "AL2", 16); break; case APP_MSG_CALLBACK_NOT_REGISTERED: // The callback could not be deregistered, because it had not been registered before. strncpy(debug2, "NOR", 16); break; case APP_MSG_OUT_OF_MEMORY: // The support library did not have sufficient application memory to perform the requested operation. strncpy(debug2, "OUT", 16); break; case APP_MSG_CLOSED: // App message was closed strncpy(debug2, "CLO", 16); break; case APP_MSG_INTERNAL_ERROR: // An internal OS error prevented APP_MSG from completing an operation. strncpy(debug2, "INT", 16); break; } snprintf(s_data.debug2, sizeof(s_data.debug2), "#%d\napp_msg_err:\n%d - %s\ntpl_live:%d\ntpl_altitude:%d\ntpl_state:%d", nb_sync_error_callback, reason, debug2, nb_tuple_live, nb_tuple_altitude, nb_tuple_state ); layer_mark_dirty(s_data.page_debug2); #endif }
static void hands_update_proc(Layer *layer, GContext *ctx) { time_t now = time(NULL); struct tm *t = localtime(&now); graphics_context_set_stroke_color(ctx, hand_color); #ifdef PBL_COLOR graphics_context_set_antialiased(ctx, false); #endif GRect bounds = layer_get_bounds(layer); GPoint center = grect_center_point(&bounds); //minute hand int16_t hand_length = bounds.size.w / 2 ; int32_t angle = TRIG_MAX_ANGLE * t->tm_min / 60; GPoint hand = { .x = (int16_t)(sin_lookup(angle) * (int32_t)hand_length / TRIG_MAX_RATIO) + center.x, .y = (int16_t)(-cos_lookup(angle) * (int32_t)hand_length / TRIG_MAX_RATIO) + center.y, }; #ifdef PBL_COLOR graphics_context_set_stroke_width(ctx, 3); #endif graphics_draw_line(ctx, hand, center); //hour hand hand_length = hand_length - 25; angle = (TRIG_MAX_ANGLE * (((t->tm_hour % 12) * 6) + (t->tm_min / 10))) / (12 * 6); hand = (GPoint){ .x = (int16_t)(sin_lookup(angle) * (int32_t)hand_length / TRIG_MAX_RATIO) + center.x, .y = (int16_t)(-cos_lookup(angle) * (int32_t)hand_length / TRIG_MAX_RATIO) + center.y, }; #ifdef PBL_COLOR graphics_context_set_stroke_width(ctx, 5); #endif graphics_draw_line(ctx, hand, center); #ifndef PBL_RECT graphics_context_set_fill_color(ctx, hand_color); graphics_fill_circle(ctx, center, 7); #endif } static void handle_second_tick(struct tm *tick_time, TimeUnits units_changed) { #ifndef PBL_COLOR memset(aplite_visited, 0, 168*20); #endif //adjusting shadow direction according to minute hand location if (tick_time->tm_min >= 0 && tick_time->tm_min < 15) { s_effect_offset.offset_x = SHADOW_LENGTH; s_effect_offset.offset_y = SHADOW_LENGTH; } else if (tick_time->tm_min >= 15 && tick_time->tm_min < 30) { s_effect_offset.offset_x = -SHADOW_LENGTH; s_effect_offset.offset_y = SHADOW_LENGTH; } else if (tick_time->tm_min >= 30 && tick_time->tm_min < 45) { s_effect_offset.offset_x = -SHADOW_LENGTH; s_effect_offset.offset_y = -SHADOW_LENGTH; } else { s_effect_offset.offset_x = SHADOW_LENGTH; s_effect_offset.offset_y = -SHADOW_LENGTH; } layer_mark_dirty(window_get_root_layer(window)); } static void window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); s_hands_layer = layer_create(bounds); layer_set_update_proc(s_hands_layer, hands_update_proc); layer_add_child(window_layer, s_hands_layer); //creating shadow layer s_effect_offset = (EffectOffset){ .orig_color = hand_color, .offset_color = shadow_color, .option = 1 // creating array for "visited" pixels and assigning it to shadow effect parameter #ifndef PBL_COLOR , .aplite_visited = aplite_visited #endif }; s_effect_layer = effect_layer_create(bounds); effect_layer_add_effect(s_effect_layer, effect_shadow, &s_effect_offset); effect_layer_add_effect(s_effect_layer, effect_blur, (void*)1); layer_add_child(window_layer, effect_layer_get_layer(s_effect_layer)); } static void window_unload(Window *window) { layer_destroy(s_hands_layer); }
static void app_focus_changed(bool focused) { if (focused) { // on resuming focus - restore background layer_mark_dirty(effect_layer_get_layer(s_effect_layer)); } }
// ------------------------------------------------------------------------ // // Button Functions // ------------------------------------------------------------------------ // void up_single_click_handler(ClickRecognizerRef recognizer, void *context) { // Solve current maze clear_solution(); solve_maze(start_x, start_y); layer_mark_dirty(solution_layer); }
static void handle_battery(BatteryChargeState charge_state) { battery_percent = charge_state.charge_percent; layer_mark_dirty(s_battery_inside_layer); }
static void timer_callback(void *context) { layer_mark_dirty(anim_layer); timer = app_timer_register(timeout_ms, timer_callback, NULL); }
void handle_second_tick(AppContextRef ctx, PebbleTickEvent *t) { (void)t; (void)ctx; // TODO: Pass tick event/PblTime rather than make layer use `get_time()`? layer_mark_dirty(&display_layer); }
// Update the bottom half of the screen: icon and temperature void npr_layer_update(NprData *npr_data) { // We have no npr data yet... don't update until we do if (npr_data->updated == 0) { return; } NprLayerData *nld = layer_get_data(npr_layer); if (npr_animation_timer && animation_timer_enabled) { app_timer_cancel(npr_animation_timer); // this is only needed to stop the error message when cancelling an already cancelled timer... animation_timer_enabled = false; layer_set_hidden(nld->loading_layer, true); } time_t current_time = time(NULL); bool stale = false; // APP_LOG(APP_LOG_LEVEL_DEBUG, "ct:%i wup:%i, stale:%i", // (int)current_time, (int)npr_data->updated, (int)NPR_STALE_TIMEOUT); // Update the npr icon and temperature if (npr_data->error) { // Only update the error icon if the npr data is stale if (stale) { switch (npr_data->error) { case ERROR_NETWORK: //npr_layer_set_icon(NPR_ICON_CLOUD_ERROR); debug_update_message("Network error"); break; case ERROR_DISCONNECTED: case ERROR_PHONE: default: //npr_layer_set_icon(NPR_ICON_PHONE_ERROR); debug_update_message("Phone disco / error"); break; } } } else { layer_set_hidden(bitmap_layer_get_layer(nld->error_icon_layer), true); text_layer_set_text(nld->primary_frequency_layer, npr_data->primary_frequency); text_layer_set_text(nld->primary_call_layer, npr_data->primary_call); //text_layer_set_text(nld->primary_band_layer, npr_data->primary_band); nld->primary_strength = npr_data->primary_strength; layer_mark_dirty(nld->primary_strength_layer); if (npr_data->secondary_available) { text_layer_set_text(nld->secondary_frequency_layer, npr_data->secondary_frequency); text_layer_set_text(nld->secondary_call_layer, npr_data->secondary_call); //text_layer_set_text(nld->secondary_band_layer, npr_data->secondary_band); nld->secondary_strength = npr_data->secondary_strength; layer_mark_dirty(nld->secondary_strength_layer); } text_layer_set_text(nld->primary_program_layer, npr_data->primary_program); text_layer_set_text(nld->secondary_program_layer, npr_data->secondary_program); } }
void update_stop_after( void ) { text_layer_set_text( &stop_after_lay, get_str_for_stop_after() ); layer_mark_dirty( &stop_after_lay.layer ); }
static void in_received_handler(DictionaryIterator *iter, void *context) { autoconfig_in_received_handler(iter, context); layer_set_hidden(inverter_layer_get_layer(inverter_layer),!getInvert()); layer_mark_dirty(window_get_root_layer(window)); handle_battery(battery_state_service_peek()); }
void in_received_handler(DictionaryIterator *iter, void *context) { // incoming message received static char unit_text[9]; static char distance_text[9]; static char bearing_text[9]; static char heading_text[9]; static char speed_text[9]; static char accuracy_text[12]; Tuple *bearing_tuple = dict_find(iter, BEARING_KEY); if (bearing_tuple) { bearing = bearing_tuple->value->int16; snprintf(bearing_text, sizeof(bearing_text), "%d", bearing); text_layer_set_text(bearing_layer, bearing_text); APP_LOG(APP_LOG_LEVEL_DEBUG, "Updated bearing to %d", bearing); layer_mark_dirty(head_layer); } Tuple *unit_tuple = dict_find(iter, UNIT_KEY); if (unit_tuple) { strncpy(unit_text, unit_tuple->value->cstring, sizeof unit_text); APP_LOG(APP_LOG_LEVEL_DEBUG, "Unit: %s", unit_text); text_layer_set_text(unit_layer, unit_text); } Tuple *distance_tuple = dict_find(iter, DISTANCE_KEY); if (distance_tuple) { if ((distance_text[0] != '!') && (distance_tuple->value->cstring[0] == '!')) vibes_double_pulse(); strcpy(distance_text, distance_tuple->value->cstring); if (distance_text[0] == '!') { text_layer_set_text(distance_layer, &distance_text[1]); #ifdef PBL_COLOR text_layer_set_text_color(distance_layer, GColorBlue); text_layer_set_text_color(unit_layer, GColorBlue); #endif } else { text_layer_set_text(distance_layer, distance_text); #ifdef PBL_COLOR text_layer_set_text_color(distance_layer, GColorBlack); text_layer_set_text_color(unit_layer, GColorBlack); #endif } } APP_LOG(APP_LOG_LEVEL_DEBUG, "Distance updated: %s %s", distance_text, unit_text); Tuple *nextcall_tuple = dict_find(iter, NEXTCALL_KEY); if (nextcall_tuple) { nextcall = nextcall_tuple->value->int32; app_timer_reschedule(locationtimer, 1000 * (nextcall + 10)); APP_LOG(APP_LOG_LEVEL_DEBUG,"Next call is %d.", nextcall); } Tuple *speed_tuple = dict_find(iter, SPEED_KEY); if (speed_tuple) { strncpy(speed_text, speed_tuple->value->cstring, sizeof speed_text); text_layer_set_text(speed_layer, speed_text); APP_LOG(APP_LOG_LEVEL_DEBUG,"Speed is %s.", speed_text); } Tuple *accuracy_tuple = dict_find(iter, ACCURACY_KEY); if (accuracy_tuple) { strncpy(accuracy_text, accuracy_tuple->value->cstring, sizeof accuracy_text); text_layer_set_text(accuracy_layer, accuracy_text); APP_LOG(APP_LOG_LEVEL_DEBUG,"Accuracy is %s.", accuracy_text); } Tuple *heading_tuple = dict_find(iter, HEADING_KEY); if (heading_tuple) { heading = heading_tuple->value->int16; if (heading >= 0) { snprintf(heading_text, sizeof(heading_text), "%d", heading); text_layer_set_text(heading_layer, heading_text); if (orientToHeading) { text_layer_set_text(star_layer, "^"); orientation = -TRIG_MAX_ANGLE * heading / 360; } else { text_layer_set_text(star_layer, "*"); } draw_compass_face(); } else /* heading <0 (not valid) */ { text_layer_set_text(heading_layer, ""); if (orientToHeading) text_layer_set_text(star_layer, "?"); else text_layer_set_text(star_layer, ""); } APP_LOG(APP_LOG_LEVEL_DEBUG, "Updated heading to %d", heading); } Tuple *message_tuple = dict_find(iter, MESSAGE_KEY); if (message_tuple && (strlen(message_tuple->value->cstring) > 0)) { if (!hint_layer) { Layer *window_layer = window_get_root_layer(window); hint_layer = text_layer_create(hint_layer_size); text_layer_set_font(hint_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD)); text_layer_set_text_alignment(hint_layer, GTextAlignmentCenter); layer_add_child(window_layer, text_layer_get_layer(hint_layer)); } strncpy(hint_text, message_tuple->value->cstring, sizeof hint_text); text_layer_set_text(hint_layer, hint_text); APP_LOG(APP_LOG_LEVEL_DEBUG, "Got message: %s", hint_text); } for (int menuItemNumber=2; menuItemNumber <= MENU_LENGTH; menuItemNumber++) { Tuple *location_tuple = dict_find(iter, LOCATION_KEY+menuItemNumber-2); APP_LOG(APP_LOG_LEVEL_DEBUG,"Finding location %d.", menuItemNumber); if ((location_tuple) && (strlen(location_tuple->value->cstring) > 0)) { strncpy(locations[menuItemNumber], location_tuple->value->cstring, sizeof locations[0]); last_menu_item = menuItemNumber; APP_LOG(APP_LOG_LEVEL_DEBUG,"Got location %d = %s.", menuItemNumber, locations[menuItemNumber]); } } #ifdef PBL_SDK_3 if (pinID_needs_sending) pin_action_handler(launch_get_args()); #endif }
static void disable_date(void *data) { draw_date=false; layer_mark_dirty(window_get_root_layer(window)); }
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()); }
void temperature_icon_update(TemperatureIcon *aIcon, int32_t aTemperature) { temperature_icon_data *data = temperature_icon_data_get(aIcon); data->mTemperature = aTemperature; layer_mark_dirty(aIcon); }
static void up_click_handler(ClickRecognizerRef recognizer, void *context) { if (--current_gcompop < 0) { current_gcompop = num_gcompops-1; } layer_mark_dirty(layer); }
static void render_bg(Layer* layer, GContext* ctx) { APP_LOG(APP_LOG_LEVEL_DEBUG, "render_bg"); // Set the colors. #ifdef PBL_COLOR graphics_context_set_stroke_color(ctx, GColorDarkGray); graphics_context_set_fill_color(ctx, mDarkColor); graphics_context_set_text_color(ctx, mLightColor); // Draw the dithered background. if (mDarkColor.r == 0 && mDarkColor.g == 0 && mDarkColor.b == 0) { draw_dithered_rect(ctx, bgRect, mLightColor, GColorBlack, DITHER_75_PERCENT); } else { draw_dithered_rect(ctx, bgRect, mDarkColor, GColorBlack, DITHER_75_PERCENT); } #else graphics_context_set_stroke_color(ctx, mTextColor); graphics_context_set_fill_color(ctx, mTextColor); graphics_context_set_text_color(ctx, mTextColor); #endif // PBL_COLOR // Draw all visible bars APP_LOG(APP_LOG_LEVEL_DEBUG, "render_bg: draw bars"); for (int i = 0; i < BAR_NUM; i++) { GRect barRect = GRect(mBlocks[i]->x, mBlocks[i]->y, mBlocks[i]->width, mBlocks[i]->height); if (mBlocks[i]->visible == true) { #ifdef PBL_COLOR graphics_context_set_fill_color(ctx, mLightColor); graphics_fill_rect(ctx, barRect, 0, GCornerNone); #else if (mDrawDithers) { draw_dithered_rect(ctx, barRect, mBackgroundColor, mTextColor, DITHER_90_PERCENT); } else { graphics_fill_rect(ctx, barRect, 0, GCornerNone); } #endif // PBL_COLOR } else // not visible { #ifdef PBL_COLOR graphics_context_set_fill_color(ctx, mMediumColor); draw_dithered_rect(ctx, barRect, mLightColor, mDarkColor, DITHER_UNFILLED_BAR); #else if (mDrawDithers) { draw_dithered_rect(ctx, barRect, mBackgroundColor, mTextColor, DITHER_20_PERCENT); } else { graphics_draw_rect(ctx, barRect); } #endif // PBL_COLOR } } if (mDrawEllipse) { APP_LOG(APP_LOG_LEVEL_DEBUG, "render_bg: draw ellipse"); // Get the lowest bars bottom Y for the circle center. int circleY = mBlocks[BAR_NUM-1]->y + mBlocks[BAR_NUM-1]->height; #ifdef PBL_COLOR graphics_context_set_fill_color(ctx, GColorBlack); if (mDarkColor.r == 0 && mDarkColor.g == 0 && mDarkColor.b == 0) { draw_dithered_circle(ctx, 120, circleY, 95, mLightColor, GColorBlack, DITHER_75_PERCENT); } else { draw_dithered_circle(ctx, 120, circleY, 95, mDarkColor, GColorBlack, DITHER_75_PERCENT); } #else //if (mDrawDithers) //{ // draw_dithered_circle(ctx, 120, circleY, 95, mBackgroundColor, mTextColor, DITHER_10_PERCENT); //} //else //{ graphics_context_set_fill_color(ctx, mBackgroundColor); graphics_fill_circle(ctx, GPoint(120, circleY), 95); //} #endif // PBL_COLOR // Draw a couple bars over the edges to clean up the circle. int coverRectX = bgRect.origin.x + bgRect.size.w; graphics_fill_rect(ctx, GRect(coverRectX, bgRect.origin.y, SCREEN_WIDTH-coverRectX, bgRect.size.h), 0, GCornerNone); int coverRectY = bgRect.origin.y + bgRect.size.h; graphics_fill_rect(ctx, GRect(0, coverRectY, SCREEN_WIDTH, SCREEN_HEIGHT-coverRectY), 0, GCornerNone); } // Set the colors for the header and footer. APP_LOG(APP_LOG_LEVEL_DEBUG, "render_bg: draw top and bottom"); #ifdef PBL_COLOR graphics_context_set_stroke_color(ctx, mDarkColor); #else graphics_context_set_stroke_color(ctx, mTextColor); graphics_context_set_fill_color(ctx, mTextColor); #endif // PBL_COLOR int boxX = SCREEN_WIDTH / 6; int boxWidth = SCREEN_WIDTH * 2 / 3; #ifdef PBL_COLOR draw_dithered_rect(ctx, GRect(boxX, TOP_TEXT_Y+TEXT_BAR_OFFSET_Y, boxWidth, TEXT_SIZE+1), mDarkColor, GColorBlack, DITHER_75_PERCENT); draw_dithered_rect(ctx, GRect(boxX, BOT_TEXT_Y+TEXT_BAR_OFFSET_Y, boxWidth, TEXT_SIZE+1), mDarkColor, GColorBlack, DITHER_75_PERCENT); graphics_context_set_stroke_color(ctx, mDarkColor); APP_LOG(APP_LOG_LEVEL_DEBUG, "render_bg: draw extra lines (R:%d, G:%d, B:%d", mDarkColor.r, mDarkColor.g, mDarkColor.b); #else graphics_draw_rect(ctx, GRect(boxX, TOP_TEXT_Y+TEXT_BAR_OFFSET_Y, boxWidth, TEXT_SIZE+1)); graphics_draw_rect(ctx, GRect(boxX, BOT_TEXT_Y+TEXT_BAR_OFFSET_Y, boxWidth, TEXT_SIZE+1)); graphics_context_set_stroke_color(ctx, mTextColor); #endif // PBL_COLOR // Draw extra lines (precalculated) graphics_draw_line(ctx, gpTop1a, gpTop1b); graphics_draw_line(ctx, gpTop1c, gpTop1d); graphics_draw_line(ctx, gpTop2a, gpTop2b); graphics_draw_line(ctx, gpTop2c, gpTop2d); graphics_draw_line(ctx, gpBot1a, gpBot1b); graphics_draw_line(ctx, gpBot1c, gpBot1d); graphics_draw_line(ctx, gpBot2a, gpBot2b); graphics_draw_line(ctx, gpBot2c, gpBot2d); #ifdef PBL_COLOR graphics_context_set_stroke_color(ctx, mMediumColor); APP_LOG(APP_LOG_LEVEL_DEBUG, "render_bg: draw more extra lines (R:%d, G:%d, B:%d", mMediumColor.r, mMediumColor.g, mMediumColor.b); #endif // PBL_COLOR graphics_draw_line(ctx, gpTopBar1, gpTopBar2); graphics_draw_line(ctx, gpBotBar1, gpBotBar2); graphics_draw_line(ctx, gpTopMiniBar1, GPoint(gpTopMiniBar1.x + LINE_OFFSET, gpTopMiniBar1.y)); graphics_draw_line(ctx, gpTopMiniBar2, GPoint(gpTopMiniBar2.x - LINE_OFFSET, gpTopMiniBar2.y)); graphics_draw_line(ctx, gpBotMiniBar1, GPoint(gpBotMiniBar1.x + LINE_OFFSET, gpBotMiniBar1.y)); graphics_draw_line(ctx, gpBotMiniBar2, GPoint(gpBotMiniBar2.x - LINE_OFFSET, gpBotMiniBar2.y)); if (mIsCharging) { // Draw the charging icon. APP_LOG(APP_LOG_LEVEL_DEBUG, "render_bg: draw charging"); #ifdef PBL_COLOR graphics_context_set_fill_color(ctx, mLightColor); #else graphics_context_set_fill_color(ctx, mTextColor); #endif // PBL_COLOR gpath_draw_filled(ctx, chargingPath); } layer_mark_dirty(sTimeLayer); }
static void battery_state_handler(BatteryChargeState charge) { s_charge_percent = charge.charge_percent; layer_mark_dirty(s_battery_layer); }
static void tick_handler(struct tm* t, TimeUnits units_changed) { APP_LOG(APP_LOG_LEVEL_DEBUG, "tick_handler"); set_time_display(t); layer_mark_dirty(sTimeLayer); }
void timer_callback(void *data) { layer_mark_dirty(countdown_layer); if (running) timer = app_timer_register(timer_delta, (AppTimerCallback) timer_callback, NULL); }
static void change_image(uint32_t new_image) { gbitmap_destroy(s_image); s_image = gbitmap_create_with_resource(new_image); layer_mark_dirty(s_image_layer); }