Example #1
0
static void update_triangle_proc(Layer *layer, GContext *ctx) {
  if(!s_spinning) {
    return;
  }
  
  // Move
  int32_t move_x = (int32_t)(sin_lookup(angle) * (RADIUS - 4) / TRIG_MAX_RATIO);
  int32_t move_y = (int32_t)(-cos_lookup(angle) * (RADIUS - 4) / TRIG_MAX_RATIO);
  gpath_move_to(s_spin_arrow_path, GPoint(s_spin_circle_center.x - move_x, s_spin_circle_center.y + move_y));
  
  if(TESTING){
    APP_LOG(APP_LOG_LEVEL_DEBUG, "move_x: %d", (int)move_x);
    APP_LOG(APP_LOG_LEVEL_DEBUG, "move_y: %d", (int)move_y);
    APP_LOG(APP_LOG_LEVEL_DEBUG, "angle: %d", (int)TRIGANGLE_TO_DEG(angle));
  }
  
  // Rotate
  gpath_rotate_to(s_spin_triangle_path, -angle);
  gpath_rotate_to(s_spin_arrow_path, -angle);
  
  // Fill the path:
  graphics_context_set_fill_color(ctx, GColorBlack);
  gpath_draw_filled(ctx, s_spin_triangle_path);
  graphics_context_set_fill_color(ctx, GColorWhite);
  gpath_draw_filled(ctx, s_spin_arrow_path);
}
Example #2
0
void set_spin_angle(int32_t compass_heading){
  if(!s_spinning) {
    return;
  }
  
  // Allocate a static output buffer
  static char s_buffer[32];
  static int32_t diff, deg;
  
  diff = math_abs(TRIGANGLE_TO_DEG(prev_compass_heading - compass_heading));
  
  if (TESTING){
    APP_LOG(APP_LOG_LEVEL_DEBUG, "prev compass heading: %d", (int)prev_compass_heading);
    APP_LOG(APP_LOG_LEVEL_DEBUG, "compass heading: %d", (int)compass_heading);
    APP_LOG(APP_LOG_LEVEL_DEBUG, "diff: %d", (int)diff);
  }
    
  if (prev_compass_heading > compass_heading && diff > 5) {
    angle -= 10 * TRIG_MAX_ANGLE / 360;
    if(TESTING) APP_LOG(APP_LOG_LEVEL_DEBUG, "clockwise");
  } else if(diff > 5) {
    angle += 10 * TRIG_MAX_ANGLE / 360;
    if(TESTING) APP_LOG(APP_LOG_LEVEL_DEBUG, "counterclockwise");
  }
  prev_compass_heading = compass_heading;
  
  // Set the number of spins completed
  deg = TRIGANGLE_TO_DEG(angle);
  spins = (int16_t)((math_abs(deg) + 20) / 180);
  
  // Turn off alarm
  if (spins == MAX_SPINS) {
    set_alarm_on(false);
  }
  
  APP_LOG(APP_LOG_LEVEL_DEBUG, "deg: %d", (int)deg);
  APP_LOG(APP_LOG_LEVEL_DEBUG, "spins: %d", (int)deg);
  
  // Set spin text
  snprintf(s_buffer, sizeof(s_buffer), "%d", MAX_SPINS - spins);
  text_layer_set_text(s_spin_spins_text_layer, s_buffer);
  
  layer_mark_dirty(s_spin_triangle_canvas_layer);
}
Example #3
0
void compass_handler(CompassHeadingData data) {
    CompassStatus status = data.compass_status;
    int heading;
    char degrees[6];
    char compass[2];
    switch(status) {
        case CompassStatusCalibrated:
        case CompassStatusCalibrating:
            heading = TRIGANGLE_TO_DEG(TRIG_MAX_ANGLE - (int)data.magnetic_heading);

            strcpy(compass, get_wind_direction((TRIGANGLE_TO_DEG((int)data.magnetic_heading) + 180) % 360));
            snprintf(degrees, sizeof(degrees), "%s", get_wind_direction_text((heading + 180) % 360));

            set_compass_layer_text(compass);
            set_degrees_layer_text(degrees);
            break;
        case CompassStatusUnavailable:
        case CompassStatusDataInvalid:
            set_compass_layer_text("N");
            set_degrees_layer_text("NA");
            break;
    }
}
void compass_direction_handler(CompassHeadingData direction_data){
  static char direction_buf[]="~~~";
  switch (direction_data.compass_status) {
    case CompassStatusDataInvalid:
      snprintf(direction_buf, sizeof(direction_buf), "%s", "!!!");
      if (!orientToHeading) return;
    case CompassStatusCalibrating:
      snprintf(direction_buf, sizeof(direction_buf), "%s", "???");
      break;
    case CompassStatusCalibrated:
      snprintf(direction_buf, sizeof(direction_buf), "%d", (int) ((360-TRIGANGLE_TO_DEG(direction_data.true_heading)) % 360));
  }
  text_layer_set_text(direction_layer, direction_buf);
  if (!orientToHeading) orientation = direction_data.true_heading;
  draw_compass_face();
}
static void head_layer_update_callback(Layer *layer, GContext *ctx) {
  gpath_rotate_to(head_path, (TRIG_MAX_ANGLE / 360) * (bearing + TRIGANGLE_TO_DEG(orientation)));
  graphics_context_set_fill_color(ctx, GColorBlack);
  graphics_fill_circle(ctx, center, 77);
#ifdef PBL_COLOR
  if (heading >= 0) {
    int angle = bearing - heading;
    if (angle < 0) angle += 360;
    if (angle < 16)
      graphics_context_set_fill_color(ctx, GColorYellow);
    else if (angle < 46)
      graphics_context_set_fill_color(ctx, GColorSpringBud);
    else if (angle < 76)
      graphics_context_set_fill_color(ctx, GColorBrightGreen);
    else if (angle < 106)
      graphics_context_set_fill_color(ctx, GColorGreen);
    else if (angle < 136)
      graphics_context_set_fill_color(ctx, GColorScreaminGreen);
    else if (angle < 166)
      graphics_context_set_fill_color(ctx, GColorMintGreen);
    else if (angle < 196)
      graphics_context_set_fill_color(ctx, GColorBabyBlueEyes);
    else if (angle < 226)
      graphics_context_set_fill_color(ctx, GColorMelon);
    else if (angle < 256)
      graphics_context_set_fill_color(ctx, GColorSunsetOrange);
    else if (angle < 286)
      graphics_context_set_fill_color(ctx, GColorRed);
    else if (angle < 316)
      graphics_context_set_fill_color(ctx, GColorOrange);
    else if (angle < 346)
      graphics_context_set_fill_color(ctx, GColorChromeYellow);
    else
      graphics_context_set_fill_color(ctx, GColorYellow);
  } else /* heading undefined */
#endif
  graphics_context_set_fill_color(ctx, GColorWhite);
  gpath_draw_filled(ctx, head_path);
  graphics_fill_circle(ctx, center, 49);
  graphics_context_set_fill_color(ctx, GColorBlack);
}
Example #6
0
// Compass callback
void compass_handler(CompassHeadingData data) {
  // Determine status of the compass
  switch (data.compass_status) {
    // Compass data is not yet valid
    case CompassStatusDataInvalid:
      APP_LOG(APP_LOG_LEVEL_ERROR, "Compass data invalid, got: %d", (int)TRIGANGLE_TO_DEG(data.true_heading));
      break;

    // Compass is currently calibrating, but a heading is available
    case CompassStatusCalibrating:
      set_spin_angle((int32_t)data.true_heading);
      break;
    // Compass data is ready for use, write the heading in to the buffer
    case CompassStatusCalibrated:
      set_spin_angle((int32_t)data.true_heading);
      break;

    // CompassStatus is unknown
    default:
      APP_LOG(APP_LOG_LEVEL_ERROR, "Unknown CompassStatus: %d", data.compass_status);
      break;
  }
}
Example #7
0
void compass_handler(CompassHeadingData data) {
  static char str[32];
  
  switch(data.compass_status) {
    case CompassStatusCalibrated:
      snprintf(str, sizeof(str), "Heading: %d", (int)(TRIGANGLE_TO_DEG(data.true_heading)));
    break;

    case CompassStatusDataInvalid:
      snprintf(str, sizeof(str), "Invalid status: %d", (int) data.compass_status);
    break;
    
    case CompassStatusCalibrating:
      strcpy(str, "Compass calibrating");
    break;
    
    default:
      strcpy(str, "unknown state");
    break;
  }
  
  text_layer_set_text(text_layer, str);
}
// Este es el manejador que se le va a pasar al servicio del compas
// Se ejecuta cada vez que el estado del compas cambia, por defecto
// se dispara cuando hay cambio de minimo 1 grado pero por ahorro se
// puede configurar a n grados.
static void compass_heading_handler(CompassHeadingData heading_data) 
{
  
  static char compass_text[10];
  static int deg;
  
  // Hay tres estados, datos invalidos o no disponibles
  // Calibrating, significa que hay que calibrar el compas y el que queda
  // es cuando el compas esta bien calibrado
  switch(heading_data.compass_status) 
  {
    case CompassStatusDataInvalid:
    if(debug_mode)
    {
      snprintf(compass_text, sizeof(compass_text), "N/A");
    }
    break;
    case CompassStatusCalibrating:
    case CompassStatusCalibrated:
    
    // arreglo del eje del servicio del compas
    // https://forums.getpebble.com/discussion/17276/compass-heading-backwards
    heading_data.magnetic_heading = TRIG_MAX_ANGLE - heading_data.magnetic_heading;
    deg = (int)TRIGANGLE_TO_DEG(heading_data.magnetic_heading) + 90;
    
    // si se pasa al sumarle los 90 grados
    if(deg >= 360)
    {
      deg %= 360;
    }
    
    if(debug_mode)
    {
      snprintf(compass_text, sizeof(compass_text), "%d°", deg);
    }
    break;
  }
  
  if(debug_mode)
  {
    text_layer_set_text(s_text_layer, compass_text);
  }
  
  
  // Declare the dictionary's iterator
  DictionaryIterator *out_iter;
  
  // Prepare the outbox buffer for this message
  AppMessageResult result = app_message_outbox_begin(&out_iter);
  
  if(result == APP_MSG_OK) {
    int value = deg;
    dict_write_int(out_iter, AppKeyCompassDegree, &value, sizeof(int), true);
    
    // Send this message
    result = app_message_outbox_send();
    if(result != APP_MSG_OK) {
    APP_LOG(APP_LOG_LEVEL_ERROR, "Error sending the outbox: %d", (int)result);
    }else{
       APP_LOG(APP_LOG_LEVEL_ERROR, "good");
    }
 
  }else{
    // The outbox cannot be used right now
    APP_LOG(APP_LOG_LEVEL_ERROR, "Error preparing the outbox: %d", (int)result);
  }
}