Exemple #1
0
void update_chrono_hands(struct HandPlacement *new_placement) {
#ifdef ENABLE_CHRONO_MINUTE_HAND
  if (new_placement->chrono_minute_hand_index != current_placement.chrono_minute_hand_index) {
    current_placement.chrono_minute_hand_index = new_placement->chrono_minute_hand_index;
    layer_mark_dirty(clock_face_layer);

    if (config.second_hand) {
      // If the second hand is enabled, the hour and minute hands are
      // baked into the clock face cache, which must be redrawn now.
      invalidate_clock_face();
    }
  }
#endif  // ENABLE_CHRONO_MINUTE_HAND

#ifdef ENABLE_CHRONO_SECOND_HAND
  if (new_placement->chrono_second_hand_index != current_placement.chrono_second_hand_index) {
    current_placement.chrono_second_hand_index = new_placement->chrono_second_hand_index;
    layer_mark_dirty(clock_face_layer);
  }
#endif  // ENABLE_CHRONO_SECOND_HAND

#ifdef ENABLE_CHRONO_TENTH_HAND
  if (new_placement->chrono_tenth_hand_index != current_placement.chrono_tenth_hand_index) {
    current_placement.chrono_tenth_hand_index = new_placement->chrono_tenth_hand_index;
    layer_mark_dirty(clock_face_layer);

    if (config.second_hand) {
      // If the second hand is enabled, the hour and minute hands are
      // baked into the clock face cache, which must be redrawn now.
      invalidate_clock_face();
    }
  }
#endif  // ENABLE_CHRONO_TENTH_HAND

#if ENABLE_SWEEP_SECONDS
  if (config.sweep_seconds) {
    if (chrono_data.running && !chrono_data.lap_paused && !chrono_digital_window_showing) {
      // With the chronograph running, the sweep timer must be fast
      // enough to capture the chrono second hand.
      if (sweep_chrono_seconds_ms < sweep_timer_ms) {
        sweep_timer_ms = sweep_chrono_seconds_ms;
      }
    }
  }
#endif  // ENABLE_SWEEP_SECONDS
}
// We have to poll the quiet_time_is_active() state from time to
// time because Pebble doesn't provide a callback handler for this.
bool poll_quiet_time_state() {
  bool new_quiet_time_state = quiet_time_is_active();
  if (quiet_time_state == new_quiet_time_state) {
    // No change.
    return quiet_time_state;
  }

  quiet_time_state = new_quiet_time_state;
  qapp_log(APP_LOG_LEVEL_INFO, __FILE__, __LINE__, "quiet_time changed to %d", quiet_time_state);

  if (config.bluetooth_indicator != IM_off) {
    invalidate_clock_face();
  }
  return quiet_time_state;
}
// Update the bluetooth guage.
static void handle_bluetooth(bool new_bluetooth_state) {
  if (got_bluetooth_state && bluetooth_state == new_bluetooth_state) {
    // No change; ignore the update.
    qapp_log(APP_LOG_LEVEL_INFO, __FILE__, __LINE__, "bluetooth update received, no change to bluetooth");
    return;
  }

  bluetooth_state = new_bluetooth_state;
  got_bluetooth_state = true;
  qapp_log(APP_LOG_LEVEL_INFO, __FILE__, __LINE__, "bluetooth changed to %d", bluetooth_state);

  if (config.bluetooth_indicator != IM_off) {
    invalidate_clock_face();
  }
}
Exemple #4
0
void compute_chrono_hands(unsigned int ms, struct HandPlacement *placement) {
  unsigned int chrono_ms = get_chrono_ms(ms);

  bool chrono_dial_wants_tenths = true;
  switch (config.chrono_dial) {
  case CDM_off:
    break;

  case CDM_tenths:
    chrono_dial_wants_tenths = true;
    break;

  case CDM_hours:
    chrono_dial_wants_tenths = false;
    break;

  case CDM_dual:
    // In dual mode, we show either tenths or hours, depending on the
    // amount of elapsed time.  Less than 30 minutes shows tenths.
    chrono_dial_wants_tenths = (chrono_ms < 30 * 60 * 1000);
    break;
  }

  if (chrono_dial_shows_tenths != chrono_dial_wants_tenths) {
    // The dial has changed states; reload and redraw it.
    chrono_dial_shows_tenths = chrono_dial_wants_tenths;
    bwd_destroy(&chrono_dial_white);
    invalidate_clock_face();
  }
    
#ifdef ENABLE_CHRONO_MINUTE_HAND
  // The chronograph minute hand rolls completely around in 30
  // minutes (not 60).
  {
    unsigned int use_ms = chrono_ms % (1800 * 1000);
    placement->chrono_minute_hand_index = ((NUM_STEPS_CHRONO_MINUTE * use_ms) / (1800 * 1000)) % NUM_STEPS_CHRONO_MINUTE;
  }
#endif  // ENABLE_CHRONO_MINUTE_HAND

#ifdef ENABLE_CHRONO_SECOND_HAND
  {
    // Avoid overflowing the integer arithmetic by pre-constraining
    // the ms value to the appropriate range.
    unsigned int use_ms = chrono_ms % (60 * 1000);
    if (!config.sweep_seconds) {
      // Also constrain to an integer second if we've not enabled sweep-second resolution.
      use_ms = (use_ms / 1000) * 1000;
    }
    placement->chrono_second_hand_index = ((NUM_STEPS_CHRONO_SECOND * use_ms) / (60 * 1000));
  }
#endif  // ENABLE_CHRONO_SECOND_HAND

#ifdef ENABLE_CHRONO_TENTH_HAND
  if (config.chrono_dial == CDM_off) {
    // Don't keep updating this hand if we're not showing it anyway.
    placement->chrono_tenth_hand_index = 0;
  } else {
    if (chrono_dial_shows_tenths) {
      // Drawing tenths-of-a-second.
      if (chrono_data.running && !chrono_data.lap_paused) {
	// We don't actually show the tenths time while the chrono is running.
	placement->chrono_tenth_hand_index = 0;
      } else {
	// We show the tenths time when the chrono is stopped or showing
	// the lap time.
	unsigned int use_ms = chrono_ms % 1000;
	// Truncate to the previous 0.1 seconds (100 ms), just to
	// make the dial easier to read.
	use_ms = 100 * (use_ms / 100);
	placement->chrono_tenth_hand_index = ((NUM_STEPS_CHRONO_TENTH * use_ms) / (1000)) % NUM_STEPS_CHRONO_TENTH;
      }
    } else {
      // Drawing hours.  12-hour scale.
      unsigned int use_ms = chrono_ms % (12 * SECONDS_PER_HOUR * 1000);
      placement->chrono_tenth_hand_index = ((NUM_STEPS_CHRONO_TENTH * use_ms) / (12 * SECONDS_PER_HOUR * 1000)) % NUM_STEPS_CHRONO_TENTH;
    }
  }
#endif  // ENABLE_CHRONO_TENTH_HAND
}