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 accel_logging_start() { s_logging_session = data_logging_create( s_session_tag++, // the unique tag of the logging session DATA_LOGGING_BYTE_ARRAY, // we are logging byte arrays, each of which is sizeof(AccelData), // this length (2+2+2+8=14 bytes) long false // we do not resume a previous session. They would be overridden. ); }
static bool init(void) { accel_data_service_subscribe(ACCEL_BATCH, &data_handler); accel_service_set_sampling_rate(ACCEL_SAMPLING_10HZ); accel_data_log = data_logging_create( 0x1010, DATA_LOGGING_BYTE_ARRAY, sizeof(AccelData) * ACCEL_BATCH, false ); return true; }