Example #1
0
__interrupt void port_0_isr(void)
{
  EA = 0;
  ENERGEST_ON(ENERGEST_TYPE_IRQ);

  /* This ISR is for the entire port. Check if the interrupt was caused by our
   * button's pin. */
  if(BUTTON_IRQ_CHECK(1)) {
    if(timer_expired(&debouncetimer)) {
      timer_set(&debouncetimer, CLOCK_SECOND / 4);
      sensors_changed(&button_sensor);
    }
  }else if(BUTTON_IRQ_CHECK(2)) {
    if(timer_expired(&debouncetimer)) {
      timer_set(&debouncetimer, CLOCK_SECOND / 4);
      sensors_changed(&button_2_sensor);
    }
  }else if(BUTTON_IRQ_CHECK(3)) {
    if(timer_expired(&debouncetimer)) {
      timer_set(&debouncetimer, CLOCK_SECOND / 4);
      sensors_changed(&button_3_sensor);
    }
  }
  

  BUTTON_IRQ_FLAG_OFF(1);
  BUTTON_IRQ_FLAG_OFF(2);
  BUTTON_IRQ_FLAG_OFF(3);

  ENERGEST_OFF(ENERGEST_TYPE_IRQ);
  EA = 1;
}
Example #2
0
__interrupt void port_1_isr(void) 
{
  EA = 0;
  ENERGEST_ON(ENERGEST_TYPE_IRQ);

  /* This ISR is for the entire port. Check if the interrupt was caused by our
   * button's pin. */
  if(BUTTON_IRQ_CHECK(1)) {
    if(timer_expired(&debouncetimer)) {
      timer_set(&debouncetimer, CLOCK_SECOND / 8);
      sensors_changed(&button_1_sensor);
    }
  }
  if(BUTTON_IRQ_CHECK(2)) {
    if(timer_expired(&debouncetimer)) {
      timer_set(&debouncetimer, CLOCK_SECOND / 8);
#if CC2531_CONF_B2_REBOOTS
      watchdog_reboot();
#else /* General Purpose */
      sensors_changed(&button_2_sensor);
#endif
    }
  }

  BUTTON_IRQ_FLAG_OFF(1);
  BUTTON_IRQ_FLAG_OFF(2);

  ENERGEST_OFF(ENERGEST_TYPE_IRQ);
  EA = 1;
}
Example #3
0
void kbi4_isr(void) {
	if(timer_expired(&debouncetimer)) {
		timer_set(&debouncetimer, CLOCK_SECOND / 4);
		sensors_changed(&button_sensor);
	}
	clear_kbi_evnt(4);
}
/**
  * @brief GPIO EXTI callback
  * @param uint16_t GPIO_Pin
  * @retval None
  */
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
#if defined(MCU_STOP_MODE)/*if MCU is in stop mode*/        

  /* Clear Wake Up Flag */
  __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
      
  /* Configures system clock after wake-up from STOP: enable HSE, PLL and select
    PLL as system clock source (HSE and PLL are disabled in STOP mode) */
    SystemClockConfig_STOP(); 
#endif
#if defined(MCU_SLEEP_MODE) 
    /* Resume Tick interrupt if disabled prior to sleep mode entry*/
    HAL_ResumeTick();
#endif 
    
    /* Initialize LEDs*/
    RadioShieldLedInit(RADIO_SHIELD_LED);
    //BSP_LED_Init(LED2); 

  if (GPIO_Pin == USER_BUTTON_PIN)
  {
    sensors_changed(&button_sensor);
  }

}
Example #5
0
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
#if defined(MCU_STOP_MODE)/*if MCU is in stop mode*/

  /* Clear Wake Up Flag */
  __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);

  /* Configures system clock after wake-up from STOP: enable HSE, PLL and select
    PLL as system clock source (HSE and PLL are disabled in STOP mode) */
    SystemClockConfig_STOP();
#endif
#if defined(MCU_SLEEP_MODE)
    /* Resume Tick interrupt if disabled prior to sleep mode entry*/
    HAL_ResumeTick();
#endif

  if (GPIO_Pin == USER_BUTTON_PIN)
  {
    sensors_changed(&button_sensor);
  }
#ifdef SPWF04
  if(GPIO_Pin == WIFI_SPI_EXTI_PIN) {
    WIFI_SPI_IRQ_Callback();
  }
#endif
}
Example #6
0
/*---------------------------------------------------------------------------*/
void extint_detection_callback(void)
{
  if(timer_expired(&debouncetimer)) {
    timer_set(&debouncetimer, CLOCK_SECOND / 8);
    sensors_changed(&button_sensor);
  }
}
Example #7
0
/**
 * \brief Handler for Sensortag-CC26XX button presses
 */
