예제 #1
0
int acc_init(int bus) {
  uint8_t buf[2];
  //init and reset chip`
  if (ioctl(imu_fd, I2C_SLAVE, ADXL345_I2C_ADDR) < 0) {
    printf("ERROR: unable to set acc address\n");
    return -1;
  }

  buf[0] = ADXL345_POWER_CTL;
  buf[1] = ADXL345_POWER_ON;
  if (write(imu_fd, buf, 2) != 2) {
    printf("ERROR: couldn't write to imu\n");
    return -1;
  }

  buf[0] = ADXL345_DATA_FORMAT;
  buf[1] = ADXL345_16G | ADXL345_FULL_RES;
  if (write(imu_fd, buf, 2) != 2) {
    printf("ERROR: couldn't write to imu\n");
    return -1;
  }

  //2.5V sensitivity is 256 LSB/g = 0.00390625 g/bit
  //3.3V x and y sensitivity is 265 LSB/g = 0.003773584 g/bit, z is the same

  acc_offsets[0] = 0.003773584;
  acc_offsets[1] = 0.003773584;
  acc_offsets[2] = 0.00390625;

  acc_update();
}
예제 #2
0
int
newepoch_gen(char *out,epoch_item_t *ep,setup_params_t *setup)
{
      char *accstr = NULL;
      int elem_size = 0;
      
      //update the accumulator 
      acc_update(ep->acc,ep->epls.act,ep->epls.rvk,setup);
      ep->epoch++;
      //sign epoch revoked list
      sign_list_rsa(ep->s_rvk,setup,ep->epls.rvk);
      //sign epoch added list      
      sign_list_rsa(ep->s_new,setup,ep->epls.act);

      elem_size = element_length_in_bytes(ep->acc->elem);
      accstr = (char *) malloc(elem_size);
      if(!accstr) {
            pbgp_error("newepoch :: %s\n",strerror(errno));
            return -1;
      }

      element_snprintf(accstr,elem_size,"%B",ep->acc->elem);
      //sign accumulator value
      sign_rsa(ep->s_acc,setup,(uint8_t *)accstr);

      //dump envelope
      newepoch_save(out,ep,setup);
      
      free(accstr); 
      return 0;  
}
예제 #3
0
/*! \brief This is an example demonstrating the accelerometer
 *         functionalities using the accelerometer driver.
 */
