Beispiel #1
0
void update_title_and_info(void) {
    GRect layerSize = GRect(0, 0, c_viewportWidth, c_viewportHeight);
    
    const char* text = g_holomesh->string_table.ptr[g_holomesh->info.craft_name_string].str.ptr;
    create_symbol_text(g_craft_name_lower, sizeof(g_craft_name_lower), text);
    
    APP_LOG(APP_LOG_LEVEL_DEBUG, "'%s' -> '%s'", text, g_craft_name_lower);
    
    GSize textSize = graphics_text_layout_get_content_size(
        text,
        g_font_sw,
        layerSize,
        0,
        GTextAlignmentLeft);
    
    GRect textRect = { GPoint(0, 0), textSize };
    layer_set_bounds((Layer*) textLayer, textRect);
    layer_set_bounds((Layer*) textLayerSym, textRect);
    
    text_layer_set_text(textLayer, text);
    text_layer_set_text(textLayerSym, g_craft_name_lower);

    GRect currentFrame = layer_get_bounds((Layer*) infoTextLayer);
    currentFrame.origin.y = textRect.origin.y + textRect.size.h / 2;
    layer_set_bounds((Layer*) infoTextLayer, currentFrame);

    set_new_stat_text();
}
Beispiel #2
0
static void sushi_step(){
  
  Layer *window_layer = window_get_root_layer(s_main_window);
  GRect window_bounds = layer_get_bounds(window_layer);
  
  GRect bounds = layer_get_bounds(bitmap_layer_get_layer(s_background_layer));
  int16_t current_x = bounds.origin.x;

  if(current_x == window_bounds.size.w-720 ) {
    layer_set_bounds(bitmap_layer_get_layer(s_background_layer), GRect(0, bounds.origin.y, bounds.size.w, bounds.size.h));
  }else{
    layer_set_bounds(bitmap_layer_get_layer(s_background_layer), GRect(current_x-36, bounds.origin.y, bounds.size.w, bounds.size.h));
  }
}
Beispiel #3
0
static void initialise_ui(void) {
    s_window = window_create();
    window_set_background_color(s_window, GColorBlack);
    IF_2(window_set_fullscreen(s_window, true));

    s_res_img_upaction = gbitmap_create_with_resource(RESOURCE_ID_IMG_UPACTION);
    s_res_img_nextaction = gbitmap_create_with_resource(RESOURCE_ID_IMG_NEXTACTION);
    s_res_img_downaction = gbitmap_create_with_resource(RESOURCE_ID_IMG_DOWNACTION);
    s_res_gothic_18_bold = fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD);
    s_res_bitham_30_black = fonts_get_system_font(FONT_KEY_BITHAM_30_BLACK);
    // action_layer
    action_layer = action_bar_layer_create();
    action_bar_layer_add_to_window(action_layer, s_window);
    action_bar_layer_set_background_color(action_layer, GColorWhite);
    action_bar_layer_set_icon(action_layer, BUTTON_ID_UP, s_res_img_upaction);
    action_bar_layer_set_icon(action_layer, BUTTON_ID_SELECT, s_res_img_nextaction);
    action_bar_layer_set_icon(action_layer, BUTTON_ID_DOWN, s_res_img_downaction);
    layer_set_frame(action_bar_layer_get_layer(action_layer), GRect(124, 0, 20, 168));
    IF_3(layer_set_bounds(action_bar_layer_get_layer(action_layer), GRect(-5, 0, 30, 168)));
    layer_add_child(window_get_root_layer(s_window), (Layer *)action_layer);

    time_layer = layer_create(GRect(0, 0, 124, 168));
    layer_set_update_proc(time_layer, draw_time);
    layer_add_child(window_get_root_layer(s_window), time_layer);
}
Beispiel #4
0
void doDataInvert(int field)  // Fixed up due to loss of inverter_layer
  {
  GRect a = layer_get_frame(text_layer_get_layer(s_data_layer[screens[currentScreen].field_layer_map[field]]));
  a.origin.y += a.size.h / 4;
  a.size.h -= a.size.h/4 ;
  #ifdef PBL_COLOR
  int fd = keyTitles[screens[currentScreen].field_data_map[field]].key;
  if (fd == KEY_LAY_BURN || fd == KEY_LINE_BURN) {  // Set BURN fields green when negative
    text_layer_set_text_color(s_data_layer[screens[currentScreen].field_layer_map[field]], greenTextColour);
  }
  else { // All other fields invert (sort of!!)
//    layer_remove_from_parent(text_layer_get_layer(dataInverterPT[field])); 
    layer_set_frame(text_layer_get_layer(dataInverterPT[field]), a);
    layer_set_hidden(text_layer_get_layer(dataInverterPT[field]), false);
    text_layer_set_background_color(dataInverterPT[field], negativeBackgroundColour);
    // layer_insert_above_sibling(text_layer_get_layer(dataInverterPT[field]), text_layer_get_layer(s_data_layer[screens[currentScreen].field_layer_map[field]]));
    text_layer_set_text_color(s_data_layer[screens[currentScreen].field_layer_map[field]], negativeTextColour);
  }
  #else // On old Pebble, just invert
  layer_set_bounds(inverter_layer_get_layer(dataInverter[field]), a);
  #endif
  
  // To revert
  // layer_set_bounds(inverter_layer_get_layer(inverter), GRect(0,0,0,0));
}
static void prv_corner_callback(void* data) {
  VirutalScreenMode mode = (VirutalScreenMode)data;
  static int pos[5][2] = {{0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}};
  pos[0][0] = -s_center_point.x;
  pos[0][1] = -s_center_point.y;
  pos[2][0] = pos[3][0] = -s_max_point.x;
  pos[3][1] = pos[4][1] = -s_max_point.y;
  uint8_t curr_pos = 0; // VIRTUAL_SCREEN_MODE_CENTERED
  switch(mode) {
    case VIRTUAL_SCREEN_MODE_BOTTOM_LEFT: {
      ++curr_pos;
      // no break
    }
    case VIRTUAL_SCREEN_MODE_BOTTOM_RIGHT: {
      ++curr_pos;
      // no break
    }
    case VIRTUAL_SCREEN_MODE_TOP_RIGHT: {
      ++curr_pos;
      // no break
    }
    case VIRTUAL_SCREEN_MODE_TOP_LEFT: {
      ++curr_pos;
      // no break
    }
    default: break;
  }
  s_accel_point = GPoint(pos[curr_pos][0], pos[curr_pos][1]);
  GRect bounds = layer_get_bounds(s_layer);
  bounds.origin = s_accel_point;
  layer_set_bounds(s_layer, bounds);
  layer_mark_dirty(s_layer);
}
Beispiel #6
0
static void update_time() {
  // Get a tm structure
  time_t temp = time(NULL); 
  struct tm *tick_time = localtime(&temp);

  // Create a long-lived buffer
  static char buffer[] = "00:00";
  static char suffixBuffer[] = "am";

  // Write the current hours and minutes into the buffer
  if(clock_is_24h_style() == true) {
    //Use 24h hour format
    strftime(buffer, sizeof("00:00"), "%H:%M", tick_time);
    layer_set_hidden((Layer*)s_suffix_layer, true);
    
    // make sure it is the right width
    GRect bounds = layer_get_bounds((Layer*)s_time_layer);
    if (bounds.size.w != 134) {
      bounds.size.w = 134;
      layer_set_bounds((Layer*)s_time_layer, bounds);
    }
  } else {
    //Use 12 hour format
    strftime(buffer, sizeof("00:00"), "%I:%M", tick_time);
    if (buffer[0] == '0') {
      memmove(buffer, &buffer[1], sizeof(buffer) - 1);
    }
    strftime(suffixBuffer, sizeof("am"), "%p", tick_time);
    layer_set_hidden((Layer*)s_suffix_layer, false);
    
    // make sure it is the right width
    GRect bounds = layer_get_bounds((Layer*)s_time_layer);
    if (bounds.size.w != 110) {
      bounds.size.w = 110;
      layer_set_bounds((Layer*)s_time_layer, bounds);
    }
  }
  
  // date
  static char dateBuffer[] = "Mon Jan 01";
  strftime(dateBuffer, sizeof("Mon Jan 01"), "%a %b %d", tick_time);

  // Display this time on the TextLayer
  text_layer_set_text(s_time_layer, buffer);
  text_layer_set_text(s_suffix_layer, suffixBuffer);
  text_layer_set_text(s_date_layer, dateBuffer);
}
static void update_ui() {
    layer_set_bounds(s_plus_layer, GRect(s_current_field*FIELD_SPACING, 0, FIELD_WIDTH, FIELD_HEIGHT));
    layer_set_bounds(s_minus_layer, GRect(s_current_field*FIELD_SPACING, 0, FIELD_WIDTH, FIELD_HEIGHT));
    for (int i = 0; i<4; i++) {
        GColor color = BG_COLOR;
        if (s_current_field == i) {
            color = SEL_COLOR;

#ifdef PBL_BW
            text_layer_set_text_color(s_ip_layers[i], GColorBlack);
#endif
        } else {
            text_layer_set_text_color(s_ip_layers[i], GColorWhite);
        }
        text_layer_set_background_color(s_ip_layers[i], color); 
        snprintf(s_value_buffers[i], 4, "%d", s_ip[i]);
        text_layer_set_text(s_ip_layers[i], s_value_buffers[i]);
    }
}
void selection_layer_set_cell_width(Layer *layer, int idx, int width) {
  SelectionLayerData *data = layer_get_data(layer);
  
  if (data && idx < data->num_cells) {
    data->cell_widths[idx] = width;
  }
#ifndef PBL_COLOR
  layer_set_bounds(inverter_layer_get_layer(data->inverter), GRect(0, 0, width, layer_get_bounds(inverter_layer_get_layer(data->inverter)).size.h));
#endif
}
Beispiel #9
0
void doDataInvert(int field)
  {
  GRect a = layer_get_frame(text_layer_get_layer(s_data_layer[screens[currentScreen].field_layer_map[field]]));
  a.origin.y += a.size.h / 4;
  a.size.h -= a.size.h/4 ;
  layer_set_bounds(inverter_layer_get_layer(dataInverter[field]), a);
  
  // To revert
  // layer_set_bounds(inverter_layer_get_layer(inverter), GRect(0,0,0,0));
}
Beispiel #10
0
void doDataRevert(int field)
  {
  #ifdef PBL_COLOR
  // layer_set_bounds(text_layer_get_layer(dataInverterPT[field]), GRectZero);
  layer_set_hidden(text_layer_get_layer(dataInverterPT[field]), true);
  text_layer_set_text_color(s_data_layer[screens[currentScreen].field_layer_map[field]], normalTextColour);
  #else
  layer_set_bounds(inverter_layer_get_layer(dataInverter[field]), GRectZero);
  #endif
}
Beispiel #11
0
static void initialise_ui(void) {
  
  s_window = window_create();
  Layer *root_layer = window_get_root_layer(s_window);
  GRect bounds = layer_get_bounds(root_layer); 
  window_set_background_color(s_window, COLOR_FALLBACK(GColorBulgarianRose, GColorBlack)); 
  IF_2(window_set_fullscreen(s_window, false));
  
#ifdef PBL_ROUND
  int dev_layer_left = (bounds.size.w - DEV_LAYER_WIDTH)/2;
  int dev_layer_top = (bounds.size.h - DEV_LAYER_HEIGHT)/2;
#else
  int dev_layer_left = ((bounds.size.w - DEV_LAYER_WIDTH - ACTION_BAR_WIDTH)/2) + 4;
  int dev_layer_top = ((bounds.size.h - DEV_LAYER_HEIGHT - 14)/2) + IF_32(14, 0);
#endif
  
  s_rect_above = GRect(dev_layer_left, -(DEV_LAYER_HEIGHT+2), DEV_LAYER_WIDTH, DEV_LAYER_HEIGHT);
  s_rect_onscreen = GRect(dev_layer_left, dev_layer_top, DEV_LAYER_WIDTH, DEV_LAYER_HEIGHT);
  s_rect_below = GRect(dev_layer_left, bounds.size.h+2, DEV_LAYER_WIDTH, DEV_LAYER_HEIGHT);
  
  // s_devicecard_layer
  s_devicecard_layer = devicecard_layer_create(s_rect_onscreen);
  layer_add_child(root_layer, s_devicecard_layer->layer);
  
  // s_layer_spots
  s_layer_spots = layer_create(PBL_IF_RECT_ELSE(GRect((dev_layer_left/2)-SPOT_RADIUS, dev_layer_top, 
                                                (SPOT_RADIUS*2)+1 , DEV_LAYER_HEIGHT), bounds));
  layer_add_child(root_layer, (Layer *)s_layer_spots);
  
#ifndef PBL_SDK_2
  s_status_bar = status_bar_layer_create();
  status_bar_layer_set_colors(s_status_bar, COLOR_FALLBACK(GColorBulgarianRose, GColorBlack), GColorWhite);
  layer_add_child(root_layer, status_bar_layer_get_layer(s_status_bar));
#endif
  
  s_res_image_action_up = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_ACTION_UP);
  s_res_image_action_set = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_ACTION_SET);
  s_res_image_action_down = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_ACTION_DOWN);
  
  // s_actionbar_main
  s_actionbar_main = action_bar_layer_create();
  action_bar_layer_add_to_window(s_actionbar_main, s_window);
  action_bar_layer_set_background_color(s_actionbar_main, GColorWhite);
  action_bar_layer_set_icon(s_actionbar_main, BUTTON_ID_UP, s_res_image_action_up);
  action_bar_layer_set_icon(s_actionbar_main, BUTTON_ID_SELECT, s_res_image_action_set);
  action_bar_layer_set_icon(s_actionbar_main, BUTTON_ID_DOWN, s_res_image_action_down);
