예제 #1
0
// Snap the stick figure to a pose
void stick_figure_snap_pose(StickFigure *stick_figure, StickFigurePose pose, int64_t epoch_ms) {
  // set the pose
  stick_figure_set_pose(stick_figure, pose, epoch_ms);
  // copy memory from data into stick figure
  memcpy(&stick_figure->old_skeleton, &skeleton_frame_data[pose][0], sizeof(SkeletonFrame));
  memcpy(&stick_figure->cur_skeleton, &skeleton_frame_data[pose][0], sizeof(SkeletonFrame));
}
예제 #2
0
파일: main.c 프로젝트: Boms/pebble-7-min
//! Callback for drawing layer to render visuals in
//! @param layer The layer being updated.
//! @param ctx The GContext to draw on
static void prv_layer_update_proc_handler(Layer *layer, GContext *ctx) {
  // get data
  WindowData *data = (*(WindowData**)layer_get_data(layer));
  GSize window_size = layer_get_bounds(layer).size;
  GPoint offset = GPoint(window_size.w / 2, window_size.h / 2);
  int64_t epoch_ms = prv_get_epoch_ms();

  // if in configuration mode
  if (data->config_mode) {
    drawing_config(ctx, window_size, data->config_bmp);
    return;
  }

  // get timing values
  int32_t run_time, period_time, period_time_total;
  prv_get_current_timing(data, epoch_ms, &run_time, &period_time, &period_time_total);
  uint32_t angle = TRIG_MAX_ANGLE * period_time / period_time_total;

  // get current pose
  StickFigurePose cur_pose = (StickFigurePose)(run_time / EXERCISE_TOTAL_PERIOD +
                                               PoseJumpingJacks);
  if (data->start_epoch <= 0) {
    cur_pose = PoseWaitingForStart;
  } else if (run_time >= EXERCISE_TOTAL_PERIOD * EXERCISE_ACTIVITY_COUNT - EXERCISE_REST_PERIOD) {
    data->start_epoch = epoch_ms - EXERCISE_TOTAL_PERIOD * EXERCISE_ACTIVITY_COUNT;
    cur_pose = PoseDone;
    angle = 0;
  } else if (period_time_total == EXERCISE_REST_PERIOD) {
    cur_pose = PoseResting;
  } else if (cur_pose == PoseSidePlanks && period_time >= EXERCISE_ACTIVITY_PERIOD / 2) {
    cur_pose = PoseSidePlanksSwapped;
  }
  StickFigurePose old_pose = stick_figure_get_pose(data->stick_figure);
  if (cur_pose != old_pose) {
    // vibrate if not at start or end
    if (!data->manual_change){
      vibes_short_pulse();
      // send a pin if last exercise
      if (cur_pose == PoseDone) {
        prv_phone_send_pin();
      }
    }
    // set the new pose
    stick_figure_set_pose(data->stick_figure, cur_pose, epoch_ms);
  }
  // set manual change to false to enable vibrations again
  data->manual_change = false;

  // step animations
  stick_figure_step_animation(data->stick_figure, epoch_ms);
  drawing_button_step_animation(data->button, epoch_ms);


  // draw the visuals on the screen
  GBitmap *bmp_gray = (cur_pose == PoseResting) ? data->grid_2_bmp : data->grid_1_bmp;
  drawing_background(ctx, window_size, angle, cur_pose, bmp_gray);
  drawing_button_draw(data->button, ctx, window_size, cur_pose, bmp_gray);
  stick_figure_draw(data->stick_figure, ctx, offset);
  stick_figure_draw_props(ctx, cur_pose, offset);
  // draw text
  uint8_t cur_activity = run_time / EXERCISE_TOTAL_PERIOD + PoseJumpingJacks;
  if (cur_pose == PoseDone) {
    cur_activity = PoseDone;
  }
  drawing_text(ctx, window_size, cur_activity, period_time,
               period_time_total == EXERCISE_ACTIVITY_PERIOD, run_time == 1);
}