static void write_blk_buf_to_persist(){ /* the persist_read_int(I_BLK_PERSIST_KEY) is NOT a count, it is the current index * but 1-indexced, so 1 is the first block and zero is the empty state */ if(persist_read_int(I_BLK_PERSIST_KEY) < N_BLK_PERSIST){ // set the index of the current block persist_write_int(I_BLK_PERSIST_KEY,persist_read_int(I_BLK_PERSIST_KEY)+1); persist_write_data(persist_read_int(I_BLK_PERSIST_KEY), blk_buf,((SIZE_SUMM*N_SUMM_BLK)+SIZE_BLK_HEAD)); } if(bluetooth_connection_service_peek()){ persist_write_int(WORKER_START_FORE_APP_REASON_PERSIST_KEY, WFAWR_PUSH_ALL_DATA_TO_SERVER); summ_since_trans_server = 0; // once try to go to server, reset worker_launch_app(); } else if(persist_read_int(I_BLK_PERSIST_KEY) >= (N_BLK_PERSIST-1) ){ // if the I_BLK_PERSIST_KEY is greater than 90% of storage, then prompt // that need to connect the phone persist_write_int(WORKER_START_FORE_APP_REASON_PERSIST_KEY, WFAWR_MEMORY_LOW_REMINDER); worker_launch_app(); } // else if(){ // // reset the counter for consecutive summaries // persist_write_int(WORKER_START_FORE_APP_REASON_PERSIST_KEY, // WFAWR_WEAR_REMINDER); // worker_launch_app(); // } }
/* BLUETOOTH CONNECTION SERVICE HANDLER*/ void worker_bt_service_handler(bool connected){ if(connected){ // set the foreground app start by worker info persistant storage id // try to send all data to phone persist_write_int(WORKER_START_FORE_APP_REASON_PERSIST_KEY, WFAWR_PUSH_ALL_DATA_TO_SERVER); worker_launch_app(); } }
void reschedule_app_timer_callback(void* data) { timeout_timer = app_timer_register(3600000,reschedule_app_timer_callback,NULL); time_t current_time = time(NULL); time_t diff = current_time-last_time; if (abs(diff-3600)>10) { // time has changed more than 10 seconds in the last hour worker_launch_app(); } last_time = current_time; }
void on_health_event(HealthEventType event, void *context) { APP_LOG(APP_LOG_LEVEL_DEBUG, "Health Event: %d", event); worker_launch_app(); }
void on_timer_event(void* data) { APP_LOG(APP_LOG_LEVEL_DEBUG, "Timer Event"); worker_launch_app(); }