Example #1
0
/**************************************************************************//**
 * @brief
  *  Set the VIS_RANGE bit of the optical sensor
  *  Si114x.
 * @param[in] vis_range_bit
 *   the boolean value to set the bit to
 * @return
 *   Returns 0.
 *****************************************************************************/
int Si114x_EnableVisRange(int vis_range_bit)
{	s16         retval = 0;
	if( vis_range_bit == 1 )
		retval += Si114xParamSet(si114x_handle, PARAM_ALSVIS_ADC_MISC, RANGE_EN);
	else
		retval += Si114xParamSet(si114x_handle, PARAM_ALSVIS_ADC_MISC, 0);

	return retval;
}
/**************************************************************************//**
 * @brief
  *  Initializes and configures the Si1147 sensor.
 * @param[in] i2c
 *   The I2C peripheral to use (not used).
 * @param[in] addr
 *   The I2C address of the sensor.
 * @param[in] lowpower
 *   Set to 1 to initialize without autonomous mode (low power) or set to 0
 *   to enable autonomous mode.
 * @return
 *   Returns 0 on success.
 *****************************************************************************/
int Si1147_ConfigureDetection(I2C_TypeDef *i2c, uint8_t addr, int lowpower)
{
  s16          retval = 0;
  SI114X_CAL_S si114x_cal;
  si114x_handle->addr = addr;
  si114x_handle->i2c  = i2c;


  /* Note that the Si114xReset() actually performs the following functions: */
  /*     1. Pauses all prior measurements */
  /*     2. Clear  i2c registers that need to be cleared */
  /*     3. Clears irq status to make sure INT* is negated */
  /*     4. Delays 10 ms */
  /*     5. Sends HW Key */
  retval += Si114xReset(si114x_handle);

  retval += Si114xWriteToRegister(si114x_handle, REG_PS_LED21, (LED1I << 4) + LED2I);
  retval += Si114xWriteToRegister(si114x_handle, REG_PS_LED3, LED3I);



  /* UV Coefficients */
  si114x_get_calibration(si114x_handle, &si114x_cal, 1);
  si114x_set_ucoef(si114x_handle, 0, &si114x_cal);



  retval += Si114xParamSet(si114x_handle, PARAM_CH_LIST, GESTURE_TASKLIST | UV_TASKLIST);

  retval += Si114xWriteToRegister(si114x_handle, REG_IRQ_ENABLE, GESTURE_IRQ);

  retval += Si114xParamSet(si114x_handle, PARAM_PS_ADC_MISC, 0x24);  /* PS_ADC_MISC to high signal range */
  retval += Si114xParamSet(si114x_handle, PARAM_PS1_ADC_MUX, 0x00);  /* PS1_ADCMUX, PS2_ADCMUX, PS3_ADCMUX to small photodiode */
  retval += Si114xParamSet(si114x_handle, PARAM_PS2_ADC_MUX, 0x00);
  retval += Si114xParamSet(si114x_handle, PARAM_PS3_ADC_MUX, 0x00);

  /* Configure the ALS IR channel for the same settings as PS */

  retval += Si114xParamSet(si114x_handle, PARAM_ALSIR_ADC_MISC, RANGE_EN);
  retval += Si114xParamSet(si114x_handle, PARAM_ALSVIS_ADC_MISC, RANGE_EN);

  if (!lowpower)
  {
    /* Set up how often the device wakes up to make measurements (10ms) */
    retval += Si114xWriteToRegister(si114x_handle, REG_MEAS_RATE_MSB, (MEASRATE_FAST & 0xff00) >> 8);
    retval += Si114xWriteToRegister(si114x_handle, REG_MEAS_RATE_LSB, MEASRATE_FAST & 0x00ff);
    /* Enable Autonomous Operation */
    retval += Si114xPsAlsAuto(si114x_handle);

  }
Example #3
0
/**************************************************************************//**
 * @brief
  *  Initializes and configures the Si1146 sensor for UV index measurements.
 * @param[in] fullInit
 *   The I2C peripheral to use (not used).
 * @param[in] handle
 *   The si114x handle for programmer's toolkit
 * @return
 *   Returns 0 on success.
 *****************************************************************************/
int Si114x_ConfigureUV(int fullInit, HANDLE *handle)
{
  s16          retval = 0;
  SI114X_CAL_S si114x_cal;

  /* Set handle */
  si114x_handle = *handle;

  /* Note that the Si114xReset() actually performs the following functions: */
  /*     1. Pauses all prior measurements */
  /*     2. Clear  i2c registers that need to be cleared */
  /*     3. Clears irq status to make sure INT* is negated */
  /*     4. Delays 10 ms */
  /*     5. Sends HW Key */
  if (fullInit)
     retval += Si114xReset(si114x_handle);

  /* UV Coefficients */
  si114x_get_calibration(si114x_handle, &si114x_cal, 0);
  si114x_set_ucoef(si114x_handle, 0, &si114x_cal);


  if (fullInit)
  {
     retval += Si114xParamSet(si114x_handle, PARAM_CH_LIST, UV_TASKLIST);
     retval += Si114xWriteToRegister(si114x_handle, REG_IRQ_ENABLE, IE_ALS_EVRYSAMPLE);

     retval += Si114xParamSet(si114x_handle, PARAM_PS_ADC_MISC, 0x24);  /* PS_ADC_MISC to high signal range */
     retval += Si114xParamSet(si114x_handle, PARAM_PS1_ADC_MUX, 0x00);  /* PS1_ADCMUX, PS2_ADCMUX, PS3_ADCMUX to small photodiode */
     retval += Si114xParamSet(si114x_handle, PARAM_PS2_ADC_MUX, 0x00);
     retval += Si114xParamSet(si114x_handle, PARAM_PS3_ADC_MUX, 0x00);
  }
  /* Configure the ALS IR channel for the same settings as PS */
  retval += Si114xParamSet(si114x_handle, PARAM_ALSIR_ADC_MISC, RANGE_EN);
  retval += Si114xParamSet(si114x_handle, PARAM_ALSVIS_ADC_MISC, RANGE_EN);
  /* If nothing went wrong after all of this time, the value */
  /* returned will be 0. Otherwise, it will be some negative */
  /* number */
  return retval;
}
Example #4
0
File: main.c Project: IceyP/DECA
int main()
{
	// variable declarations
	int usr_sel;
	int s16_current = 0x0bbb;
	int s16_tasklist = -1;
	int s16_measrate = 0x84;
	int gest_cnt = 0;
	s16 SI114x_ret_val = -1;
	u8 SI114x_write_val;
	u8 SI114x_ret_val_array[8];
	u8* SI114x_ptr = &SI114x_ret_val_array;

	// data structure declarations
	SI114X_IRQ_SAMPLE  samples;
	gesture_t  gest = NONE;
	HANDLE si114x_handle;
	si114x_handle = 0;

	// main program
	printf("\nGesture Sensor program starting... Please wait...\n\n");
	
	// initializing the I2C bus @ addr = I2C_OPENCORES_0_BASE
	printf("Initializing I2C bus...\n");
	I2C_init(I2C_OPENCORES_0_BASE, (alt_32) 50000000, (alt_32) 200000);
	
	// reset the Si1143 Gesture IC
	printf("Resetting Si1143 Gesture Sensor...\n");
	SI114x_ret_val = Si114xReset(si114x_handle);
	if ( SI114x_ret_val != 0 )	// if reset is successful...
	{
		printf("Si1143 Reset completed successfully!\n");
		
		// set IR LED current values to a default level
		printf("Setting LED current values...\n");
		u8 i21, i3;
		i21 = 0xbb; // current = LEDI_202;
		i3  = 0x0b;
		SI114x_ret_val+=Si114xWriteToRegister(si114x_handle, REG_PS_LED21, i21);
		SI114x_ret_val+=Si114xWriteToRegister(si114x_handle, REG_PS_LED3 , i3);
	}
	else	// if reset fails, exit
	{
		printf("Si1143 Reset failed... Exiting...\n");
		return -1;
	}
	// gesture recognition loop
	printf("Entering main loop...\n Loop exits after 32 gestures are recognized.\n");
	// have Si1143 measure all three proximity channels, the visual channel, and the IR channel
	s16_tasklist = PS1_TASK + PS2_TASK + PS3_TASK + ALS_VIS_TASK + ALS_IR_TASK;
	SI114x_ret_val+=Si114xParamSet(si114x_handle, PARAM_CH_LIST, s16_tasklist);

	while ( gest_cnt <= 32 ){
		// make measurement
		SI114x_ret_val = Si114xPsAlsForce(si114x_handle);
		//usleep(10000);	// uncomment if you need a pause in measurements
		if ( SI114x_ret_val > 0 ){	// if measurement is successful...
			// retrieve data from sensor and put it in struct "samples"
			DECA_si1143_irq_pop(si114x_handle, &samples);
			// process data in gesture algorithm
			gest = ProcessSi1143Samples(&samples);
			
			// report the gesture and increment counter
			if ( gest != NONE ) gest_cnt++;
			if ( gest == UP ) printf("UP swipe detected!\n");
			if ( gest == DOWN ) printf("DOWN swipe detected!\n");
			if ( gest == LEFT ) printf("LEFT swipe detected!\n");
			if ( gest == RIGHT ) printf("RIGHT swipe detected!\n");
			if ( gest == TAP ) printf("TAP detected!\n");
		}
		else printf("Unable to force measurement...\n");
	}

	return 0;
}