static void
button_press_handler(uint8_t ioid)
{
  if(ioid == BOARD_IOID_KEY_LEFT) {
    if(!timer_expired(&left_timer.debounce)) {
      return;
    }

    timer_set(&left_timer.debounce, DEBOUNCE_DURATION);

    /*
     * Start press duration counter on press (falling), notify on release
     * (rising)
     */
    if(ti_lib_gpio_pin_read(BOARD_KEY_LEFT) == 0) {
      left_timer.start = clock_time();
      left_timer.duration = 0;
    } else {
      left_timer.duration = clock_time() - left_timer.start;
      sensors_changed(&button_left_sensor);
    }
  }

  if(ioid == BOARD_IOID_KEY_RIGHT) {
    if(BUTTON_SENSOR_ENABLE_SHUTDOWN == 0) {
      if(!timer_expired(&right_timer.debounce)) {
        return;
      }

      timer_set(&right_timer.debounce, DEBOUNCE_DURATION);

      /*
       * Start press duration counter on press (falling), notify on release
       * (rising)
       */
      if(ti_lib_gpio_pin_read(BOARD_KEY_RIGHT) == 0) {
        right_timer.start = clock_time();
        right_timer.duration = 0;
      } else {
        right_timer.duration = clock_time() - right_timer.start;
        sensors_changed(&button_right_sensor);
      }
    } else {
      lpm_shutdown(BOARD_IOID_KEY_RIGHT);
    }
  }
}
Example #8
0
/**
 * \brief Callback registered with the GPIO module. Gets fired with a button
 * port/pin generates an interrupt
 * \param port The port number that generated the interrupt
 * \param pin The pin number that generated the interrupt. This is the pin
 * absolute number (i.e. 0, 1, ..., 7), not a mask
 */
static void
btn_callback(uint8_t port, uint8_t pin)
{
  if(!timer_expired(&debouncetimer)) {
    return;
  }

  timer_set(&debouncetimer, CLOCK_SECOND / 8);
  
  if((port == GPIO_F_NUM) && (pin == BUTTON_SW1_PIN_NO)) {
      printf("SW1\n");
      sensors_changed(&button_sw1_sensor);
  }
  else if((port == GPIO_F_NUM) && (pin == BUTTON_SW2_PIN_NO)) {
      printf("SW2\n");
      sensors_changed(&button_sw2_sensor);
  }
}
static void temperature_sensor_handler(int value)
{
  if (--samplingCounter) return;
  samplingCounter = SAMPLING_TIME;
  if (CurrentValue != value) {
    CurrentValue = value;
    sensors_changed(&temperature_sensor);
    //printf("%d\r\n",CurrentValue);
  }
}
Example #10
0
/*---------------------------------------------------------------------------*/
static void
notify_ready(void *not_used)
{
  enabled = HDC_1000_SENSOR_STATUS_READINGS_READY;

  /* Latch readings */
  read_data();

  sensors_changed(&hdc_1000_sensor);
}
Example #11
0
/**
 * \brief Interrupt handler for the user button.
 *
 * \param port The port number that generated the interrupt
 * \param pin The pin number that generated the interrupt.
 *
 * This function is called inside interrupt context.
 */
static void
user_button_irq_handler(uint8_t port, uint8_t pin)
{
  if(!timer_expired(&debouncetimer)) {
    return;
  }

  timer_set(&debouncetimer, CLOCK_SECOND / 8);
  sensors_changed(&button_sensor);
}
Example #12
0
/*---------------------------------------------------------------------------*/
static int
irq(void)
{
    if(PIR_CHECK_IRQ()) {
        ++pir;
        if(flags & PIR_ENABLE_EVENT) {
            sensors_changed(&pir_sensor);
        }
        return 1;
    }
    return 0;
}
Example #13
0
/*---------------------------------------------------------------------------*/
static void
doInterfaceActionsBeforeTick(void)
{
  // Check if button value has changed
  if(simButtonChanged && simButtonIsActive && simButtonIsDown) {
    if(timer_expired(&debouncetimer)) {
      timer_set(&debouncetimer, CLOCK_SECOND / 10);
      sensors_changed(&button_sensor);
    }
  }
  simButtonChanged = 0;
}
/**
 * \brief Callback registered with the GPIO module. Gets fired with a button
 * port/pin generates an interrupt
 * \param port The port number that generated the interrupt
 * \param pin The pin number that generated the interrupt. This is the pin
 * absolute number (i.e. 0, 1, ..., 7), not a mask
 */