#ifdef PBL_RECT
  layer_set_frame(action_bar_layer_get_layer(s_actionbar_main), GRect(bounds.size.w-20, 0, 20, bounds.size.h));
  IF_3(layer_set_bounds(action_bar_layer_get_layer(s_actionbar_main), GRect(-5, 0, 30, bounds.size.h)));
#endif
  layer_add_child(root_layer, (Layer *)s_actionbar_main);
}
Beispiel #12
0
static void initialise_ui(void) {
  s_window = window_create();
  window_set_background_color(s_window, GColorBlack);
  IF_2(window_set_fullscreen(s_window, true));
  
  s_res_img_upaction = gbitmap_create_with_resource(RESOURCE_ID_IMG_UPACTION);
  s_res_img_okaction = gbitmap_create_with_resource(RESOURCE_ID_IMG_OKACTION);
  s_res_img_downaction = gbitmap_create_with_resource(RESOURCE_ID_IMG_DOWNACTION);
  s_res_gothic_24 = fonts_get_system_font(FONT_KEY_GOTHIC_24);
  s_res_gothic_28 = fonts_get_system_font(FONT_KEY_GOTHIC_28);
  // s_actionbarlayer
  s_actionbarlayer = action_bar_layer_create();
  action_bar_layer_add_to_window(s_actionbarlayer, s_window);
  action_bar_layer_set_background_color(s_actionbarlayer, GColorWhite);
  action_bar_layer_set_icon(s_actionbarlayer, BUTTON_ID_UP, s_res_img_upaction);
  action_bar_layer_set_icon(s_actionbarlayer, BUTTON_ID_SELECT, s_res_img_okaction);
  action_bar_layer_set_icon(s_actionbarlayer, BUTTON_ID_DOWN, s_res_img_downaction);
  layer_set_frame(action_bar_layer_get_layer(s_actionbarlayer), GRect(124, 0, 20, 168));
  IF_3(layer_set_bounds(action_bar_layer_get_layer(s_actionbarlayer), GRect(-5, 0, 30, 168)));
  layer_add_child(window_get_root_layer(s_window), (Layer *)s_actionbarlayer);
  
  // s_textlayer_info
  s_textlayer_info = text_layer_create(GRect(7, 25, 117, 32));
  text_layer_set_background_color(s_textlayer_info, GColorClear);
  text_layer_set_text_color(s_textlayer_info, GColorWhite);
  text_layer_set_text(s_textlayer_info, "Skip Until:");
  text_layer_set_text_alignment(s_textlayer_info, GTextAlignmentCenter);
  text_layer_set_font(s_textlayer_info, s_res_gothic_24);
  layer_add_child(window_get_root_layer(s_window), (Layer *)s_textlayer_info);
  
  // s_textlayer_date
  s_textlayer_date = text_layer_create(GRect(2, 64, 122, 32));
  text_layer_set_background_color(s_textlayer_date, GColorClear);
  text_layer_set_text_color(s_textlayer_date, GColorWhite);
  text_layer_set_text(s_textlayer_date, "Thu, Feb 22");
  text_layer_set_text_alignment(s_textlayer_date, GTextAlignmentCenter);
  text_layer_set_font(s_textlayer_date, s_res_gothic_28);
  layer_add_child(window_get_root_layer(s_window), (Layer *)s_textlayer_date);
  
  // s_textlayer_status
  s_textlayer_status = text_layer_create(GRect(7, 100, 117, 32));
  text_layer_set_background_color(s_textlayer_status, GColorClear);
  text_layer_set_text_color(s_textlayer_status, GColorWhite);
  text_layer_set_text(s_textlayer_status, "(No skipping)");
  text_layer_set_text_alignment(s_textlayer_status, GTextAlignmentCenter);
  text_layer_set_font(s_textlayer_status, s_res_gothic_24);
  layer_add_child(window_get_root_layer(s_window), (Layer *)s_textlayer_status);
}
Beispiel #13
0
static void initialise_ui(void) {
  s_window = window_create();
  window_set_background_color(s_window, GColorBlack);
  IF_A(window_set_fullscreen(s_window, true));
  
  s_res_img_standby = gbitmap_create_with_resource(RESOURCE_ID_IMG_STANDBY);
  s_res_img_settings = gbitmap_create_with_resource(RESOURCE_ID_IMG_SETTINGS);
  s_res_roboto_bold_subset_49 = fonts_get_system_font(FONT_KEY_ROBOTO_BOLD_SUBSET_49);
  s_res_gothic_18_bold = fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD);
  // action_layer
  action_layer = action_bar_layer_create();
  action_bar_layer_add_to_window(action_layer, s_window);
  action_bar_layer_set_background_color(action_layer, GColorWhite);
  action_bar_layer_set_icon(action_layer, BUTTON_ID_UP, s_res_img_standby);
  action_bar_layer_set_icon(action_layer, BUTTON_ID_DOWN, s_res_img_settings);
  layer_set_frame(action_bar_layer_get_layer(action_layer), GRect(124, 0, 20, 168));
  IF_B(layer_set_bounds(action_bar_layer_get_layer(action_layer), GRect(-5, 0, 30, 168)));
  layer_add_child(window_get_root_layer(s_window), (Layer *)action_layer);
  
  // clockbg_layer
  clockbg_layer = text_layer_create(GRect(0, 60, 144, 50));
  text_layer_set_background_color(clockbg_layer, GColorBlack);
  text_layer_set_text_color(clockbg_layer, GColorClear);
  text_layer_set_text(clockbg_layer, "    ");
  layer_add_child(window_get_root_layer(s_window), (Layer *)clockbg_layer);
  
  // clock_layer
  clock_layer = text_layer_create(GRect(0, 52, 144, 65));
  text_layer_set_background_color(clock_layer, GColorClear);
  text_layer_set_text_color(clock_layer, GColorWhite);
  text_layer_set_text(clock_layer, "23:55");
  text_layer_set_text_alignment(clock_layer, GTextAlignmentCenter);
  text_layer_set_font(clock_layer, s_res_roboto_bold_subset_49);
  layer_add_child(window_get_root_layer(s_window), (Layer *)clock_layer);
  
  // onoff_layer
  onoff_layer = text_layer_create(GRect(2, 2, 119, 56));
  layer_set_update_proc(text_layer_get_layer(onoff_layer), draw_onoff); 
  layer_add_child(window_get_root_layer(s_window), (Layer *)onoff_layer);
  
  // info_layer
  info_layer = text_layer_create(GRect(2, 110, 119, 56));
  layer_set_update_proc(text_layer_get_layer(info_layer), draw_info); 
  layer_add_child(window_get_root_layer(s_window), (Layer *)info_layer);
}
Beispiel #14
0
void event_window_load(Window *window) {
  
  // generate random int for selecting text message
  
  int text_selector = rand()%4;
  
  if (text_selector == 0) {
    snprintf(stringbuffer, 64, "Daily progress: %d",event_counter);
  } else if (text_selector == 1) {
    snprintf(stringbuffer, 64, "Percent complete: %d",(int)(((float)event_counter/(float)yesterday_counter)*100));
  } else if (text_selector == 2) {
    snprintf(stringbuffer, 64, "Remaining: %d\nGreat work!",yesterday_counter-event_counter);
  } else if (text_selector == 3) {
    snprintf(stringbuffer, 64, "Today: %d\nGoal: %d",event_counter, yesterday_counter);
  }
  
  gbfly_ld = gbitmap_create_with_resource(RESOURCE_ID_BFLY_LD);
  gbfly_lu = gbitmap_create_with_resource(RESOURCE_ID_BFLY_LU);
  gbfly_rd = gbitmap_create_with_resource(RESOURCE_ID_BFLY_RD);
  gbfly_ru = gbitmap_create_with_resource(RESOURCE_ID_BFLY_RU);
  
  draw_layer = bitmap_layer_create(GRect(0, 0, 144, 112));
  layer_set_bounds(bitmap_layer_get_layer(draw_layer),GRect(x, y, 144-x, 112-y));
  bitmap_layer_set_bitmap(draw_layer, gbfly_rd);
  
  drawtimer = app_timer_register(100, draw_timer_callback, NULL);
  
  
  event_title_layer = text_layer_create(GRect(0, 112, 144, 168));
  
  text_layer_set_font(event_title_layer, fonts_get_system_font(FONT_KEY_ROBOTO_CONDENSED_21));
  text_layer_set_text(event_title_layer, stringbuffer);
  
  //event_inverter = inverter_layer_create(GRect(0, 112, 144, 168));
  
  
  // add child layers
  Layer *event_root_layer = window_get_root_layer(window);
  layer_add_child(event_root_layer, text_layer_get_layer(event_title_layer));
  layer_add_child(event_root_layer, bitmap_layer_get_layer(draw_layer));
  //layer_add_child(event_root_layer, inverter_layer_get_layer(event_inverter));
  
  timer = app_timer_register(5000, event_timer_callback, NULL);
}
Beispiel #15
0
void draw_timer_callback(void *data) {
  int direction = rand()%5;
  
  while (((direction == 0) && (last_direction == 0))
         || ( ((direction == 2) || (direction == 5)) &&(facing == 1)&&(last_direction!= 0))
         || ( ((direction == 3) || (direction == 4)) &&(facing == 0)&&(last_direction!= 0))) {
    direction = rand()%4;
  }
  
  if (direction == 0) {         // up
    y = y-(6*pixel_multiplier);
    if (facing == 0) {
      selected_gbit = gbfly_lu;
    } else {
      selected_gbit = gbfly_ru;
    }
  } else if (direction == 1) {  // down
    y=y+(3*pixel_multiplier);
    if (facing == 0) {
      selected_gbit = gbfly_ld;
    } else {
      selected_gbit = gbfly_rd;
    }
  } else if ((direction == 2)||(direction == 5)) { // left
    x=x-(3*pixel_multiplier);
    selected_gbit = gbfly_ld;
    facing = 0;
  } else if ((direction == 3)||(direction == 4)) {  // right
    x=x+(3*pixel_multiplier);
    facing = 1;
    selected_gbit = gbfly_rd;
  }
  
  bitmap_layer_set_bitmap(draw_layer, selected_gbit);
  layer_set_bounds(bitmap_layer_get_layer(draw_layer), GRect(x, y, 144-x, 112-y));
  
  last_direction = direction;
  
  if (is_window_loaded == 1) {
  drawtimer = app_timer_register(100, draw_timer_callback, NULL);
  }
}
Beispiel #16
0
static void initialise_ui(void) {
  
  Layer *root_layer = NULL;
  GRect bounds; 
  s_window = window_create_fullscreen(&root_layer, &bounds);
  
  s_res_img_standby = gbitmap_create_with_resource(RESOURCE_ID_IMG_STANDBY);
  s_res_img_settings = gbitmap_create_with_resource(RESOURCE_ID_IMG_SETTINGS);
  s_res_roboto_bold_subset_49 = fonts_get_system_font(FONT_KEY_ROBOTO_BOLD_SUBSET_49);
  s_res_gothic_18_bold = fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD);
  // action_layer
  action_layer = action_bar_layer_create();
  action_bar_layer_add_to_window(action_layer, s_window);
  action_bar_layer_set_background_color(action_layer, GColorWhite);
  action_bar_layer_set_icon(action_layer, BUTTON_ID_UP, s_res_img_standby);
  action_bar_layer_set_icon(action_layer, BUTTON_ID_DOWN, s_res_img_settings);
