Exemplo n.º 1
0
static void select_click_handler(ClickRecognizerRef recognizer, void *context) {
  // Check to see if the worker is currently active
  bool running = app_worker_is_running();

  // Toggle running state
  AppWorkerResult result;
  if(running) {
    result = app_worker_kill();

    if(result == APP_WORKER_RESULT_SUCCESS) {
      text_layer_set_text(s_ticks_layer, "Worker stopped!");
    } else {
      text_layer_set_text(s_ticks_layer, "Error killing worker!");
    }
  } else {
    result = app_worker_launch();

    if(result == APP_WORKER_RESULT_SUCCESS) {
      text_layer_set_text(s_ticks_layer, "Worker launched!");
    } else {
      text_layer_set_text(s_ticks_layer, "Error launching worker!");
    }
  }

  APP_LOG(APP_LOG_LEVEL_INFO, "Result: %d", result);
}
Exemplo n.º 2
0
// worker functions
static void launch_background_worker(void) {
    if (app_worker_is_running()) return; // already running
    switch (app_worker_launch()) {
        case APP_WORKER_RESULT_SUCCESS: break;
        case APP_WORKER_RESULT_NO_WORKER: APP_LOG(APP_LOG_LEVEL_ERROR, "launch_background_worker: APP_WORKER_RESULT_NO_WORKER"); break;
        case APP_WORKER_RESULT_NOT_RUNNING: APP_LOG(APP_LOG_LEVEL_ERROR, "launch_background_worker: APP_WORKER_RESULT_NOT_RUNNING"); break;
        case APP_WORKER_RESULT_ALREADY_RUNNING: APP_LOG(APP_LOG_LEVEL_ERROR, "launch_background_worker: APP_WORKER_RESULT_ALREADY_RUNNING"); break;
        case APP_WORKER_RESULT_DIFFERENT_APP: APP_LOG(APP_LOG_LEVEL_ERROR, "launch_background_worker: APP_WORKER_RESULT_DIFFERENT_APP"); break;
        case APP_WORKER_RESULT_ASKING_CONFIRMATION: APP_LOG(APP_LOG_LEVEL_ERROR, "launch_background_worker: APP_WORKER_RESULT_ASKING_CONFIRMATION"); break;
        default: APP_LOG(APP_LOG_LEVEL_ERROR, "launch_background_worker: UNKNOWN ERROR WHILE LAUNCHING BACKGROUND WORKER"); break;
    }
}
Exemplo n.º 3
0
static void window_appear(Window *window){
  tick_timer_service_subscribe(MINUTE_UNIT, handle_minute_tick);
  handle_minute_tick(NULL, MINUTE_UNIT);
  
   bool running = app_worker_is_running();
 
  if (running) {
     APP_LOG(APP_LOG_LEVEL_DEBUG, "Worker Running do nothing");
   //result= app_worker_kill();
  } else {
     APP_LOG(APP_LOG_LEVEL_DEBUG, "Worker stopped");
     app_worker_launch();
  }

}
Exemplo n.º 4
0
static void select_click_handler(ClickRecognizerRef recognizer, void *context) {


  bool running = app_worker_is_running();

  if (running){
    get_step_count();

    static char step_count[] = "9999";
    snprintf(step_count, sizeof("9999"), "%d", s_worker_steps);
    
    text_layer_set_text(text_layer, step_count);
  }else{
    text_layer_set_text(text_layer, "Not Running");
  }

  
}
Exemplo n.º 5
0
//---------------------------------------------------------------------------------
// Click Handlers
//---------------------------------------------------------------------------------
//------- Select Click Handlers ----------
static void select_click_handler(ClickRecognizerRef recognizer, void *context) {
    // Toggle running state
    if (app_worker_is_running()) {
        if (app_worker_kill() == APP_WORKER_RESULT_SUCCESS) {
            text_layer_set_text(text_layer, "Worker stopped!");
            APP_LOG(APP_LOG_LEVEL_INFO, "Worker Stopped");
        } else {
            text_layer_set_text(text_layer, "Error killing worker!");
            APP_LOG(APP_LOG_LEVEL_INFO, "Error Killing Worker");
        }
    } else {
        if (app_worker_launch() == APP_WORKER_RESULT_SUCCESS) {
            text_layer_set_text(text_layer, "Worker launched!");
            APP_LOG(APP_LOG_LEVEL_INFO, "Worker Launched");
        } else {
            text_layer_set_text(text_layer, "Error launching worker!");
            APP_LOG(APP_LOG_LEVEL_INFO, "Error Launching Worker");
        }
    }
}
Exemplo n.º 6
0
// load from beginning to end (to calculate runtimes) and put the text allways onto the top:
static void load_data(void){
  time_t time_stamp = 0;
  time_t period_since_begin = 0;
  time_t period_since_last_event = 0;
  
  if (app_worker_is_running()){
    snprintf(text_header, sizeof(text_header), "Worker is running\nLaunch result = %d\n%s", (int)AWresult, text_devider);
  } else {
    snprintf(text_header, sizeof(text_header), "Worker is NOT running\nLaunch result = %d\n%s", (int)AWresult, text_devider);
  }
  strcpy(text, "");
  //snprintf(text, TEXT_LENGTH, "%s", text_header);
  
  int read_pos = -1, write_pos = -1;
  int key = KEY_CURRENT_INDEX;
  int number_of_entries_read = 0;
  if (persist_exists(key)){
    read_pos = persist_read_int(key);
    write_pos = read_pos; //save which was the write_pos from the worker
    while (1){
      
      read_pos++;
      if (read_pos > NUMBER_OF_ENTRIES) read_pos = 0;
      if (read_pos < 0) read_pos = NUMBER_OF_ENTRIES-1;
      
      key = KEY_EVENT_STRING_001+read_pos;
      if (persist_exists(key)){
        uint8_t byte_array[3];
        persist_read_data(key, byte_array, sizeof(byte_array));
        
        //read time stamp:
        key = KEY_EVENT_TIME_STAMP_001+read_pos;
        if (persist_exists(key)){
          time_stamp = (time_t)persist_read_int(key);
          struct tm* loctime = localtime(&time_stamp);
          strftime(time_str, sizeof(time_str), "%Y-%m-%d_%H:%M:%S:\n", loctime);
          number_of_entries_read++;
        } else {
          snprintf(time_str, sizeof(time_str), "no time stamp found:\n");
          time_stamp = 0;
        }
        switch (byte_array[0]){ //message
          case 1: 
          case 2:
          case 3:
            period_begin = time_stamp;
            strcpy(text_buffer, text);
            snprintf(text, sizeof(text), "%s%s", text_devider, text_buffer);
            break;
        }
        period_since_begin = time_stamp - period_begin;
        period_since_last_event = time_stamp - last_event;
        if (byte_array[0] > 0) last_event = time_stamp;
        
        print_time(time1_str, sizeof(time1_str), period_since_begin, 0);
        print_time(time2_str, sizeof(time2_str), period_since_last_event, 0);
        
        strcpy(text_buffer, text);
        snprintf(text, TEXT_LENGTH, "%s    %d: %d %% --> %d %%\n    %s [%s]\n%s", time_str, byte_array[0], byte_array[2], byte_array[1], time1_str, time2_str, text_buffer);
      }
      
      if (read_pos == write_pos) break;
      if (number_of_entries_read > NUMBER_OF_ENTRIES_TO_SHOW) break;
    }
    
    strcpy(text_buffer, text);
    snprintf(text, TEXT_LENGTH, "%s%s\n", text_header, text_buffer);
  } else {
    snprintf(text, TEXT_LENGTH, "%sNo data found.\n", text_header);
  }
  
  text_layer_set_size(text_layer, GSize(bounds.size.w, 2000));
  text_layer_set_text(text_layer, text); 
  GSize max_size = text_layer_get_content_size(text_layer);
  text_layer_set_size(text_layer, max_size);
  scroll_layer_set_content_size(scroll_layer, GSize(bounds.size.w, max_size.h + 4 + STATUS_HIGH));
}