Esempio n. 1
0
void chrono_start_stop_handler(ClickRecognizerRef recognizer, void *context) {
  Window *window = (Window *)context;
  unsigned int ms = get_time_ms();

  // The start/stop button was pressed.
  if (chrono_data.running) {
    // If the chronograph is currently running, this means to stop (or
    // pause).
    chrono_data.hold_ms = ms - chrono_data.start_ms;
    chrono_data.running = false;
    chrono_data.lap_paused = false;
    vibes_enqueue_custom_pattern(chrono_tap);
    update_hands(NULL);
    reset_tick_timer();

    // We change the click config provider according to the chrono run
    // state.  When the chrono is stopped, we listen for a different
    // set of buttons than when it is started.
    window_set_click_config_provider(window, &stopped_click_config_provider);
    if (chrono_digital_window != NULL) {
      window_set_click_config_provider(chrono_digital_window, &stopped_click_config_provider);
    }
  } else {
    // If the chronograph is not currently running, this means to
    // start, from the currently showing Chronograph time.
    chrono_data.start_ms = ms - chrono_data.hold_ms;
    chrono_data.running = true;
#if ENABLE_SWEEP_SECONDS
    if (config.sweep_seconds) {
      if (sweep_chrono_seconds_ms < sweep_timer_ms) {
        sweep_timer_ms = sweep_chrono_seconds_ms;
      }
    }
#endif  // ENABLE_SWEEP_SECONDS
    vibes_enqueue_custom_pattern(chrono_tap);
    update_hands(NULL);
    reset_tick_timer();

    window_set_click_config_provider(window, &started_click_config_provider);
    if (chrono_digital_window != NULL) {
      window_set_click_config_provider(chrono_digital_window, &started_click_config_provider);
    }
  }
}
Esempio n. 2
0
// Updates any runtime settings as needed when the config changes.
void apply_config() {
  app_log(APP_LOG_LEVEL_INFO, __FILE__, __LINE__, "apply_config");

  // Reset the memory panic count when we get a new config setting.
  // Maybe the user knows what he's doing.
  memory_panic_count = 0;

  if (face_index != config.face_index) {
    // Update the face bitmap if it's changed.
    face_index = config.face_index;
    bwd_destroy(&clock_face);

    // Also move any layers to their new position on this face.
    for (int i = 0; i < NUM_DATE_WINDOWS; ++i) {
      const struct IndicatorTable *window = &date_windows[i][config.face_index];
      layer_set_frame((Layer *)date_window_layers[i], GRect(window->x - 19, window->y - 8, 39, 19));
    }

    {
      const struct IndicatorTable *window = &battery_table[config.face_index];
      move_battery_gauge(window->x, window->y, window->invert, window->opaque);
    }
    {
      const struct IndicatorTable *window = &bluetooth_table[config.face_index];
      move_bluetooth_indicator(window->x, window->y, window->invert, window->opaque);
    }
  }

  if (display_lang != config.display_lang) {
    // Unload the day font if it changes with the language.
    if (date_lang_font != NULL && (display_lang == -1 || lang_table[display_lang].font_index != lang_table[config.display_lang].font_index)) {
      app_log(APP_LOG_LEVEL_INFO, __FILE__, __LINE__, "apply_config unload date_lang_font %p", date_lang_font);
      safe_unload_custom_font(&date_lang_font);
    }

    // Reload the weekday, month, and ampm names from the appropriate
    // language resource.
    fill_date_names(date_names, NUM_DATE_NAMES, date_names_buffer, DATE_NAMES_MAX_BUFFER, lang_table[config.display_lang].date_name_id);

    display_lang = config.display_lang;
  }

#ifdef SUPPORT_MOON
  // Reload the moon bitmap just for good measure.  Maybe the user
  // changed the draw mode or the lunar direction.
  bwd_destroy(&moon_bitmap);
#endif  // SUPPORT_MOON

  layer_mark_dirty(clock_face_layer);

  reset_tick_timer();
}
Esempio n. 3
0
void chrono_reset_button() {
  // Resets the chronometer to 0 time.
  time_t now;
  struct tm *this_time;

  now = time(NULL);
  this_time = localtime(&now);
  chrono_data.running = false;
  chrono_data.lap_paused = false;
  chrono_data.start_ms = 0;
  chrono_data.hold_ms = 0;
  memset(&chrono_data.laps[0], 0, sizeof(chrono_data.laps[0]) * CHRONO_MAX_LAPS);
  vibes_double_pulse();
  update_chrono_laps_time();
  update_hands(this_time);
  reset_tick_timer();
}