static void
btn_callback(uint8_t port, uint8_t pin)
{
	//it's not self-explanatory. we don't need debounce, because frequency sensor is connected to that "button".
	if((port == BUTTON_RIGHT_PORT) && (pin == BUTTON_RIGHT_PIN)){
		sensors_changed(&button_right_sensor);
	}else if(!timer_expired(&debouncetimer)) {
    		return;
  	}else{
		timer_set(&debouncetimer, CLOCK_SECOND / 8);
		if((port == BUTTON_SELECT_PORT) && (pin == BUTTON_SELECT_PIN)){
    			sensors_changed(&button_select_sensor);
		}else if((port == BUTTON_LEFT_PORT) && (pin == BUTTON_LEFT_PIN)){
      			sensors_changed(&button_left_sensor);
		}else if((port == BUTTON_UP_PORT) && (pin == BUTTON_UP_PIN)){
      			sensors_changed(&button_up_sensor);
	      	}else if((port == BUTTON_DOWN_PORT) && (pin == BUTTON_DOWN_PIN)){
      			sensors_changed(&button_down_sensor);
	      	}
	}
}
Example #15
0
/*---------------------------------------------------------------------------*/
static int
value(int type)
{
  if(!active()){
    return 0;
  }


#if DEBOUNCE
  if(timer_expired(&debouncetimer)) {

    if(halGetButtonStatus(BUTTON_S1) == BUTTON_PRESSED){

      timer_set(&debouncetimer, CLOCK_SECOND / 10);
      if(BUTTON_HAS_BEEN_RELEASED()){ // Button has been previously released.
        sensors_changed(&button_sensor);
      }
      BUTTON_SET_PRESSED();

      return 1;
    }
    else {
      BUTTON_SET_RELEASED();
      return 0;
    }
  }
  else {
    return 0;
  }
#else
  if(halGetButtonStatus(BUTTON_S1) == BUTTON_PRESSED){
    sensors_changed(&button_sensor);
    return 1;
  }
  else {
    return 0;
  }
#endif

}
Example #16
0
/*---------------------------------------------------------------------------*/
static void
extint_detection_callback(void)
{
  bool pin_state = port_pin_get_input_level(BUTTON_0_PIN);
  pin_state = pin_state;

  if(!timer_expired(&debouncetimer)) {
    return;
  }

  sensors_changed(&button_sensor);
  timer_set(&debouncetimer, DEBOUNCE_TIME);
}
Example #17
0
/*---------------------------------------------------------------------------*/
static int
irq(void)
{
  if(BUTTON_CHECK_IRQ()) {
    if(timer_expired(&debouncetimer)) {
      timer_set(&debouncetimer, CLOCK_SECOND / 4);
      sensors_changed(&button_sensor);
      return 1;
    }
  }

  return 0;
}
static void
myHandler(void)
{
  /* Change the internal resistance state
   * (pull-up -> pull-down // pull-down -> pull-up)
   */
  PRESENCE_RESISTOR_PULL_SWAP();
  /*
   * Change the level detection
   * (up -> down // down up)
   */
  PRESENCE_IRQ_EDGE_SWAP();
  /* Notify the sensor module */
  sensors_changed(&PIR_555_28027_sensor);
}
Example #19
0
/*---------------------------------------------------------------------------*/
void BUTTON_S1_ISR(void)
{
  
  ENERGEST_ON(ENERGEST_TYPE_IRQ);
  
  //sensors_handle_irq(IRQ_BUTTON);
  
   if(INT_GPIOFLAG & BUTTON_S1_FLAG_BIT) {
    
#if DEBOUNCE
    if(timer_expired(&debouncetimer)) {
      timer_set(&debouncetimer, CLOCK_SECOND / 5);
      sensors_changed(&button_sensor);
    }
#else
    sensors_changed(&button_sensor);
#endif
    
  }
  
  INT_GPIOFLAG = BUTTON_S1_FLAG_BIT;  
  
  ENERGEST_OFF(ENERGEST_TYPE_IRQ);  
}
Example #20
0
/**
 * \brief Callback registered with the GPIO module. Gets fired with a button
 * port/pin generates an interrupt
 * \param port The port number that generated the interrupt
 * \param pin The pin number that generated the interrupt. This is the pin
 * absolute number (i.e. 0, 1, ..., 7), not a mask
 */
