Пример #1
0
/*
 * Messages incoming from the phone
 */
void received_message(DictionaryIterator *received, void *context) {
   Event temp_event;
	
   Tuple *tuple = dict_find(received, RECONNECT_KEY);
   if (tuple) {
	 vibes_short_pulse();
	 calendar_request();	
   }
	
   // Gather the bits of a calendar together	
   tuple = dict_find(received, CALENDAR_RESPONSE_KEY);
	  
   if (tuple) {
	    set_status(STATUS_REPLY);
    	uint8_t i, j;

		if (g_count > g_received_rows) {
      		i = g_received_rows;
      		j = 0;
        } else {
      	    g_count = tuple->value->data[0];
      	    i = 0;
      	    j = 1;
        }

        while (i < g_count && j < tuple->length) {
    	    memcpy(&temp_event, &tuple->value->data[j], sizeof(Event));
			if (temp_event.index < MAX_EVENTS)
      	        memcpy(&g_events[temp_event.index], &temp_event, sizeof(Event));

      	    i++;
      	    j += sizeof(Event);
        }

        g_received_rows = i;

        if (g_count == g_received_rows) {
			g_max_entries = g_count;
			process_rot_events();
			if (nothing_showing) {
				nothing_showing = false;
				show_next_event();
			}
			battery_request();
	    }
	}
	
	tuple = dict_find(received, BATTERY_RESPONSE_KEY);

    if (tuple) {
        memcpy(&g_battery_status, &tuple->value->data[0], sizeof(BatteryStatus));
		set_battery(g_battery_status.state, g_battery_status.level);
    }

}
Пример #2
0
/**
 * Rotate timer
 */
void second_timer() {

	// rotate display
	rotate_tick++;
	if (rotate_tick >= rotate_change) {
		rotate_tick = 0;
	    show_next_event();
	    if (rotate_change < MAX_SECOND_PER_ROTATE && g_entry_no == 1)
	    	rotate_change++;
	}
}
Пример #3
0
/*
 * Timer handling. Includes a hold off for a period of time if there is resource contention
 */
void handle_calendar_timer(AppContextRef app_ctx, AppTimerHandle handle, uint32_t cookie) {
	
  // If we're rotating the visible event, get on with it. Slower overnight to save power
  if (cookie == ROTATE_EVENT) {
	  // Clobber the timer
	  app_timer_cancel_event(app_ctx, handle);
	  
	  // Show next event 
      show_next_event();
	  
	  // Kick off new timer
	  if (is_overnight()) 
    	app_timer_send_event(app_ctx, ROTATE_EVENT_INTERVAL_OVERNIGHT_MS, cookie);
	  else
    	app_timer_send_event(app_ctx, ROTATE_EVENT_INTERVAL_MS, cookie);
	
	  // Retire from active duty
	  return;
  }
	
  // Show the alert and let the world know
  if (cookie >= ALERT_EVENT && cookie <= (ALERT_EVENT + (MAX_EVENTS * 2))) {
	  app_timer_cancel_event(app_ctx, handle);
	  int num = cookie - ALERT_EVENT;
	  if (g_timer_rec[num].active == false)
		  return; // Already had the data for this event deleted - cannot show it.
	  g_timer_rec[num].active = false;
	  g_showing_alert = true;
      set_event_display(g_timer_rec[num].event_desc, g_timer_rec[num].relative_desc, g_timer_rec[num].location, 0);
	  set_invert_when_showing_event(true);
	  app_timer_send_event(app_ctx, 30000, RESTORE_DATE);	
	  app_timer_send_event(app_ctx, 15000, SECOND_ALERT);	
	  vibes_double_pulse();
      light_enable_interaction();
	  return;
  }

  // Let us know again
  if (cookie == SECOND_ALERT) {
      app_timer_cancel_event(app_ctx, handle);
      vibes_double_pulse();
      light_enable_interaction();
      return;
   }
      
  // Put the date back into the display area	
  if (cookie == RESTORE_DATE) {
	  app_timer_cancel_event(app_ctx, handle);
	  g_showing_alert = false;
	  show_next_event();
	  set_invert_when_showing_event(false);
	  return;
  }

  // Fire the calendar request
  if (cookie == REQUEST_CALENDAR_KEY) {
	  app_timer_cancel_event(app_ctx, handle);
	  calendar_request();
  }

}