void controller_setmodel(PropertyName propertyName, const char* const value) {
  Tuplet values[] = {
    TupletCString(propertyName, value)
  };
  app_sync_set(&s_sync, values, ARRAY_LENGTH(values));
  modelChangedCallback(propertyName, value);
}
Example #2
0
/*----------------------------------------------------------------------------*/
void accel_data_callback(void * data, uint32_t num_samples)
{
  AppMessageResult result;
  AccelData * vector = (AccelData*) data;

  if (vector->did_vibrate) {
    syncStats.sync_vib++;
    return;
  }

  if (syncChangeCount > 0) {
    syncStats.sync_missed++;
    return;
  }

  /* Build the dictionary to hold this vector */
  Tuplet vector_dict[] = {
    TupletInteger(PP_KEY_CMD, PP_CMD_VECTOR),
    TupletInteger(PP_KEY_X, (int) vector->x),
    TupletInteger(PP_KEY_Y, (int) vector->y),
    TupletInteger(PP_KEY_Z, (int) vector->z),
  };

  /* Send the newly built dictionary to the remote side. */
  result = app_sync_set( &sync, vector_dict, ARRAY_LENGTH(vector_dict) );

  if (result != APP_MSG_OK) {
      APP_LOG(APP_LOG_LEVEL_DEBUG, "app_sync_set: APP_MSG_%s",
             AppMessageResult_to_String(result));
  }
  else {
    syncChangeCount = ARRAY_LENGTH(vector_dict);
    syncStats.sync_set++;
  }
}
Example #3
0
// Send message to phone asking for a weather update
void request_weather_update() {

  vibes_double_pulse();

  Tuplet values[] = {
   TupletInteger(WEATHER_FORECAST_REQUEST_KEY, 1),
  };
  app_sync_set(&s_data.sync, values, ARRAY_LENGTH(values));

}
Example #4
0
/*
  Initialization
*/
void handle_init( void ) {
  window = window_create();
  window_stack_push( window, true );
  Layer *window_layer = window_get_root_layer( window );

  // Read persistent data
  if ( persist_exists( SETTING_STATUS_KEY ) ) {
    current_status = persist_read_int( SETTING_STATUS_KEY );
  } else {
    current_status = STATUS_ON;
  }  
  if ( persist_exists( SETTING_WEATHERSTATUS_KEY ) ) {
    weather_status = persist_read_int( SETTING_WEATHERSTATUS_KEY );
  } else {
    weather_status = WEATHER_ON;
  }
  if ( persist_exists( SETTING_LANGUAGE_KEY ) ) {
    current_language = persist_read_int( SETTING_LANGUAGE_KEY );
  } else {
    current_language = LANG_EN;
  }
  if ( persist_exists( SETTING_FORMAT_KEY ) ) {
    current_format = persist_read_int( SETTING_FORMAT_KEY );
  } else {
    current_format = FORMAT_WEEK;
  }
  if ( persist_exists( SETTING_INVERT_KEY ) ) {
    invert_format = persist_read_int( SETTING_INVERT_KEY );
  } else {
    invert_format = INVERT_ON;
  }
  if ( persist_exists( BLUETOOTHVIBE_KEY ) ) {
    bluetoothvibe_status = persist_read_int( BLUETOOTHVIBE_KEY );
  } else {
    bluetoothvibe_status = BLUETOOTHVIBE_ON;
  }
  if ( persist_exists( HOURLYVIBE_KEY ) ) {
    hourlyvibe_status = persist_read_int( HOURLYVIBE_KEY );
  } else {
    hourlyvibe_status = HOURLYVIBE_ON;
  }
  if ( persist_exists( SECS_KEY ) ) {
    secs_status = persist_read_int( SECS_KEY );
  } else {
    secs_status = SECS_ON;
  }
	
	
  // Read watchface settings from persistent data or use default values
  current_status = persist_exists( SETTING_STATUS_KEY ) ? persist_read_int( SETTING_STATUS_KEY ) : STATUS_ON;
  weather_status = persist_exists( SETTING_WEATHERSTATUS_KEY ) ? persist_read_int( SETTING_WEATHERSTATUS_KEY ) : WEATHER_ON;
  current_language = persist_exists( SETTING_LANGUAGE_KEY ) ? persist_read_int( SETTING_LANGUAGE_KEY ) : LANG_EN;
  current_format = persist_exists( SETTING_FORMAT_KEY ) ? persist_read_int( SETTING_FORMAT_KEY ) : FORMAT_WEEK;
  invert_format = persist_exists( SETTING_INVERT_KEY ) ? persist_read_int( SETTING_INVERT_KEY ) : INVERT_ON;
  bluetoothvibe_status = persist_exists( BLUETOOTHVIBE_KEY ) ? persist_read_int( BLUETOOTHVIBE_KEY ) : BLUETOOTHVIBE_ON;
  hourlyvibe_status = persist_exists( HOURLYVIBE_KEY ) ? persist_read_int( HOURLYVIBE_KEY ) : HOURLYVIBE_ON;
  secs_status = persist_exists( SECS_KEY ) ? persist_read_int( SECS_KEY ) : SECS_ON;

  // Background image
  background_image = gbitmap_create_with_resource( RESOURCE_ID_IMAGE_BACKGROUND );
  background_layer = bitmap_layer_create( layer_get_frame( window_layer ) );
  bitmap_layer_set_bitmap( background_layer, background_image );
  layer_add_child( window_layer, bitmap_layer_get_layer( background_layer ) );

  // Initial settings
  Tuplet initial_values[] = { TupletInteger( SETTING_STATUS_KEY, current_status )
	  						, TupletInteger( SETTING_WEATHERSTATUS_KEY, weather_status )
                            , TupletInteger( SETTING_LANGUAGE_KEY, current_language )
                            , TupletInteger( SETTING_FORMAT_KEY, current_format )
                            , TupletInteger( SETTING_INVERT_KEY, invert_format )
                            , TupletInteger( BLUETOOTHVIBE_KEY, bluetoothvibe_status )
                            , TupletInteger( HOURLYVIBE_KEY, hourlyvibe_status )
                            , TupletInteger( SECS_KEY, secs_status )
							, TupletInteger( SETTING_ICON_KEY, (uint8_t) 14)
                            , TupletCString( SETTING_TEMPERATURE_KEY, "")
                            };

  // Open AppMessage to transfers
  app_message_open( 256	, 256 );

  // Initialize AppSync
  app_sync_init( &app, sync_buffer
               , sizeof( sync_buffer )
               , initial_values
               , ARRAY_LENGTH( initial_values )
               , tuple_changed_callback
               , app_error_callback
               , NULL 
               );

  // Perform sync
  app_sync_set( &app, initial_values, ARRAY_LENGTH( initial_values ) );

	
		appStarted = true;

	
  // Adjust GRect for Hours, Minutes and Blink to compensate for missing AM/PM indicator
  if ( clock_is_24h_style() ) {
    TIME_RECT.origin.y = TIME_RECT.origin.y + 1;
  }

  // Load fonts
  font_time = fonts_load_custom_font( resource_get_handle( RESOURCE_ID_FONT_LCARS_68 ) );
  font_days = fonts_load_custom_font( resource_get_handle( RESOURCE_ID_FONT_LCARS_20 ) );
  font_date = fonts_load_custom_font( resource_get_handle( RESOURCE_ID_FONT_LCARS_25 ) );

  // Setup time layer
  text_time_layer = setup_text_layer( TIME_RECT, GTextAlignmentRight, font_time );
#ifdef PBL_COLOR
 text_layer_set_text_color(text_time_layer, GColorChromeYellow);
#endif		
  layer_add_child( window_layer, text_layer_get_layer( text_time_layer ) );

  // Setup AM/PM name layer
  text_ampm_layer = setup_text_layer( AMPM_RECT, GTextAlignmentLeft, font_days );
  layer_add_child( window_layer, text_layer_get_layer( text_ampm_layer ) );

  // Setup days line layer
  text_days_layer = setup_text_layer( DAYS_RECT, GTextAlignmentLeft, font_days );
#ifdef PBL_COLOR
		  text_layer_set_text_color(text_days_layer, GColorDarkGray);
#endif			 

  layer_add_child( window_layer, text_layer_get_layer( text_days_layer ) );
  text_layer_set_text( text_days_layer, day_lines[current_language] );

  // Setup date layer
  text_date_layer = setup_text_layer( ( current_status == STATUS_ON ) ? DATE_RECT : OFF_DATE_RECT
                                    , GTextAlignmentLeft
                                    , font_date );
#ifdef PBL_COLOR
 text_layer_set_text_color(text_date_layer, GColorChromeYellow);
#endif		
  layer_add_child( window_layer, text_layer_get_layer( text_date_layer ) );

  // Setup week layer
  text_week_layer = setup_text_layer( ( current_status == STATUS_ON ) ? WEEK_RECT : OFF_WEEK_RECT
                                    , GTextAlignmentLeft
                                    , font_date );
#ifdef PBL_COLOR
 text_layer_set_text_color(text_week_layer, GColorChromeYellow);
#endif			 

  layer_add_child( window_layer, text_layer_get_layer( text_week_layer ) );

  
  // Setup weather info
  Layer *weather_holder = layer_create(GRect(0, 0, 144, 168 ));
  layer_add_child(window_layer, weather_holder);

  icon_layer = bitmap_layer_create( ( weather_status == WEATHER_ON ) ? ICON_RECT : EMPTY_RECT );	
//  icon_layer = bitmap_layer_create( ICON_RECT );
  layer_add_child(weather_holder, bitmap_layer_get_layer(icon_layer));

   temp_layer = setup_text_layer( ( weather_status == WEATHER_ON ) ? TEMP_RECT : EMPTY_RECT
	                            , GTextAlignmentLeft
                                , font_days );
  //temp_layer = setup_text_layer( TEMP_RECT, GTextAlignmentLeft, font_days );
  layer_add_child(weather_holder, text_layer_get_layer(temp_layer));

  // Setup battery layer
  battery_layer = bitmap_layer_create( ( current_status == STATUS_ON ) ? BATT_RECT : EMPTY_RECT );
  layer_add_child( window_layer, bitmap_layer_get_layer( battery_layer ) );

  // Setup bluetooth layer
  bluetooth_layer = bitmap_layer_create( ( current_status == STATUS_ON ) ? BT_RECT : EMPTY_RECT );
  layer_add_child( window_layer, bitmap_layer_get_layer( bluetooth_layer ) );

  // Add inverter layer (indicator for the current day of the week)
  currentDayLayer = inverter_layer_create( EMPTY_RECT );
  layer_add_child( window_layer, inverter_layer_get_layer( currentDayLayer ) );

  // Setup seconds name layer
  text_secs_layer = setup_text_layer( SECS_RECT, GTextAlignmentLeft, font_days );
  layer_add_child( window_layer, text_layer_get_layer( text_secs_layer ) );
	
  // Subscribe to services
  tick_timer_service_subscribe( SECOND_UNIT, handle_tick );

  // Force update to avoid a blank screen at startup of the watchface
  update_time();
}
Example #5
0
void handle_init(void) {
   window = window_create();
   window_stack_push(window, true /* Animated */);
   window_set_background_color(window, GColorBlack);

   Layer *window_layer = window_get_root_layer(window);
   GRect bounds = layer_get_bounds(window_layer);

   int smallh = 21;
   int largeh = 51;
   int halfw = bounds.size.w / 2;
   int margin = 8;
   int offy = bounds.origin.y;

   // Date in upper-left
   text_date_layer = text_layer_create(
      GRect(bounds.origin.x,
            offy,
            halfw,
            smallh));
   text_layer_set_text_color(text_date_layer, GColorWhite);
   text_layer_set_background_color(text_date_layer, GColorClear);
   text_layer_set_font(text_date_layer,
                       fonts_get_system_font(FONT_KEY_ROBOTO_CONDENSED_21));
   layer_add_child(window_layer, text_layer_get_layer(text_date_layer));

   // Watch battery in upper-right
   text_watchbatt_layer = text_layer_create(
      GRect(bounds.origin.x + halfw,
            offy,
            halfw,
            smallh));
   text_layer_set_text_color(text_watchbatt_layer, GColorWhite);
   text_layer_set_background_color(text_watchbatt_layer, GColorClear);
   text_layer_set_font(text_watchbatt_layer,
                       fonts_get_system_font(FONT_KEY_ROBOTO_CONDENSED_21));
   text_layer_set_text_alignment(text_watchbatt_layer, GTextAlignmentRight);
   layer_add_child(window_layer, text_layer_get_layer(text_watchbatt_layer));

   offy = offy + smallh;

   // Time next
   text_time_layer = text_layer_create(
      GRect(bounds.origin.x + margin,
            offy,
            bounds.size.w - margin*2,
            largeh));
   text_layer_set_text_color(text_time_layer, GColorWhite);
   text_layer_set_background_color(text_time_layer, GColorClear);
   text_layer_set_text_alignment(text_time_layer, GTextAlignmentCenter);
   text_layer_set_font(text_time_layer,
                       fonts_get_system_font(FONT_KEY_ROBOTO_BOLD_SUBSET_49));
   layer_add_child(window_layer, text_layer_get_layer(text_time_layer));

   offy = offy + largeh + 2;

   // Separator
   GRect line_frame = GRect(bounds.origin.x + margin,
                            offy,
                            bounds.size.w - margin*2,
                            2);
   line_layer = layer_create(line_frame);
   layer_set_update_proc(line_layer, line_layer_update_callback);
   layer_add_child(window_layer, line_layer);

   offy = offy + 2;

   // Event in bottom half -1
   text_event_layer = text_layer_create(
      GRect(bounds.origin.x,
            offy,
            bounds.size.w,
            bounds.size.h - offy - smallh));
   text_layer_set_text_color(text_event_layer, GColorWhite);
   text_layer_set_background_color(text_event_layer, GColorClear);
   text_layer_set_overflow_mode(text_event_layer, GTextOverflowModeFill);
   text_layer_set_font(text_event_layer,
                       fonts_get_system_font(FONT_KEY_ROBOTO_CONDENSED_21));
   layer_add_child(window_layer, text_layer_get_layer(text_event_layer));


   // Location in bottom row
   text_location_layer = text_layer_create(
      GRect(bounds.origin.x,
            bounds.size.h - smallh,
            bounds.size.w,
            smallh));
   text_layer_set_text_color(text_location_layer, GColorWhite);
   text_layer_set_background_color(text_location_layer, GColorClear);
   text_layer_set_overflow_mode(text_location_layer, GTextOverflowModeFill);
   text_layer_set_font(text_location_layer,
                       fonts_get_system_font(FONT_KEY_ROBOTO_CONDENSED_21));
   layer_add_child(window_layer, text_layer_get_layer(text_location_layer));



   // Subscribe to date/time
   tick_timer_service_subscribe(MINUTE_UNIT, handle_minute_tick);

   // Subscribe to watchbatt
   battery_state_service_subscribe(handle_watchbatt_change);
   handle_watchbatt_change(battery_state_service_peek());

   // Subscribe to phone data
   const int inbound_size = 256;
   const int outbound_size = 16;
   app_message_open(inbound_size, outbound_size);
   Tuplet initial_values[] = {
       TupletCString(EVENT, "No event synced"),
       //TupletCString(EVENT, "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea"),
       TupletCString(LOCATION, ""),
   };
   app_sync_init(&sync, sync_buffer, sizeof(sync_buffer),
                 initial_values, ARRAY_LENGTH(initial_values),
                 sync_tuple_changed_callback,
                 sync_error_callback, NULL);

   app_sync_set(&sync, initial_values, ARRAY_LENGTH(initial_values));
}