static void
btn_callback(uint8_t port, uint8_t pin)
{
  /* Check if the debounce timer is still active. If so, skip this button
     press. */
  if (!timer_expired(&debouncetimer)) {
    return;
  }

  /* Start the timer to ignore any upcoming bounces */
  timer_set(&debouncetimer, CLOCK_SECOND / 8);

  /* Make sure that we should notify upper level applications */
  if (port == RELAY_BUTTON_PORT && pin == RELAY_BUTTON_PIN) {
    sensors_changed(&relay_button_sensor);
  }
}
Example #21
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(key_sampling, ev, data)
{
  PROCESS_BEGIN();
  static struct etimer et;
  static int previous_key_value = 0;
  static char debounce_check = 0;
  int current_key_value;

  etimer_set(&et, CLOCK_SECOND / 50);
  while(1) {
    PROCESS_WAIT_EVENT_UNTIL((ev == PROCESS_EVENT_TIMER) || (ev == PROCESS_EVENT_MSG));
    if(ev == PROCESS_EVENT_TIMER) {
      /* Handle sensor reading.   */
      PRINTF("Key sample\n");
      current_key_value = get_key_value();
      if(debounce_check != 0) {
        /* Check if key remained constant */
        if(previous_key_value == current_key_value) {
          sensors_changed(&button_sensor);
          key_value = current_key_value;
          debounce_check = 0;
        } else {
          /* Bouncing */
          previous_key_value = current_key_value;
        }
      } else
      /* Check for new key change */
      if(current_key_value != previous_key_value) {
        previous_key_value = current_key_value;
        debounce_check = 1;
      }
      etimer_reset(&et);
    } else {
      /* ev == PROCESS_EVENT_MSG */
      if(*(buttons_status_t *)data == BUTTONS_STATUS_NOT_ACTIVE) {
        /* Stop sampling */
        etimer_stop(&et);
      } else if((*(buttons_status_t *)data == BUTTONS_STATUS_ACTIVE)) {
        /* restart sampling */
        etimer_restart(&et);
      }
    }
  }
  PROCESS_END();
}
Example #22
0
     irq_p2(void)
{
  ENERGEST_ON(ENERGEST_TYPE_IRQ);

  if(BUTTON_CHECK_IRQ()) {
    if(timer_expired(&debouncetimer)) {
      timer_set(&debouncetimer, CLOCK_SECOND / 4);
      sensors_changed(&button_sensor);
      LPM4_EXIT;
    }
  }
//Added by Atena as the ISR for P2.3 which will be connected to the precipitation sensor with pulse output
//*****************************************************************************************
  if(P2IFG & BIT3){
pulses++;
 P2IFG = 0x00;
  ENERGEST_OFF(ENERGEST_TYPE_IRQ);
}
}
static void
irq(irq_t s)
{
  switch(s) {
  case IRQ_ADC1:
    x = u16AHI_AdcRead();
    break;
  case IRQ_ADC2:
    y = u16AHI_AdcRead();
    break;
  case IRQ_ADC3:
    z = u16AHI_AdcRead();
    break;
  default:
    break;
  }

  sensors_changed(&acc_sensor);
}
Example #24
0
/**
 * \brief Callback registered with the GPIO module. Gets fired with a button
 * port/pin generates an interrupt
 * \param port The port number that generated the interrupt
 * \param pin The pin number that generated the interrupt. This is the pin
 * absolute number (i.e. 0, 1, ..., 7), not a mask
 */
static void
btn_callback(uint8_t port, uint8_t pin)
{
  if(!timer_expired(&debouncetimer)) {
    return;
  }

  timer_set(&debouncetimer, DEBOUNCE_DURATION);

  if(press_duration) {
    press_event_counter = 0;
    if(value(BUTTON_SENSOR_VALUE_TYPE_LEVEL) == BUTTON_SENSOR_PRESSED_LEVEL) {
      ctimer_set(&press_counter, press_duration, duration_exceeded_callback,
                 NULL);
    } else {
      ctimer_stop(&press_counter);
    }
  }

  sensors_changed(&button_sensor);
}
Example #25
0
/* Process to get ht sensor value.
   ht sensor is sampled. Sampling stopped when sensor is de-activated.
   Event is generated if temp and/or hum value changed at least the value DELTA_TEMP_SENSOR_VALUE
   or DELTA_HUM_SENSOR_VALUE since last event. */