#ifdef PBL_RECT
  layer_set_frame(action_bar_layer_get_layer(action_layer), GRect(bounds.size.w-20, 0, 20, bounds.size.h));
  IF_3(layer_set_bounds(action_bar_layer_get_layer(action_layer), GRect(-6, 0, 31, bounds.size.h)));
  // Put Action Bar underneath other layers on rectangular Pebbles
  layer_add_child(root_layer, action_bar_layer_get_layer(action_layer));
#endif
  
  // clock_layer
  clock_layer = layer_create_with_proc(root_layer, draw_clock,
                                       GRect(0 - PBL_IF_RECT_ELSE(0, ACTION_BAR_WIDTH/2), (bounds.size.h/2)-32-PBL_IF_ROUND_ELSE(2, 0), bounds.size.w, 65));
  
  // onoff_layer
  onoff_layer = layer_create_with_proc(root_layer, draw_onoff,
                                      PBL_IF_RECT_ELSE(GRect(2, (bounds.size.h/2)-82, 119, 56),
                                                   GRect(-10, (bounds.size.h/2)-82, bounds.size.w+11, 56)));
  
  // info_layer
  info_layer = layer_create_with_proc(root_layer, draw_info,
                                     PBL_IF_RECT_ELSE(GRect(2, (bounds.size.h/2)+26, 119, 56),
                                                 GRect(-10, (bounds.size.h/2)+24, bounds.size.w+11, 56)));
  
