Пример #1
0
/************************************************************************
 * clock_tick_handler() - Analyse data and update display.
 * Updates the text layer clock_layer to show current time.
 * This function is the handler for tick events and is called every 
 * second.
 */
static void clock_tick_handler(struct tm *tick_time, TimeUnits units_changed) {
  static char s_batt_buffer[16];
  static char s_time_buffer[16];
  static int dataUpdateCount = 0;
  static int lastAlarmState = 0;

  if (isManAlarm) {
    APP_LOG(APP_LOG_LEVEL_DEBUG,"Manual Alarm - manAlarmTime=%d, manAlarmPeriod=%d",
	    manAlarmTime,manAlarmPeriod);
    if (manAlarmTime < manAlarmPeriod) {
      alarmState = ALARM_STATE_MAN_ALARM;
      text_layer_set_text(alarm_layer, "** MAN ALARM **");
      manAlarmTime += 1;
    } else {
      isManAlarm = 0;
      manAlarmTime = 0;
    }
  }
  if (isMuted) {
    APP_LOG(APP_LOG_LEVEL_DEBUG,"Alarms Muted - muteTime=%d",muteTime);
    if (muteTime < mutePeriod) {
      text_layer_set_text(alarm_layer, "** MUTE **");
      muteTime += 1;
    } else {
      isMuted = 0;
      muteTime = 0;
    }
  }
  
  
  // Do FFT analysis if we have filled the buffer with data.
  if (accDataFull) {
    do_analysis();
    if (fallActive) check_fall();  // sets fallDetected global variable.
    // Check the alarm state, and set the global alarmState variable.
    alarm_check();
    
    // If no seizure detected, modify alarmState to reflect potential fall
    // detection
    if ((alarmState == ALARM_STATE_OK) && (fallDetected==1))
      alarmState = ALARM_STATE_FALL;
    
    //  Display alarm message on screen.
    if (alarmState == ALARM_STATE_OK) {
      text_layer_set_text(alarm_layer, "OK");
    }
    if (alarmState == ALARM_STATE_WARN) {
      //vibes_short_pulse();
      text_layer_set_text(alarm_layer, "WARNING");
    }
    if (alarmState == ALARM_STATE_ALARM) {
      //vibes_long_pulse();
      text_layer_set_text(alarm_layer, "** ALARM **");
    }
    if (alarmState == ALARM_STATE_FALL) {
      //vibes_long_pulse();
      text_layer_set_text(alarm_layer, "** FALL **");
    }
    if (isManAlarm) {
      alarmState = ALARM_STATE_MAN_ALARM;
      text_layer_set_text(alarm_layer, "** MAN ALARM **");
    }
    if (isMuted) {
      alarmState = ALARM_STATE_MUTE;
      text_layer_set_text(alarm_layer, "** MUTE **");
    }    
    
    // Send data to phone if we have an alarm condition.
    // or if alarm state has changed from last time.
    if ((alarmState != ALARM_STATE_OK && !isMuted) ||
	(alarmState != lastAlarmState)) {
      sendSdData();
    }
    lastAlarmState = alarmState;
  }
  
  // See if it is time to send data to the phone.
  dataUpdateCount++;
  if (dataUpdateCount>=dataUpdatePeriod) {
    sendSdData();
    dataUpdateCount = 0;
  }
 
  // Update the display
  text_layer_set_text(text_layer, "OpenSeizureDetector");
  if (clock_is_24h_style()) {
    strftime(s_time_buffer, sizeof(s_time_buffer), "%H:%M:%S", tick_time);
  } else {
    strftime(s_time_buffer, sizeof(s_time_buffer), "%I:%M:%S", tick_time);
  }
  text_layer_set_text(clock_layer, s_time_buffer);
  BatteryChargeState charge_state = battery_state_service_peek();
  snprintf(s_batt_buffer,sizeof(s_batt_buffer),
  	   "%d%%", 
  	   charge_state.charge_percent);
  text_layer_set_text(batt_layer, s_batt_buffer);
}
Пример #2
0
/************************************************************************
 * clock_tick_handler() - Analyse data and update display.
 * Updates the text layer clock_layer to show current time.
 * This function is the handler for tick events.*/
static void clock_tick_handler(struct tm *tick_time, TimeUnits units_changed) {
  static char s_time_buffer[16];
  static char s_alarm_buffer[64];
  static char s_buffer[256];
  static int analysisCount=0;

  /* Only process data every ANALYSIS_PERIOD seconds */
  analysisCount++;
  if (analysisCount>=ANALYSIS_PERIOD) {
    // Do FFT analysis
    if (accDataFull) {
      do_analysis();
      if (fallActive) check_fall();  // sets fallDetected global variable.
      // Check the alarm state, and set the global alarmState variable.
      alarm_check();

      // If no seizure detected, modify alarmState to reflect potential fall
      // detection
      if ((alarmState == 0) && (fallDetected==1)) alarmState = 3;

      //  Display alarm message on screen.
      if (alarmState == 0) {
	text_layer_set_text(alarm_layer, "OK");
      }
      if (alarmState == 1) {
	//vibes_short_pulse();
	text_layer_set_text(alarm_layer, "WARNING");
      }
      if (alarmState == 2) {
	//vibes_long_pulse();
	text_layer_set_text(alarm_layer, "** ALARM **");
      }
      if (alarmState == 3) {
	//vibes_long_pulse();
	text_layer_set_text(alarm_layer, "** FALL **");
      }
      // Send data to phone
      sendSdData();
    }
    // Re-set counter.
    analysisCount = 0;
  }
 

  // Update data display.
  //snprintf(s_buffer,sizeof(s_buffer),
  //	   "max=%d, P=%ld\n%d Hz",
  //	   /*latestAccelData.x, latestAccelData.y, latestAccelData.z,*/
  //	   maxVal,specPower,maxFreq
  //	   );
  text_layer_set_text(text_layer, "OpenSeizureDetector");

  // and update clock display.
  if (clock_is_24h_style()) {
    strftime(s_time_buffer, sizeof(s_time_buffer), "%H:%M:%S", tick_time);
  } else {
    strftime(s_time_buffer, sizeof(s_time_buffer), "%I:%M:%S", tick_time);
  }
  BatteryChargeState charge_state = battery_state_service_peek();
  snprintf(s_time_buffer,sizeof(s_time_buffer),
	   "%s %d%%", 
	   s_time_buffer,
	   charge_state.charge_percent);
  text_layer_set_text(clock_layer, s_time_buffer);
}