PROCESS_THREAD(HTSensorSampling, ev, data)
{
  PROCESS_BEGIN();
  static struct etimer et;

  etimer_set(&et, CLOCK_SECOND);
  while(1) {
    PROCESS_WAIT_EVENT_UNTIL((ev == PROCESS_EVENT_TIMER) || (ev == PROCESS_EVENT_MSG));
    if(ev == PROCESS_EVENT_TIMER) {
      /* Handle sensor reading. */
      vHTSstartReadTemp();
      temp_sensor_value = u16HTSreadTempResult();
      PRINTF("Temperature sample: %d\n", temp_sensor_value);
      vHTSstartReadHumidity();
      hum_sensor_value = u16HTSreadHumidityResult();
      PRINTF("Humidity sample: %d\n", hum_sensor_value);
      if((abs(temp_sensor_value - prev_temp_event_val) > DELTA_TEMP_SENSOR_VALUE) ||
         (abs(hum_sensor_value - prev_hum_event_val) > DELTA_HUM_SENSOR_VALUE)) {
        prev_temp_event_val = temp_sensor_value;
        prev_hum_event_val = hum_sensor_value;
        sensors_changed(&ht_sensor);
      }
      etimer_reset(&et);
    } else {
      /* ev == PROCESS_EVENT_MSG */
      if(*(int *)data == HT_SENSOR_STATUS_NOT_ACTIVE) {
        /* Stop sampling */
        etimer_stop(&et);
      } else if((*(int *)data == HT_SENSOR_STATUS_ACTIVE)) {
        /* restart sampling */
        etimer_restart(&et);
      }
    }
  }
  PROCESS_END();
}
Example #26
0
void
GPIO_timer_callback(void *n)
{
static uint8_t GPIO_handle;

 GPIO_handle = n;
 switch (GPIO_handle) {

 case 0x10:
  if (GPIO_READ_PIN(GPIO_C_BASE, GPIO_handle ) == 0) {
   onboard_timer.start = clock_time();
   onboard_timer.duration = 0;
   onboard_timer.status = 0xAA;
  }
  else if (onboard_timer.status==0xAA) {
   onboard_timer.duration = clock_time() - onboard_timer.start;
   sensors_changed(&button_onboard_sensor);
   onboard_timer.status = 0;
  }
  break;
 case 0x1:
  if (GPIO_READ_PIN(GPIO_D_BASE, GPIO_handle ) == 0) {
   GPIO1_timer.start = clock_time();
   GPIO1_timer.duration = 0;
   GPIO1_timer.status = 0xAA;
  }
  else {
   GPIO1_timer.duration = clock_time() - GPIO1_timer.start;
   sensors_changed(&button_GPIO1_sensor);
   GPIO1_timer.status = 0x0;
  }
  break;
 case 0x2:
  if (GPIO_READ_PIN(GPIO_D_BASE, GPIO_handle ) == 0) {
   GPIO0_timer.start = clock_time();
   GPIO0_timer.duration = 0;
   GPIO0_timer.status = 0xAA;
  }
  else {
   GPIO0_timer.duration = clock_time() - GPIO0_timer.start;
   sensors_changed(&button_GPIO0_sensor);
   GPIO0_timer.status = 0x0;
  }
  break;

 case 0x4:
  if (GPIO_READ_PIN(GPIO_D_BASE, GPIO_handle ) == 0) {
   leds_on(LEDS_RED);
   clock_delay_usec(1000);
   leds_off(LEDS_RED);
   GPIO2_timer.start = clock_time();
   GPIO2_timer.duration = 0;
   GPIO2_timer.status = 0xAA;
  }
  else if (GPIO2_timer.status==0xAA){
   leds_on(LEDS_GREEN);
   clock_delay_usec(1000);
   leds_off(LEDS_GREEN);
   GPIO2_timer.duration = clock_time() - GPIO2_timer.start;
   sensors_changed(&button_GPIO2_sensor);
   GPIO2_timer.status = 0x0;
  }
  break;


  }
}
Example #27
0
static void
acc_startsample(bool status)
{ /* this callback is *not* called in irq-context */
  if (acc_active) i2c(&acc_transaction);
  sensors_changed(&acc_sensor);
}
Example #28
0
/*---------------------------------------------------------------------------*/
void
button_press(void)
{
  sensors_changed(&button_sensor);
}
Example #29
0
/*---------------------------------------------------------------------------*/
void
pir_sensor_changed(int strength)
{
  pir_value += strength;
  sensors_changed(&pir_sensor);
}
/*---------------------------------------------------------------------------*/
static void
notify_ready(void *not_used)
{
  state = SENSOR_STATE_ENABLED;
  sensors_changed(&mpu_9250_sensor);
}