#ifdef PBL_ROUND
  // Put Action Bar on top for Pebble Round
  layer_add_child(root_layer, (Layer *)action_layer);
#endif
}
Beispiel #17
0
void set_new_stat_text(void) {
    const holomesh_tag_t* tag = &g_holomesh->tags.ptr[
        (++g_current_stat) % g_holomesh->tags.size
    ];

    const char* stat = g_holomesh->string_table.ptr[tag->name_string].str.ptr;

    GRect currentFrame = layer_get_bounds(text_layer_get_layer(infoTextLayer));

    currentFrame.size = GSize(c_viewportWidth, c_viewportHeight);
    currentFrame.size = graphics_text_layout_get_content_size(
        stat,
        g_font_info,
        currentFrame,
        0,
        GTextAlignmentLeft);
    
    layer_set_bounds(text_layer_get_layer(infoTextLayer), currentFrame);
    text_layer_set_text(infoTextLayer, stat);
}
static void prv_direct_callback(void* data) {
  static AccelData last_accel_data;
  AccelData accel_data;
  accel_service_peek(&accel_data);
  if(   ABS(accel_data.x, last_accel_data.x) > VIRTUAL_SCREEN_UPDATE_THRESHOLD
     || ABS(accel_data.y, last_accel_data.y) > VIRTUAL_SCREEN_UPDATE_THRESHOLD) {
    s_accel_point = GPoint(
      s_center_point.x-(s_reference_point.x - accel_data.x)/VIRTUAL_SCREEN_UPDATE_SENSITIVITY,
      s_center_point.x+(s_reference_point.y - accel_data.y)/VIRTUAL_SCREEN_UPDATE_SENSITIVITY);
    if(s_accel_point.x > s_max_point.x) s_accel_point.x = s_max_point.x;
    if(s_accel_point.x < 0) s_accel_point.x = 0;
    if(s_accel_point.y > s_max_point.y) s_accel_point.y = s_max_point.y;
    if(s_accel_point.y < 0) s_accel_point.y = 0;
    GRect bounds = layer_get_bounds(s_layer);
    bounds.origin = GPoint(-s_accel_point.x, -s_accel_point.y);
    layer_set_bounds(s_layer, bounds);
    layer_mark_dirty(s_layer);
  }
  last_accel_data = accel_data;
  s_timer = app_timer_register(VIRTUAL_SCREEN_UPDATE_TIMEOUT_MS, prv_direct_callback, data);
}
Beispiel #19
0
void screenMessage(char *message)
  {
  static int preHoldThisScreen = TRANSITION_IDLE;
  
  if (*message != '\0') // Setting a message
    {
    updatescreen(-1,""); //Blank
    layer_set_bounds(inverter_layer_get_layer(inverter), GRect(0,0,0,0)); // Turn off the inverter layer
    preHoldThisScreen = holdThisScreen; // Remember what it was
    holdThisScreen = -1;
    messageClick = true;
    text_layer_set_text(messageLayer, message);
  }
  else //Clearing a message
    {
    messageClick = false;
    holdThisScreen = preHoldThisScreen; // Restore it to what it was
    text_layer_set_text(messageLayer,"");  
    updatescreen(currentScreen, "");
  }
  
}
Beispiel #20
0
MarqueeTextLayer* marquee_text_layer_create(GRect frame) {
    
	MarqueeTextLayer *marquee = layer_create_with_data(frame, sizeof(MarqueeData));
	MarqueeData *marqueedata = (MarqueeData *)layer_get_data(marquee);
	//APP_LOG(APP_LOG_LEVEL_DEBUG, "marquee_text_layer_create: malloc MarqueeTextLayer");
	//APP_LOG(APP_LOG_LEVEL_DEBUG, "marquee_text_layer_create: got a marquee pointer, allocated %d bytes at %p", sizeof(MarqueeTextLayer), marquee);
	
	marqueedata->text = malloc(128); // allocate some bytes for the string
	if (marqueedata->text)
		APP_LOG(APP_LOG_LEVEL_DEBUG, "allocated 128 bytes for marquee->text at %p", marqueedata->text);
	
	
	// And now we lie about our frame. See above.
    //frame.origin.x -= BOUND_OFFSET;
    //frame.size.w += BOUND_OFFSET;
	
	layer_set_frame(marquee,GRect(frame.origin.x - BOUND_OFFSET,frame.origin.y,frame.size.w + BOUND_OFFSET, frame.size.h));
	APP_LOG(APP_LOG_LEVEL_DEBUG, "frame.origin.x = %d, frame.origin.y = %d, frame.size.w = %d, frame.size.h = %d", layer_get_frame(marquee).origin.x, layer_get_frame(marquee).origin.y, layer_get_frame(marquee).size.w, layer_get_frame(marquee).size.h);
	
    //GRect bounds = layer_get_bounds(marquee);
    //APP_LOG(APP_LOG_LEVEL_DEBUG, "pre bounds.origin.x = %d, bounds.origin.y = %d, bounds.size.w = %d, bounds.size.h = %d", bounds.origin.x, bounds.origin.y, bounds.size.w, bounds.size.h);
	//bounds.origin.x += BOUND_OFFSET + 25;
    //APP_LOG(APP_LOG_LEVEL_DEBUG, "post adjust bounds.origin.x = %d, bounds.origin.y = %d, bounds.size.w = %d, bounds.size.h = %d", bounds.origin.x, bounds.origin.y, bounds.size.w, bounds.size.h);
	//layer_set_bounds(marquee, bounds);
	layer_set_bounds(marquee,GRect(layer_get_bounds(marquee).origin.x + BOUND_OFFSET,0,frame.size.w + BOUND_OFFSET, frame.size.h));
	APP_LOG(APP_LOG_LEVEL_DEBUG, "post set bounds.origin.x = %d, bounds.origin.y = %d, bounds.size.w = %d, bounds.size.h = %d", layer_get_bounds(marquee).origin.x, layer_get_bounds(marquee).origin.y, layer_get_bounds(marquee).size.w, layer_get_bounds(marquee).size.h);
    marqueedata->background_colour = GColorWhite;
    marqueedata->text_colour = GColorBlack;
    marqueedata->offset = 0;
	marqueedata->text_width = -1;
    marqueedata->countdown = 100;
    marqueedata->font = fonts_get_system_font(FONT_KEY_FONT_FALLBACK);

	layer_set_clips(marquee, false);
	layer_set_update_proc(marquee, do_draw);
	marquee_text_layer_mark_dirty(marquee);
		
	return marquee;
}
Beispiel #21
0
void calendar_load(Window* wnd)
{
    // Set the background first
    window_set_background_color(wnd, CALENDAR_BACKGROUND);
    
    // Create a graphics context
    Layer* windowLayer = window_get_root_layer(wnd);
    
    // Get the frame of the parent layer
    GRect calendarFrame = layer_get_frame(windowLayer);
    GRect calendarBounds = calendarFrame;
    
    // Get the height and triple it
    // This allows us to have a region at the top and bottom
    // for next/previous months.
    // Then set the frame to be dead in the middle of it.
    calendarBounds.origin.y = -calendarFrame.size.h;
    calendarBounds.size.h *= 3;
    
    Layer* graphicsLayer = layer_create(calendarFrame);
    layer_set_bounds(graphicsLayer, calendarBounds);
    
    RootData* data = malloc(sizeof(RootData));
    if(data == NULL)
        APP_LOG(APP_LOG_LEVEL_ERROR, "Failed to allocate storage for data");
    data->graphicsLayer = graphicsLayer;
    data->curTime = time(NULL);
    window_set_user_data(wnd, data);
    
    // Set the update callback
    layer_set_update_proc(graphicsLayer, calendar_graphics_draw);
    
    layer_add_child(windowLayer, graphicsLayer);
    
    window_set_click_config_provider(wnd, calendar_click_config_provider);
}
Beispiel #22
0
void doDataRevert(int field)
  {
  layer_set_bounds(inverter_layer_get_layer(dataInverter[field]), GRect(0,0,0,0));
}
Beispiel #23
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);
}
Beispiel #24
0
//
// Handle incoming messages from phone
//
void inbox_received_callback(DictionaryIterator *iterator, void *context) {
  // Store incoming information
  static char *layDecode[] = {"SPN", "SCB", "SMD",NULL,NULL,NULL,NULL,NULL,NULL,NULL,"PPN","PCB","PMD","PPN","PCB","PMD"};
  static int tackLog[7] = {0,0,0,0,0,0,0};
  static bool warnedLineBurn = false;
  static int currentState = -1;
  static int thisTack = 0, oldTack = 0;
  int angle;
  bool earlyWarnDone = false;
  bool weAreRacing = false;
  bool doScreenTransition;
  #ifdef PBL_COLOR
  bool redAWA, highVMG;
  #endif
  int j, tmp, ii;
  bool foundKey, negNum; 
  #ifdef CONFIG_SUPPORT
  bool foundAKey = false; // Did we find any data keys in the message?
  #endif
  int startingScreen; // To remember which screen we were at when we arrived here so we don't loop forever looking for a screen with data on it
  int a;
  float b;
  static int flashFlag = 0;
  char *sa, *sb;
  bool fieldUpdated[6];
  bool canDoVMG;
  int twd, bs, hdg;
  #ifdef CONFIG_SUPPORT
    bool receivedConfig = false;
  #endif
  
  if (doubleClick || messageClick)
    return; // Get out of here if we are displaying a message - note - we may miss a tack because of this, but unlikely!!
  startingScreen = currentScreen;
#ifdef PBL_COLOR
  text_layer_set_background_color(flash, flashFlag == 0 ? GColorGreen : GColorClear);
#else
  layer_set_bounds(inverter_layer_get_layer(flash), flashFlag == 0 ? GRectZero : GRect(0,0,7,7)); 
#endif
  flashFlag = 1 - flashFlag;
  if (holdThisScreen > 0)
    holdThisScreen--;
  
  weAreRacing = false; // Assume we're not racing unless we receive a mark name
  do
    {
    for (ii = 0; ii < screens[currentScreen].num_fields; ii++) {
      fieldUpdated[ii] = false;
    }
    canDoVMG = false;
    #ifdef PBL_COLOR
    redAWA = false;
    highVMG = false;
    #endif
    doScreenTransition = false;
    weAreRacing = false;
    // Read first item
    Tuple *t = dict_read_first(iterator);
    j = 0;
    while(t != NULL) {
    foundKey = true;
    char *bj;
    bj = buffer[j];
    // Which key was received?
    //APP_LOG(APP_LOG_LEVEL_INFO, "Key %d Value %d", (int)t->key, (int)t->value->int32);
    switch(t->key) {
      
      case KEY_LINE_BURN:      
      case KEY_LAY_TIME:
      case KEY_LINE_TIME:
      case KEY_SECS_TO_START:
      case KEY_LAY_BURN:
      case KEY_TIME_TO_MARK:
      negNum = false;    
      tmp = abs((int)t->value->int32) ;
      negNum = ((int)t->value->int32 < 0);

      if (tmp >= 100)
      {
        if ((tmp < 6000 && isBigField(t->key)) || tmp < 600) // We have room for mins & seconds & always when mins < 10
        {
          snprintf(bj, sizeof(buffer[0]),"%d:%02d", tmp / 60, tmp % 60);
        }
        else if (tmp < 3600)
        {
          snprintf(bj, sizeof(buffer[0]),"%dm", tmp / 60 + ((tmp % 60) >= 30 ? 1:0));
        }
        else
          {
          snprintf(bj, sizeof(buffer[0]),"%dh", tmp / 3600 + ((tmp % 3600) >= 1800 ? 1:0));          
        }
      }
      else // (tmp < 100)
      {
        snprintf(bj, sizeof(buffer[0]),"%ds", tmp);
      }
      break;

      case KEY_LAST_TACK:
      oldTack = thisTack; // Remember the tack from the last message 
      thisTack = (int)t->value->int32;
      negNum = false; // This definitely shouldn't happen!
      if (currentState != 1)
        bj[0] = '\0';
      else
        snprintf(bj, sizeof(buffer[0]),"%d", abs((int)t->value->int32));
      break;
      
      case KEY_TARGET_TACK:
      negNum = false;
      snprintf(bj, sizeof(buffer[0]),"%d", abs((int)t->value->int32));
      
      case KEY_TWD:
      if (t->key == KEY_TWD) {
        canDoVMG = true;
        twd = t->value->int32;
      }
      case KEY_LAY_DIST:
      case KEY_LINE_DIST:

      case KEY_TARGET_ANGLE:
      case KEY_MARK_BEARING:
      case KEY_HEADING_COG:
      case KEY_HEADING:
      if (t->key == KEY_HEADING)
        hdg = t->value->int32;
      case KEY_AWS:

      case KEY_TWS:
      case KEY_DEPTH:
      case KEY_HEEL:
      case KEY_CURRENT_DIR:
      negNum = ((int)t->value->int32 < 0);
      snprintf(bj, sizeof(buffer[0]),"%d", abs((int)t->value->int32));
      break;
 
      case KEY_TWA:
      case KEY_AWA:
      negNum = false;
      angle = (int)t->value->int32;
      #ifdef PBL_COLOR
      redAWA = angle > 180;
      if (colourAWA) {
              snprintf(bj, sizeof(buffer[0]),"%d", angle <= 180 ? angle : abs(angle - 360));
      } else {
              snprintf(bj, sizeof(buffer[0]),"%d%s", angle <= 180 ? angle : abs(angle - 360), angle <= 180 ? "S":"P");
      }
      #else
      snprintf(bj, sizeof(buffer[0]),"%d%s", angle <= 180 ? angle : abs(angle - 360), angle <= 180 ? "S":"P");
      #endif
      break;
      
      case KEY_BOAT_SOG:
      case KEY_BOAT_SPEED:
      if (t->key == KEY_BOAT_SPEED)
        bs = t->value->int32;
      case KEY_TARGET_SPEED: 
      case KEY_CURRENT_SPEED:
      snprintf(bj, sizeof(buffer[0]),"%d.%d", abs((int)t->value->int32)/10, abs((int)t->value->int32) % 10);
      negNum = ((int)t->value->int32 < 0);
      break;
      
      case KEY_LINE_ANGLE: // If this is negative, we will be over the line early - red burn time
      a = t->value->int32;
      #ifdef PBL_COLOR
      highVMG = (a < 0);
      #endif
      a = abs(a);
      negNum = false;
      snprintf(bj, sizeof(buffer[0]),"%d", a);
      break;
      
      case KEY_MARK_DIST:
      case KEY_MARK_LAY_DIST:
      negNum = false;
      if (currentState != 1  && t->key == KEY_MARK_LAY_DIST)
        bj[0] = '\000';
      else
        {
        a = (int)t->value->int32;
        negNum = (a < 0);
        a = abs(a);
        b = a / 18.52;
        bool bf = isBigField((int)t->key);
        if (a < 1000) // Less than 1000m - just show m
          snprintf(bj, sizeof(buffer[0]), "%d", a);
        else if (b < 1000 || bf) // less than 100nm or it's a big field - show nm.n
          {
          int d1, d2, d3;
          d1 = (int)b/100;
          d2 = (((int)b % 100)/10);
          d3 = ((((int)b % 10) > 4) ? 1 : 0);
          if (d3 == 1)
            d2 += 1;
          if (d2 == 10)
            {
            d1 += 1;
            d2 = 0;
          }
          snprintf(bj, sizeof(buffer[0]), "%d.%d", d1, d2);
        }
        else
            {
            snprintf(bj, sizeof(buffer[0]), "%d", (int)b/10);
        }
      }
      break;
      
      case KEY_LAY_SEL:
      //APP_LOG(APP_LOG_LEVEL_INFO, "Key %d Value %d", (int)t->key, (int)t->value->int32);
      negNum = false;
      snprintf(bj, sizeof(buffer[0]),"%s", layDecode[(int)t->value->int32]);
      break;
      
      /* These are the turn style values - Rnn & Lnn */
      case KEY_MARK_TURN:
      case KEY_TACK_HEADER:
      negNum = false;
      if (currentState != 1 && t-> key == KEY_TACK_HEADER)
        bj[0] = '\000';
      else
        {
//        if (t->value->int32 >= 0)
          snprintf(bj, sizeof(buffer[0]), "%c%02d", t->value->int32 >= 0 ? 'R' : 'L', abs((int)t->value->int32));
//        else
//          snprintf(buffer[j], sizeof(buffer[j]), "L%02d", -(int)(t->value->int32));
      }
      break;
      
      case KEY_CURRENT_MARK:
      weAreRacing = true; //This data only arrives once the start is over, we must be racing
      negNum = false;
      sa = t->value->cstring;
      sb = tmpbuf;
             // APP_LOG(APP_LOG_LEVEL_ERROR, "Mark->%s", sa);
      while (*sa != '\000') {
        *sb = *sa; // Copy the current char
        if (*sb == ':' && *(sa+1) == ':') { // Found :: don't increment b so we ignore the extra :
          sa++;
          continue;
        }
        else if (*sb == ':' && *(sa+1) == '\000') { // End of string coming up & last char was : - don't increment b - it will be zapped
          sa++;
          continue;
        }
        else {
          sa++;
          sb++;
        }
      }
      *sb = '\000';
      snprintf(bj, sizeof(buffer[0]), "%s", tmpbuf);
      break;
      
      case KEY_TACK_STATE:
      a = (int)t->value->int32;
      negNum = a < 0;
      snprintf(bj, sizeof(buffer[0]), "%d", abs((int)(t->value->int32)));
      if (currentState == 1 && a != 1) // Just detected a tack
        {
        tackLog[0] = oldTack;
        int i;
        for (i = 6; i > 0; i--) // Shuffle them all up one
          tackLog[i] = tackLog[i-1];
      }
      currentState = a;
      // Now display the log
      int k = 1; // Start the log at 1 - 0 is the current tack ready to be shuffled up
      int i = 0;
      for (i=0; i < screens[currentScreen].num_fields; i++) // Go look for TACK LOG on the screen
      {
        if (keyTitles[screens[currentScreen].field_data_map[i]].key == KEY_TACK_LOG) // Tack Log is displayed
        {
          if (tackLog[k] == 0)
            tackLogBuffer[k][0] = '\000';
          else
            snprintf(tackLogBuffer[k], sizeof(tackLogBuffer[0]), "%d", tackLog[k]);
          setField(i, false, tackLogBuffer[k]);
          fieldUpdated[i] = true;
          k++; // Step to the next tacklog entry
        }
      }
      break;
      #ifdef CONFIG_SUPPORT
      case KEY_CONFIG_BOLD: useBold = (t->value->int32 != 0);
      foundKey = false;
      receivedConfig = true;
      break;
      
      case KEY_CONFIG_RACEBOX: racebox = t->value->int32;
      foundKey = false;
      receivedConfig = true;
      break;
      
      case KEY_CONFIG_VIBEDISCONNECT: vibeDisconnect = t->value->int32;
      foundKey = false;
      receivedConfig = true;
      break;
      
      
      case KEY_CONFIG_COLOURAWA: 
      #ifdef PBL_COLOR
        colourAWA = t->value->int32 != 0;
      #endif // PBL_COLOUR
      foundKey = false;
      receivedConfig = true;
      break;

      #endif //CONFIG_SUPPORT
      default:
      APP_LOG(APP_LOG_LEVEL_ERROR, "Key %d not recognized, value %d", (int)t->key, (int)t->value->int32);
      foundKey = false;
      break;
    }
    if (foundKey) // Now look through the fields on the current screen to see if it is displayed
      {
      #ifdef CONFIG_SUPPORT
      foundAKey = true;
      #endif
      if (t->key == KEY_LINE_BURN) // Do vibrate regardless of what is displayed
              {
              if (!earlyWarnDone && t->value->int32 < 10 && t->value->int32 >0)
                {
                vibes_double_pulse ();
                earlyWarnDone = true;
              }
              else if (t->value->int32 <= 0)
                {
                if (!warnedLineBurn)
                    {
                    vibes_long_pulse();
                    warnedLineBurn = true;
                }
              }
              else
                {
                warnedLineBurn = false;
              }
            }
                
      int i;
        for (i=0; i<screens[currentScreen].num_fields; i++)
          {
          if (weAreRacing && keyTitles[screens[currentScreen].field_data_map[i]].preStart) // We are racing & we have pre-start data displayed
              doScreenTransition = true; // Force a transition if we are racing with a screen displaying prestart data
          if (keyTitles[screens[currentScreen].field_data_map[i]].key == (int)t->key) // Did we find a match?
            { // To this point we have only decoded the message into the buffer
            setField(i, negNum, bj);  // Display the data - we found a match
            fieldUpdated[i] = true;
          }
        }
    // Use next buffer - the buffer remains in use even after the data actually appears on the screen
    // So we need to use a different buffer for each message.
      j++;
    }
    t = dict_read_next(iterator); // Look for next item
  }
#ifdef CONFIG_SUPPORT    
  if (receivedConfig) {
    screenMessageTimer = 3;
    screenMessage("Configuration received");
}
  if (foundAKey) {
  // Messages are still arriving
    if (tickCounter >= 7 && vibeDisconnect)
      vibes_double_pulse();
    tickCounter = 0;
  }
#endif    
  if (weAreRacing && doScreenTransition && holdThisScreen == 0) // We are racing, are showing some prestart data & don't need to hold this screen
    {
      do // Loop around looing for the next in use screen
        {
        currentScreen = (1 + currentScreen) % NUM_SCREENS;
      } while (screens[currentScreen].num_fields == 0);
    if (currentScreen == startingScreen)
      doScreenTransition = false; // Stop looking - we're back where we started!
    updatescreen(currentScreen, NULL); 
  }
  } while (weAreRacing && doScreenTransition && holdThisScreen == 0);
  
  int VMGtoWind;
  
  if (canDoVMG) {
    VMGtoWind = mycos(M_PI * ((hdg - twd) / 180.0)) * (bs * 10);
    VMGtoWind = VMGtoWind / 10 + (VMGtoWind % 10 >=5 ? 1 : 0);
    snprintf(VMGtoWindBuffer, sizeof(VMGtoWindBuffer), "%d.%d", abs(VMGtoWind)/10, abs(VMGtoWind)%10);
  }
  
  // Post process screen fields - VMGWind, blank non-updated fields etc.
  for (ii = 0; ii < screens[currentScreen].num_fields; ii++) {
    int fieldKeyTitle = keyTitles[screens[currentScreen].field_data_map[ii]].key;
    if (canDoVMG) {
      if (fieldKeyTitle == KEY_VMG_WIND) {
        setField(ii, false, VMGtoWindBuffer);  
        fieldUpdated[ii] = true;
      }
    }
    #ifdef PBL_COLOR
    if ((fieldKeyTitle == KEY_LINE_BURN && highVMG) || (colourAWA && (fieldKeyTitle == KEY_AWA || fieldKeyTitle == KEY_TWA) && redAWA)) {
      // APP_LOG(APP_LOG_LEVEL_ERROR, "High VMG/AWA Port in post process");
      text_layer_set_text_color(s_data_layer[screens[currentScreen].field_layer_map[ii]], redTextColour); 
    }
    else if (colourAWA && (fieldKeyTitle == KEY_AWA || fieldKeyTitle == KEY_TWA) && !redAWA) {
      // APP_LOG(APP_LOG_LEVEL_ERROR, "AWA Starboard in post process");
      text_layer_set_text_color(s_data_layer[screens[currentScreen].field_layer_map[ii]], greenTextColour);       
    }
    #endif
    if (!fieldUpdated[ii])
      {
      setField(ii, false, ""); // If a field has not been updated, blank it out - it will be mapped to the wrong buffer[] element
    }
  }
  
}
Beispiel #25
0
static void main_window_load(Window *window) {
  
  //APP_LOG(APP_LOG_LEVEL_ERROR, "In Main_window_load");
  // Use system font, apply it and add to Window
  s_3_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_PTN_64));
  s_2_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_PTN_59));
  s_4_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_PTN_50));
  s_6_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_PTN_47));
 
  
  s_title_font = fonts_get_system_font(FONT_KEY_GOTHIC_14);
  s_large_title_font = fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD);
  s_medium_title_font = fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD);

  inverter = inverter_layer_create(GRect(0,0,144,168));
  layer_set_bounds(inverter_layer_get_layer(inverter),GRectZero);
  
  flash = inverter_layer_create(GRect(2,7,7,7));
  
  int jj;
  for (jj = 0; jj < 6; jj++) {
  dataInverter[jj] = inverter_layer_create(GRect(0,0,144,168));
  layer_set_bounds(inverter_layer_get_layer(dataInverter[jj]),GRectZero);  
  }
  
  // Create Display RectAngles
  
  // Six data fields & their titles
  #define SIX_FIELD_INDEX 0
  #define SIX_FIELD_MAX 5
  s_data_layer[0] = text_layer_create(GRect(0, 2, 71, 49));
  s_data_title[0] = text_layer_create(GRect(0, 49, 71, 15));

  s_data_layer[1] = text_layer_create(GRect(73, 2, 71, 49));
  s_data_title[1] = text_layer_create(GRect(73, 49, 71, 15));
  
  s_data_layer[2] = text_layer_create(GRect(0, 53, 71, 49));
  s_data_title[2] = text_layer_create(GRect(0, 102, 71, 14));
  
  s_data_layer[3] = text_layer_create(GRect(73, 53, 71, 49));
  s_data_title[3] = text_layer_create(GRect(73, 102, 71, 14));
  
  s_data_layer[4] = text_layer_create(GRect(0, 105, 71, 49));
  s_data_title[4] = text_layer_create(GRect(0, 154, 71, 15));
  
  s_data_layer[5] = text_layer_create(GRect(73, 105, 71, 49));
  s_data_title[5] = text_layer_create(GRect(73, 154, 71, 15));
  
  // Two data fields & their titles
  #define TWO_FIELD_INDEX 6
  #define TWO_FIELD_MAX 7
  s_data_layer[6] = text_layer_create(GRect(0, 2, 288, 60));
  layer_set_frame((Layer *) s_data_layer[6], GRect(0, 2, 144, 60));
  s_data_title[6] = text_layer_create(GRect(0, 64, 144, 28));
  
  s_data_layer[7] = text_layer_create(GRect(0, 79, 288, 60));
  layer_set_frame((Layer *) s_data_layer[7], GRect(0, 79, 144, 60));
  s_data_title[7] = text_layer_create(GRect(0, 140, 144, 28));

  
  // Four data fields & their titles
  #define FOUR_FIELD_INDEX 8
  #define FOUR_FIELD_MAX 11
  s_data_layer[8] = text_layer_create(GRect(0, 12, 142, 51));
  layer_set_frame((Layer *) s_data_layer[8], GRect(0, 12, 71, 51));
  s_data_title[8] = text_layer_create(GRect(0, 65, 71, 24));
  
  s_data_layer[9] = text_layer_create(GRect(73, 12, 71, 51));
  s_data_title[9] = text_layer_create(GRect(73, 65, 71, 24));
  
  s_data_layer[10] = text_layer_create(GRect(0, 91, 142, 51));
  layer_set_frame((Layer *) s_data_layer[10], GRect(0, 91, 71, 51));
  s_data_title[10] = text_layer_create(GRect(0, 144, 71, 24));
  
  s_data_layer[11] = text_layer_create(GRect(73, 91,  71, 51));
  s_data_title[11] = text_layer_create(GRect(73, 144, 71, 24));
  
  // Three fields - One big, two small
  //#define THREE_FIELD_INDEX 12
  #define THREE_FIELD_MAX 14
  s_data_layer[12] = text_layer_create(GRect(0, 10, 432, 65));
  layer_set_frame((Layer *) s_data_layer[12], GRect(0, 10, 144, 65));
  s_data_title[12] = text_layer_create(GRect(0, 75, 144, 28));

  s_data_layer[13] = text_layer_create(GRect(0, 91, 150, 51));
  layer_set_frame((Layer *) s_data_layer[13], GRect(0, 91, 71, 51));
  s_data_title[13] = text_layer_create(GRect(0, 144, 71, 24));
  
  
  //s_data_layer[14] = text_layer_create(GRect(73, 91, 142, 51));
  //layer_set_frame((Layer *) s_data_layer[14], GRect(73, 91, 71, 51));
  s_data_layer[14] = text_layer_create(GRect(73, 91,  71, 51));
  s_data_title[14] = text_layer_create(GRect(73, 144, 71, 24));
  
  
  // Top title
  s_data_layer[TITLE_INDEX] = text_layer_create(GRect(0, 0, 144, 16));
  
  

  // Set up top title area
    text_layer_set_background_color(s_data_layer[TITLE_INDEX], GColorBlack);
    text_layer_set_text_color(s_data_layer[TITLE_INDEX], GColorWhite);
    text_layer_set_text_alignment(s_data_layer[TITLE_INDEX], GTextAlignmentCenter);
    text_layer_set_text(s_data_layer[TITLE_INDEX], "StartLine");
    text_layer_set_font(s_data_layer[TITLE_INDEX], s_title_font);
    layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_data_layer[TITLE_INDEX])); 
 
  window_set_background_color(window, GColorBlack);
  // Set up the messgage layer
  messageLayer = text_layer_create(GRect(10,30,124,120));
  text_layer_set_background_color(messageLayer, GColorClear);
  text_layer_set_text_color(messageLayer, GColorWhite);
  text_layer_set_text_alignment(messageLayer, GTextAlignmentCenter);
  text_layer_set_font(messageLayer, s_large_title_font);
  
  

  
  titleLayer = layer_create(GRect(0, 0, 144, 168));
  layer_insert_below_sibling(titleLayer, (Layer *)s_data_layer[TITLE_INDEX]);
  
  
  dataLayer = layer_create(GRect(0, 0, 144, 168));
  layer_insert_below_sibling(dataLayer, titleLayer); 
 
  
  int i;
  for (i =0; i < TITLE_INDEX; i++)
    {
    //Data

    text_layer_set_background_color(s_data_layer[i], GColorClear);
    text_layer_set_text_color(s_data_layer[i], GColorWhite);
    text_layer_set_text_alignment(s_data_layer[i], GTextAlignmentCenter);
    text_layer_set_overflow_mode(s_data_layer[i], GTextOverflowModeWordWrap);
    layer_add_child(dataLayer, text_layer_get_layer(s_data_layer[i]));
    
    //Title

    text_layer_set_background_color(s_data_title[i], GColorClear);
    text_layer_set_text_color(s_data_title[i], GColorWhite);
    text_layer_set_text_alignment(s_data_title[i], GTextAlignmentCenter);
    
    if (i >= SIX_FIELD_INDEX && i <= SIX_FIELD_MAX) // Small title fonts on the 6 field layout
      {
      text_layer_set_font(s_data_layer[i], s_6_font);    
      text_layer_set_font(s_data_title[i], s_title_font);
    }
    else if (i >= TWO_FIELD_INDEX && i <= TWO_FIELD_MAX) // This is 2 fields
      {
      text_layer_set_font(s_data_layer[i], s_2_font); 
      text_layer_set_font(s_data_title[i], s_large_title_font);
    }

    else if (i >= FOUR_FIELD_INDEX && i <= FOUR_FIELD_MAX) // 4 field layout
      {
      text_layer_set_font(s_data_layer[i], s_4_font); 
      text_layer_set_font(s_data_title[i], s_medium_title_font);
    }
    else if (i >= THREE_FIELD_INDEX && i <= THREE_FIELD_MAX)
      {
      if (i == THREE_FIELD_INDEX) // First field is big
        {
        text_layer_set_font(s_data_layer[i], s_3_font); 
        text_layer_set_font(s_data_title[i], s_large_title_font);
      } else
        {
        text_layer_set_font(s_data_layer[i], s_4_font);    
        text_layer_set_font(s_data_title[i], s_medium_title_font);        
      }
    }      
   
    layer_add_child(titleLayer, text_layer_get_layer(s_data_title[i]));
    
  }
  
 layer_add_child(window_get_root_layer(window), inverter_layer_get_layer(inverter));


  int ii;
  for (ii = 0; ii < 6; ii++) {
     layer_add_child(window_get_root_layer(window), inverter_layer_get_layer(dataInverter[ii]));
  }
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(messageLayer)); 

   layer_add_child(window_get_root_layer(window), inverter_layer_get_layer(flash));

  
  // Go find a screen with some fields in use
  for (currentScreen = 0; screens[currentScreen].num_fields == 0; currentScreen++)
    ;

  // Add the padlock icon - steals the rest of my heap!!
  s_padlockLayer = bitmap_layer_create(GRect(133, 3, 8, 11));
  s_res_padlock = gbitmap_create_with_resource(RESOURCE_ID_PADLOCK);
  bitmap_layer_set_bitmap(s_padlockLayer, s_res_padlock);
  layer_add_child(window_get_root_layer(window), (Layer *)s_padlockLayer);
  layer_set_hidden((Layer *)s_padlockLayer, configLock == 1);
  
  // And make it the current screen
  updatescreen(currentScreen,"00");
}
Beispiel #26
0
void setField(int i /* Field Index */,  bool negNum, char* value)
  {
  static PropertyAnimation *pa1[6] = {NULL}, *pa2[6] = {NULL}; //Arrays to cope with 6 fields
    {
    static GSize textContent;
    static GRect gfrom, gto, gframe;
    TextLayer *flm = s_data_layer[screens[currentScreen].field_layer_map[i]];
    text_layer_set_text_alignment(flm, GTextAlignmentLeft);
    text_layer_set_text(flm, value); // This line only
    textContent = text_layer_get_content_size(flm);
    gfrom = layer_get_bounds((Layer *)flm);
    gframe = layer_get_frame((Layer *)flm);
    
    // APP_LOG(APP_LOG_LEVEL_INFO, "gframe.size.w=%d textContent.w=%d i=%d", gframe.size.w, textContent.w, i);
    if (textContent.w > gframe.size.w) // Overflowed
      {
      // APP_LOG(APP_LOG_LEVEL_INFO, "setfield11 value=%s", value);
      if ( (pa1[i] == NULL || !animation_is_scheduled((Animation*)pa1[i])) 
          && (pa2[i] == NULL || !animation_is_scheduled((Animation*) pa2[i]))) // We are not already animating
        {
        // APP_LOG(APP_LOG_LEVEL_INFO, "setField 10");
        gto = gfrom;
        gfrom.origin.x = 0;
        gto.origin.x = (gframe.size.w - textContent.w)/2; //Work out har far left to move animate the text
        // APP_LOG(APP_LOG_LEVEL_INFO, "setField11 gfrom.x=%d gfrom.y=%d", gfrom.origin.x, gfrom.origin.y);
        // APP_LOG(APP_LOG_LEVEL_INFO, "setField11 gto.x=%d gto.y=%d", gto.origin.x, gto.origin.y);
        int tim = (int)(-2000.0 * ((float)gto.origin.x) / 20.0);
        animate_layer_bounds(&pa1[i], (Layer *)flm, &gfrom, &gto, tim, 0);
        animate_layer_bounds(&pa2[i], (Layer *)flm, &gto, &gfrom, tim, tim);
        }
      else
        {
        //APP_LOG(APP_LOG_LEVEL_INFO, "Already scheduled screen=%d i=%d %d %d %d %d", currentScreen, i, (int)pa1[i], animation_is_scheduled((Animation*)pa1[i]), (int)pa2[i], animation_is_scheduled((Animation*)pa2[i]) );
        text_layer_set_text(flm, value); // Animation running - just set the text
      }
    }
    else // We need to redraw the text centred in the reset bounds
      {
      // APP_LOG(APP_LOG_LEVEL_INFO, "setfield11 value=%s", value);
      GRect bF = layer_get_bounds((Layer *)flm);
      GRect fF = layer_get_frame((Layer *)flm);
      if (bF.size.w != fF.size.w) // is there extra space?
        {
        bF.origin.x = -(bF.size.w / 2 - fF.size.w / 2) /2;
        // APP_LOG(APP_LOG_LEVEL_INFO, "origin.x =%d", bF.origin.x);
        layer_set_bounds((Layer *)flm, bF); // Centre the Bounds below the Frame
      }
      text_layer_set_text_alignment(flm, GTextAlignmentCenter); //Should be Center but need to work out how!
      text_layer_set_text(flm, value); // This line only
    }
    
  }
  if (negNum) // Did we get a negative number
  {
    doDataInvert(i);
  } 
  else // No, positive number
  {
    doDataRevert(i);
  }
}