Exemple #1
0
static void worker_message_handler(uint16_t type, AppWorkerMessage *data) {
	static AppWorkerMessage msg_data;
		switch(type) {
		case WORKER_MSG_ECHO:
#if !ECHO_CMDS			
			 // Construct a data packet
			msg_data.data0 = data->data0;
	  		// Send the data to the foreground app
			app_worker_send_message(WORKER_MSG_ECHO, &msg_data);
#endif			
		break;
		
		case WORKER_MSG_ACCEL_START:
			accel_data_service_subscribe(data->data0, worker_accel_data_handler);
			accel_service_set_sampling_rate(data->data1);
			worker_accel_enabled = true;
		break;
		
		case WORKER_MSG_ACCEL_STOP:
			accel_data_service_unsubscribe();
			worker_accel_enabled = false;
		break;
				
		case WORKER_MSG_ACCEL_MODIFY:
			accel_service_set_samples_per_update(data->data0);
			accel_service_set_sampling_rate(data->data1);
		break;
		
		case WORKER_MSG_TICK_START:
			if ( data->data0 != 0 ) 
				tickRate = data->data0; // how often do we want updates.
			tick_timer_service_subscribe(SECOND_UNIT, worker_tick_handler);
			worker_tick_enabled = true;
		break;
		
		case WORKER_MSG_TICK_STOP:
			tick_timer_service_unsubscribe();
			worker_tick_enabled = false;
		break;
			
		case WORKER_MSG_LOGGING_START:
			datalog_ref = data_logging_create(SLEEP_DATA_LOG_TAG, DATA_LOGGING_BYTE_ARRAY, sizeof(struct AccelData), true);
			worker_logging_enabled = true;
		break;
		
		case WORKER_MSG_LOGGING_STOP:
			data_logging_finish(datalog_ref);
			worker_logging_enabled = false;
		break;
			
		case WORKER_MSG_STATUS_RQST:
			worker_send_status_resp();
		break;
	}
	
#if ECHO_CMDS
	msg_data.data0 = type;
	app_worker_send_message(WORKER_MSG_ECHO,&msg_data);
#endif
}
void deinit() {
  app_worker_send_message(ActionStop, NULL);
  app_worker_message_unsubscribe();
  health_service_events_unsubscribe();
  if (next_event_limit != NULL) {
    app_timer_cancel(next_event_limit);
  }
}
Exemple #3
0
//method for handling "down" button press
static void down_click_handler(ClickRecognizerRef recognizer, void *context) {
  text_layer_set_text(text_layer, "Logging Ended");
//   datalogging_end();
  APP_LOG(APP_LOG_LEVEL_DEBUG, "Logging ended"); //Pebble log output
  
   //testing
  AppWorkerMessage msg;
  app_worker_send_message(WORKER_KEY_ECZEMAMALOGGER_STOP, &msg);
  //endtesting
}
Exemple #4
0
//method for handling "select" button press
static void select_click_handler(ClickRecognizerRef recognizer, void *context) {
  select_count++;
  text_layer_set_text(text_layer, "Counting...");
  APP_LOG(APP_LOG_LEVEL_DEBUG, "%d counts", select_count); //Pebble log output
  
  //testing
  AppWorkerMessage msg;
  app_worker_send_message(WORKER_KEY_ECZEMAMALOGGER_TOGGLE, &msg);
  //endtesting
}
static void tick_handler(struct tm *tick_timer, TimeUnits units_changed) {
  // Update value
  s_ticks++;

  // Construct a data packet
  AppWorkerMessage msg_data = {
    .data0 = s_ticks
  };

  // Send the data to the foreground app
  app_worker_send_message(WORKER_TICKS, &msg_data);
}
static void update_data_sent() {
  uint16_t data_sent_current = get_accel_logging_data_sent() / 1000;
  static uint16_t data_sent_last = -1;
  if (data_sent_last == data_sent_current)
    return;  // info is up-to-date enough
  data_sent_last = data_sent_current;

    // Construct a data packet
  AppWorkerMessage message = {
    .data0 = data_sent_current
  };
 
  app_worker_send_message(1, &message); // 1 = number of kb sent
}
static void accel_data_handler(AccelData *data, uint32_t num_samples) {
  DataLoggingResult res = accel_logging_send_data(data, num_samples);
  if (DATA_LOGGING_SUCCESS == res) {
    s_send_counter++;
    update_data_sent();    
  }
  else {
      // Construct a data packet
    AppWorkerMessage message = {
      .data0 = res
    };
   
    app_worker_send_message(2, &message); // 2 = logging error
  }
}
Exemple #8
0
void worker_send_status_resp() {
  // Construct a data packet
	uint16_t status = 0;
	if ( worker_logging_enabled )
		status |= LOG_BIT;
	if ( worker_tick_enabled)
		status |= TICK_BIT;
	if ( worker_accel_enabled ) 
		status |= ACCEL_BIT;
	AppWorkerMessage status_msg_data = {
		.data0 = s_ticks,
		.data1 = s_accel_ticks,
		.data2 = status
	};

  // Send the data to the foreground app
  app_worker_send_message(WORKER_MSG_STATUS, &status_msg_data);
}
static void menu_select_callback(MenuLayer *menu_layer, MenuIndex *cell_index, void *data) {
  // step_goal = cell_index->row;
  setStepGoal(cell_index->row);
  persist_write_int(GOAL, cell_index->row);
  AppWorkerMessage packet = {
    .data0 = cell_index->row
  };
  app_worker_send_message(GOAL, &packet);
  menu_layer_reload_data(main_menu);
  layer_mark_dirty(info_bar);
}

static int get_step_count() {
    HealthServiceAccessibilityMask request = health_service_metric_accessible(HealthMetricStepCount,
    time_start_of_today(), time(NULL));
    if(request == HealthServiceAccessibilityMaskAvailable) {
      return (int)health_service_sum_today(HealthMetricStepCount);
    } else {
      return 0;
    }
}
void init() {
  app_worker_message_subscribe(on_app_message);
  app_worker_send_message(ActionStart, NULL);
  health_service_events_subscribe(on_health_event, NULL);
  app_timer_register((uint32_t)10000, on_timer_event, NULL);
}
Exemple #11
0
static void select_click_handler(ClickRecognizerRef recognizer, void *context) {
  AppWorkerMessage msg;
  app_worker_send_message(WORKER_KEY_TRICORDER_TOGGLE, &msg);
}