Exemplo n.º 1
0
MenuIndex get_current_session_from_time() {
    time_t now = time(NULL);
    struct tm *tm_now = localtime(&now);
    MenuIndex current = {.section = 0, .row = 0};
    if (tm_now->tm_mon != event_month - 1 || tm_now->tm_mday != event_day) {
        return current;
    }
    for(int ts_idx=0; ts_idx<schedule.num_slots; ts_idx++) {
        TimeSlot *ts = &schedule.slots[ts_idx];
        if (tm_now->tm_hour < ts->start_hour) {
            break;
        } else if(tm_now->tm_hour == ts->start_hour && tm_now->tm_min < ts->start_min) {
            break;
        }
        current.section = ts_idx;
    }
    return current;
}

MenuIndex get_current_session_from_args() {
    int args = launch_get_args();
    MenuIndex current = {.section = args / 10, .row = args % 10};
    return current;
}

MenuIndex get_current_session() {
    #ifdef PBL_COLOR
    if (launch_reason() == APP_LAUNCH_TIMELINE_ACTION && launch_get_args() > 0) {
        return get_current_session_from_args();
    }
    #endif
    return get_current_session_from_time();
}

static void main_window_load(Window *window) {
  Layer *window_layer = window_get_root_layer(window);
  GRect bounds = layer_get_frame(window_layer);

  menu_schedule = menu_layer_create(bounds);

  #ifdef PBL_COLOR
  menu_layer_set_normal_colors(menu_schedule, ROW_BG_COLOR, ROW_FG_COLOR);
  menu_layer_set_highlight_colors(menu_schedule, HIGHLIGHT_BG_COLOR, HIGHLIGHT_FG_COLOR);
  #endif

  menu_layer_set_callbacks(menu_schedule, NULL, (MenuLayerCallbacks) {
    .get_num_sections = menu_get_num_sections_callback,
    .get_num_rows = menu_get_num_rows_callback,
    .get_header_height = menu_get_header_height_callback,
    .get_cell_height = menu_get_height_callback,
    .draw_header = menu_draw_header_callback,
    .draw_row = menu_draw_row_callback,
    .select_click = menu_select_callback,
  });

  menu_layer_set_click_config_onto_window(menu_schedule, window);
  MenuIndex idx = get_current_session();
  menu_layer_set_selected_index(menu_schedule, idx, MenuRowAlignCenter, false);
  layer_add_child(window_layer, menu_layer_get_layer(menu_schedule));
}
Exemplo n.º 2
0
/*
 * Create main window
 */
static void handle_init() {
  // Check which defines are defined
  #ifdef PBL_SDK_3
  LOG_INFO("PBL_SDK_3");
  #endif
  #ifdef PBL_PLATFORM_APLITE
  LOG_INFO("PBL_PLATFORM_APLITE");
  #endif
  #ifdef PBL_PLATFORM_BASALT
  LOG_INFO("PBL_PLATFORM_BASALT");
  #endif
  #ifdef PBL_PLATFORM_CHALK
  LOG_INFO("PBL_PLATFORM_CHALK");
  #endif
  #ifdef PBL_COLOR
  LOG_INFO("PBL_COLOR");
  #endif
  #ifdef PBL_BW
  LOG_INFO("PBL_BW");
  #endif
  #ifdef PBL_ROUND
  LOG_INFO("PBL_ROUND");
  #endif
  #ifdef PBL_RECT
  LOG_INFO("PBL_RECT");
  #endif
  
  // Create primary window
  ui.primary_window = window_create();

  // Go straight to chart if needed
#ifdef ENABLE_CHART_VIEWER
  if (launch_reason() == APP_LAUNCH_TIMELINE_ACTION && launch_get_args() == TIMELINE_LAUNCH_CHART) {
     window_set_window_handlers(ui.primary_window, (WindowHandlers ) { .load = chart_load, .unload = chart_unload });
Exemplo n.º 3
0
static void in_received_handler(DictionaryIterator *iter, void *context) {
  Tuple *tuple;

  // send the launch_arg when we receive ready from JS
  tuple = dict_find(iter, APP_KEY_READY);
  if (tuple) {
    DictionaryIterator *iter;
    app_message_outbox_begin(&iter);
    dict_write_uint32(iter, APP_KEY_ACTION, launch_get_args());
    dict_write_end(iter);
    app_message_outbox_send();
  }

  // update text
  tuple = dict_find(iter, APP_KEY_TEXT);
  if (tuple) {
    snprintf(text, sizeof(text), "%s", tuple->value->cstring);
    text_layer_set_text(text_layer, text);
  }

  // quit the app
  tuple = dict_find(iter, APP_KEY_QUIT);
  if (tuple) {
    window_stack_pop_all(false);
  }
}
Exemplo n.º 4
0
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
}