int main(void)
{
  volatile unsigned long i;

  // switch to oscillator 0
  pm_switch_to_osc0(&AVR32_PM, FOSC0, OSC0_STARTUP);

  // Initialize the debug USART module.
  init_dbg_rs232(FOSC0);

  acc_init();

  // do a loop
  for (;;)
  {
    // slow down operations
    for ( i=0 ; i < 50000 ; i++);

    // display a header to user
    print_dbg("\x1B[2J\x1B[H\r\n\r\nAccelerometer Example\r\n\r\n");

    // Get accelerometer acquisition and process data
    acc_update();

    // test for fast or slow changes
    // depending on that, play with angles or moves
    if ( is_acc_slow() )
    {
      print_mouse() ;
      print_angles() ;
    }
    else
      print_move() ;

    // MEUH
    // only text here , needs to be combined with PWM
    // meuh_stop is the "end" signal from PWM
    meuh_en = is_acc_meuh( meuh_stop ) ;
  }
}
예제 #4
0
//!
//! @brief Looks for mouse events.
//!
bool is_usb_mouse_event( void )
{
   static uint8_t   disp=1;
   static uint16_t  count=0;
#if BOARD != EVK1104 && BOARD != UC3C_EK && BOARD != EVK1105
   static bool old_click_0=false;  // false means released, true means pushed
   static bool old_click_1=false;  // false means released, true means pushed
#endif
#if BOARD == EVK1100
   static bool old_click_2=false;  // false means released, true means pushed
#endif
   bool b_activity;

   u8_report_buttons=0;
   u8_report_disp_x=0;
   u8_report_disp_y=0;
   u8_report_disp_wheel=0;
   b_activity=false;

#if BOARD == EVK1101
   signed int res;

   // Get accelerometer acquisition and process data
   acc_update();

   // Look joystick activity for the Wheel events
   // input is pulled up, if 1 : input is not active
   if( is_joystick_up() )
     u8_report_disp_wheel=disp, b_activity=true;

   if( is_joystick_down() )
     u8_report_disp_wheel=-disp, b_activity=true;

   // Look accelerometer activity for the X and Y events
   if( 0!=(res=is_acc_abs_angle_x(40)) )
   {
     if(      res>0 )
       u8_report_disp_x=-10*disp, b_activity=true;
     else if( res<0 )
       u8_report_disp_x=10*disp, b_activity=true;
   }
   else if( 0!=(res=is_acc_abs_angle_x(30)) )
   {
     if(      res>0 )
       u8_report_disp_x=-6*disp, b_activity=true;
     else if( res<0 )
       u8_report_disp_x=6*disp, b_activity=true;
   }
   else if( 0!=(res=is_acc_abs_angle_x(20)) )
   {
     if(      res>0 )
       u8_report_disp_x=-4*disp, b_activity=true;
     else if( res<0 )
       u8_report_disp_x=4*disp, b_activity=true;
   }

   else if( 0!=(res=is_acc_abs_angle_x(15)) )
   {
     if(      res>0 )
       u8_report_disp_x=-2*disp, b_activity=true;
     else if( res<0 )
       u8_report_disp_x=2*disp, b_activity=true;
   }
   else if( 0!=(res=is_acc_abs_angle_x(10)) )
   {
     if(      res>0 )
       u8_report_disp_x=-disp, b_activity=true;
     else if( res<0 )
       u8_report_disp_x=disp, b_activity=true;
   }



   if( 0!=(res=is_acc_abs_angle_y(40)) )
   {
     if(      res>0 )
       u8_report_disp_y=-10*disp, b_activity=true;
     else if( res<0 )
       u8_report_disp_y=10*disp, b_activity=true;
   }
   else if( 0!=(res=is_acc_abs_angle_y(30)) )
   {
     if(      res>0 )
       u8_report_disp_y=-6*disp, b_activity=true;
     else if( res<0 )
       u8_report_disp_y=6*disp, b_activity=true;
   }
   else if( 0!=(res=is_acc_abs_angle_y(20)) )
   {
     if(      res>0 )
       u8_report_disp_y=-4*disp, b_activity=true;
     else if( res<0 )
       u8_report_disp_y=4*disp, b_activity=true;
   }
   else if( 0!=(res=is_acc_abs_angle_y(15)) )
   {
     if(      res>0 )
       u8_report_disp_y=-2*disp, b_activity=true;
     else if( res<0 )
       u8_report_disp_y=2*disp, b_activity=true;
   }
   else if( 0!=(res=is_acc_abs_angle_y(10)) )
   {
     if(      res>0 )
       u8_report_disp_y=-disp, b_activity=true;
     else if( res<0 )
       u8_report_disp_y=disp, b_activity=true;
   }

#elif BOARD == EVK1100

   // Look Joystick activity for the X and Y events
   // input is pulled up, if 1 : input is not active
   if (is_joystick_right())
      u8_report_disp_x=disp, b_activity=true;

   if (is_joystick_left())
      u8_report_disp_x=-disp, b_activity=true;

   if (is_joystick_down())
      u8_report_disp_y=disp, b_activity=true;

   if (is_joystick_up())
      u8_report_disp_y=-disp, b_activity=true;

#elif BOARD == EVK1105

   // Right
   if (is_touch_sensor_2())
      u8_report_disp_x=disp, b_activity=true;
   // Left
   if (is_touch_sensor_3())
      u8_report_disp_x=-disp, b_activity=true;
   // Down
   if (is_touch_sensor_1())
      u8_report_disp_y=disp, b_activity=true;
   // Up
   if (is_touch_sensor_0())
      u8_report_disp_y=-disp, b_activity=true;

#elif BOARD == EVK1104
   if (gpio_get_pin_value(GPIO_PUSH_BUTTON_SW2) == GPIO_PUSH_BUTTON_SW2_PRESSED)
      u8_report_disp_y=-disp, b_activity=true;
#elif BOARD == UC3C_EK
   // mouse pointer down
   if( !gpio_get_pin_value(GPIO_PUSH_BUTTON_0)) {
     u8_report_disp_y=disp, b_activity=true;
   }

      // mouse pointer up
   if( !gpio_get_pin_value(GPIO_PUSH_BUTTON_1)) {
     u8_report_disp_y=-disp, b_activity=true;
   }
#endif

   if( b_activity )
   {
      count++;
      if( count >= DISP_LIMIT_HIGH )
         disp=3;
      else if( count >= DISP_LIMIT_LOW )
         disp=2;
   }
   else
      count=0, disp=1;



   // Look for button activity
#if BOARD != EVK1104 && BOARD != UC3C_EK && BOARD != EVK1105
   // input is pulled up, if 1 : input is not active
   if( (!gpio_get_pin_value(GPIO_PUSH_BUTTON_0))
   ||  (is_joystick_pressed()                  ) )
   {
      Set_bits(u8_report_buttons, BUTTON_0_EVENT_PUSH);
      if( old_click_0==false )
         old_click_0=true, b_activity=true;
   }
   else
      if( old_click_0==true )
         old_click_0=false, b_activity=true;



   if( !gpio_get_pin_value(GPIO_PUSH_BUTTON_1) )
   {
      Set_bits(u8_report_buttons, BUTTON_1_EVENT_PUSH);
      if( old_click_1==false )
         old_click_1=true, b_activity=true;
   }
   else
      if( old_click_1==true )
         old_click_1=false, b_activity=true;
#endif
#if BOARD == EVK1100
   if( !gpio_get_pin_value(GPIO_PUSH_BUTTON_2) )
   {
      Set_bits(u8_report_buttons, BUTTON_2_EVENT_PUSH);
      if( old_click_2==false )
         old_click_2=true, b_activity=true;
   }
   else
      if( old_click_2==true )
         old_click_2=false, b_activity=true;
#endif

   if( b_activity )  return true;
   else              return false;
}
예제 #5
0
void imu_update() {
  acc_update();
  //gyro_update();
  mag_update();
}