Skip to content

Commit

Permalink
Merge pull request #504 from hello/integration
Browse files Browse the repository at this point in the history
RC3
  • Loading branch information
zer0page authored Sep 14, 2016
2 parents 6737349 + dba442e commit 1eedbe8
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 261 deletions.
6 changes: 3 additions & 3 deletions common/app_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
* A place to put all common defines
*/
//make sure the FW_VERSION_STRING fits in MorpheusCommand.top_version (16 bytes)
#define FW_VERSION_STRING "1.5.5"
#define FW_VERSION_STRING "1.5.6"

//pill only
#define FIRMWARE_VERSION_8BIT (55)
#define FIRMWARE_VERSION_8BIT (56)

#define BLE_SIG_COMPANY_ID 998
#define BLE_SIG_COMPANY_ID 1002

typedef struct __attribute__((packed)){
uint8_t hw_type; /* hw type, see ant_devices.h */
Expand Down
231 changes: 0 additions & 231 deletions common/printf.c

This file was deleted.

2 changes: 1 addition & 1 deletion drivers/imu.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#define LIS2DH_HRES_MG_PER_CNT (1)
#define MPU6500_MG_PER_LSB (16384UL)

#define IMU_WTM_THRESHOLD (6)
#define IMU_WTM_THRESHOLD (3)

#define IMU_USE_PIN_INT1
//#define IMU_USE_PIN_INT2
Expand Down
2 changes: 1 addition & 1 deletion pill/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ enum {
#define HEARTBEAT_INTERVAL_MIN (3600/60)
#define BATT_MEASURE_INTERVAL_MIN (1200/60) /* Measure battery level every 20 minutes */

#define SHAKING_MOTION_THRESHOLD (400000000)
#define SHAKING_MOTION_THRESHOLD (500000000)
#define SLIDING_WINDOW_SIZE_SEC (2) // shake second timer runs on imu active timer at 2hz now, so this is 1/2 secs
#define SHAKING_DATA_COUNT_THRESHOLD (5)

Expand Down
41 changes: 21 additions & 20 deletions pill/message_imu.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ static uint8_t stuck_counter;
static uint32_t top_of_minute = 0;
static uint32_t active_time = 0;

static void _update_motion_mask(uint32_t now, uint32_t anchor);

static struct imu_settings _settings = {
.active_wom_threshold = IMU_ACTIVE_WOM,
Expand Down Expand Up @@ -105,18 +106,6 @@ static uint32_t _aggregate_motion_data(const int16_t* raw_xyz, size_t len)
//int32_t aggregate = ABS(values[0]) + ABS(values[1]) + ABS(values[2]);
uint32_t aggregate = values[0] * values[0] + values[1] * values[1] + values[2] * values[2];

/*
tf_unit_t curr = TF_GetCurrent();
PRINTS("Current value: ");
PRINT_HEX(&curr, sizeof(curr));
PRINTS("\r\n");
PRINTS("New value: ");
PRINT_HEX(&aggregate, sizeof(tf_unit_t));
PRINTS("\r\n");
*/

//TF_SetCurrent((uint16_t)values[0]);
tf_unit_t* current = TF_GetCurrent();
++current->num_meas;
if(current->max_amp < aggregate){
Expand Down Expand Up @@ -169,21 +158,28 @@ static void _imu_gpiote_process(uint32_t event_pins_low_to_high, uint32_t event_

#define PRINT_HEX_X(x) PRINT_HEX(&x, sizeof(x)); PRINTS("\r\n");

static void _update_motion_mask(uint32_t now, uint32_t anchor){
uint32_t time_diff = 0;
app_timer_cnt_diff_compute(now, anchor, &time_diff);
time_diff /= APP_TIMER_TICKS( 1000, APP_TIMER_PRESCALER );

uint64_t old_mask = TF_GetCurrent()->motion_mask;
TF_GetCurrent()->motion_mask |= 1ull<<(time_diff%60);

if(TF_GetCurrent()->motion_mask != old_mask){
PRINTS("mask\r\n");
PRINT_HEX_X( TF_GetCurrent()->motion_mask );
}
}

static void _on_wom_timer(void* context)
{
uint32_t current_time = 0;
app_timer_cnt_get(&current_time);
uint32_t time_diff = 0;
app_timer_cnt_diff_compute(current_time, top_of_minute, &time_diff);

uint32_t active_time_diff = 0;
app_timer_cnt_diff_compute(current_time, active_time, &active_time_diff);

time_diff /= APP_TIMER_TICKS( 1000, APP_TIMER_PRESCALER );
TF_GetCurrent()->motion_mask |= 1ull<<(time_diff%60);
PRINTS("mask\r\n");

PRINT_HEX_X( TF_GetCurrent()->motion_mask );

ShakeDetectDecWindow();

if(active_time_diff < IMU_ACTIVE_INTERVAL && _settings.is_active)
Expand Down Expand Up @@ -377,6 +373,11 @@ static MSG_Status _send(MSG_Address_t src, MSG_Address_t dst, MSG_Data_t * data)
case IMU_READ_XYZ:
ret = _handle_read_xyz();
imu_clear_interrupt_status();
{
uint32_t current_time = 0;
app_timer_cnt_get(&current_time);
_update_motion_mask(current_time, top_of_minute);
}
break;
case IMU_SELF_TEST:
ret = _handle_self_test();
Expand Down
15 changes: 10 additions & 5 deletions pill/timedfifo.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,16 @@ bool TF_GetCondensed(MotionPayload_t* payload){
dot = ((uint64_t)dot*_fastinvsqrt(_mag(datum.prev_avg_accel)))>>16;

payload->cos_theta = _bitlog(dot);
uint32_t s = (_fastsqrt(datum.max_amp)) >> 8;
if( s < UINT8_MAX ) {
payload->max = s;
}else{
payload->max = UINT8_MAX;
uint32_t s = _fastsqrt(datum.max_amp);
if ( s < IMU_ONE_G ) {
payload->max = 0;
} else {
s = (s-IMU_ONE_G)>>7; //remove 1g, scale into 8 bits
if( s < UINT8_MAX ) {
payload->max = s;
}else{
payload->max = UINT8_MAX;
}
}
payload->motion_mask = datum.motion_mask;
#if 1
Expand Down

0 comments on commit 1eedbe8

Please sign in to comment.