Example #1
0
void board_init_devices(void) {
#if defined(ENVIRONMENT_SENSOR)
    kputs("Initializing i2c\n");
    i2c_init();

    kputs("Initializing Devices... Light,");
    light_init();
#ifdef REPORT_TYPE_GYRO
    kputs("Gyro, ");
    gyro_init();
#endif
#ifdef REPORT_TYPE_ACCEL
    kputs("Accell, ");
    accel_init();
#endif
#ifdef REPORT_TYPE_HUMID
    kputs("Humid, ");
    humid_init();
#endif
    kputs("PIR\n");
    pir_init();
#elif defined POWER_STRIP_MONITOR
    kputs("Initializing Devices... Power\n");
    powermon_init();
#endif

#ifdef USE_PN532
    kputs("Initializing RFID reader... \n");
    rfid_init();
#endif

#ifdef USE_MACHXO2_PMCO2
    kputs("Initializing CO2 and PM extension...\n");
    machxo2_init();
#endif

#ifdef USE_DOOR_SENSORS
    kputs("Initializing Door Sensors...\n");
    door_sensors_init();
#endif
}
Example #2
0
/*************************************************************************************************
          Main
**************************************************************************************************/
void main(void)
{
 
  HAL_BOARD_INIT();
  
  UART_init();
  U0CSR &= ~0x04;
  ENABLE_RX();
  
  /*setup sensors*/
  sensors_init();
  sensor_int_init();
  
  /* Setup LED's */  
  P1DIR |= BV(0);
  P0DIR |= BV(4);
  
  P1_0 = 0;
 
   
  start_gyro(); //start the gyro
  init_acc();   //start the accelerometer
  start_mag();
  start_baro();
  
  //zero_mag();
  
  EA = 1;

  SLEEPCMD |= 0x02;  //pm 2
  
  uint8 flag;
  uint8 IDbyte;
  
  
  uint8 baro_stage = 1;

  
   while(1){      
        
     if (RXin)
     {
      //If it is a cal data request 
      if ( active_sensors & BV(4) )
      {
        flag = 0x03;
        flush_data(&flag);
        baro_read_cal();
        
        //End of line char
        flag = 0x00;
        flush_byte(&flag);
        
      } else if ( active_sensors > 0 ) {
       
     //  P0_4 = 1;
    /**************************************************************************/
    /* Read and transmit sensor data                                          */
    flag = 0x04;
    flush_byte(&flag);   
    flush_byte(&active_sensors);
     
    /*---------------------------------------------------------------------*/ 
    //Read accelerometer and gyro
    
     if ( active_sensors & BV(0) )
     {       
       IDbyte = BV(0);
       flush_data(&IDbyte);
      
      while( !( acc_int_status() ) ); //wait for interrupt 
      read_acc();                 //read the accelerometer

      while( !(gyro_int_status() & BV(0) ) ); //wait for interrupt
      read_gyro();

     }
    
    /*---------------------------------------------------------------------*/
    //Read Magnetometer
    //start_interrupts(MAG_INT);
     
     if ( active_sensors & BV(1) )
     {
       
    
       IDbyte = BV(1);
       flush_data(&IDbyte);
       
       //PCON |= 1;
       while( !(mag_status() & 0x08 ) );
       read_mag();
 
      // mag_sleep(TRUE);  
     } 
    
    /*---------------------------------------------------------------------*/
    //Barometer
    
    //uint16 delay_ticks;
    uint8 baro_res = 2;
    
    
    if ( active_sensors & BV(2) )
    {
       IDbyte = BV(2);
       flush_data(&IDbyte);
       
       if (active_sensors & 0x40)
       {
         //delay_ticks = 0xFA00;
         baro_capture_press(baro_res);
         //while(delay_ticks--);
         baro_read_press(TRUE);
         
         //delay_ticks = 0xFA00;         
         baro_capture_temp();
         //while(delay_ticks--);
         baro_read_temp(TRUE); 
       }else{
      
         uint8 nullbyte = 3;
         switch (baro_stage)
         {
         case 1 :
            baro_capture_press(baro_res);
            baro_read_press(FALSE);
            baro_read_temp(FALSE);
            baro_stage++;
            break;
         case 2 :
            baro_read_press(TRUE);
            baro_read_temp(FALSE);
            baro_stage++;
            break;
         case 3 :
            baro_capture_temp();
            baro_read_press(FALSE);
            baro_read_temp(FALSE);
            baro_stage++;
            break;
         case 4 :
           baro_read_press(FALSE);
           baro_read_temp(TRUE);
           baro_stage = 1;
           break;
         }
       }

      //baro_shutdown();
    }
    
    /*---------------------------------------------------------------------*/
    //Humidity
    
    if ( active_sensors & BV(3) )
    {
      IDbyte = BV(3);
      flush_data(&IDbyte);
      humid_init();
      humid_read_humidity(TRUE);
    }
    
    /*---------------------------------------------------------------------*/

    
    //End of line char
    flag = 0x00;
    flush_byte(&flag);
    
    }
       

    if ( !(active_sensors & BV(5)) )        //if autopoll is off
    {
      P0_4 = 1;
      RXin = 0;                             //clear the RX flag
    }else{
      P0_4 = 0;
    }

    }
    
   IEN0 |= 0x04; 
   U0CSR &= ~0x04;
   }
   
}