Exemplo n.º 1
0
void timer_intr(void)
{
  timer_systime_counter.low++;
  if(timer_systime_counter.low >= TIMER_SYSTIME_LOW_RESO) {
    timer_systime_counter.high++;
    timer_systime_counter.low = 0;
  }

  pic_eoi(PIC_IRQ_TIMER);	/* notify "Reception completion" to PIC */
/*
{
  static char i=0;
  int pos;
  char s[4];
  byte2hex(i,s);
  i++;
  pos = console_getpos();
  console_locatepos(77,0);
  console_puts(s);
  console_putpos(pos);
}
*/
  alarm_check();

  task_tick();
  task_dispatch();

  return;
}
Exemplo n.º 2
0
void alarm_2_update(int upper, int lower) {
	alarm_2_upper_setpoint = upper;
	alarm_2_lower_setpoint = lower;
	update_setpoint_icon(2, true, upper != SETPOINT_OFF);
	update_setpoint_icon(2, false, lower != SETPOINT_OFF);
	alarm_check();
}
Exemplo n.º 3
0
/**
  * @brief  This function handles RTC_IRQHandler .
  * @param  None
  * @retval : None
  */
void RTC_IRQHandler(void)
{
    NVIC_ClearPendingIRQ(RTC_IRQn);
    RTC_ClearITPendingBit(RTC_IT_SEC);

    CalculateTime();
    alarm_check(alarm_buffer_ptr);

    /* If counter is equal to 86399: one day was elapsed */
    /* This takes care of date change and resetting of counter in case of
    power on - Run mode/ Main supply switched on condition*/
    if(RTC_GetCounter() == 86399)
    {
        /* Wait until last write operation on RTC registers has finished */
        RTC_WaitForLastTask();
        /* Reset counter value */
        RTC_SetCounter(0x0);
        /* Wait until last write operation on RTC registers has finished */
        RTC_WaitForLastTask();

        /* Increment the date */
        DateUpdate();
    }
}
Exemplo n.º 4
0
void update_temp2(int t) {
	master_temp2 = t;
	ditoa(temp2_str, sizeof(temp2_str), t);
	text_layer_set_text(temp2_layer, temp2_str);
	alarm_check();
}
Exemplo n.º 5
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);
}
Exemplo n.º 6
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);
}