int main(int argc, char* argv[])
{

	int handle = -1; 
	print_banner();




	handle = PasInit();
	PasStart(handle);


	printf("\n--------------- Detect devices -------------------------------------------\n");
	test_find_devices(handle);

	printf("\n-------------- Number of Channels ----------------------------------------\n");
	test_channels(handle);

	printf("\n-------------- Sensor attributes -----------------------------------------\n");	
	test_print_some_good_stuff_for_all_sensors(handle);

	printf("\n-------------- Read one shot data ----------------------------------------\n");
	test_read_data(handle,2); /* 2 -- do the test twice */

	printf("\n-------------- Read continous data ---------------------------------------\n");	
	test_read_continuous_data(handle,2); /* 2 -- do the test twice */
	

	PasStop(handle);
	PasDelete(handle);
	
#ifdef _WINDOWS
	// do this on windows since the cmd window might close automatically otherwise
	printf("\n>>>>Press enter to end the program<<<<\n");
	getchar();
#endif
	
	return 0;
}
Beispiel #2
0
/** \brief Proximity Sensor gesture recognition demo application entry
 *
 * This application uses a 3-channel proximity sensor to recognize simple
 * gestures.  When a proximity event occurs, the routine will wake up from
 * a low-power sleep mode and begin repeatedly sampling the proximity
 * sensor, until the proximity of the object is no longer detected.  Then
 * the beginning and ending sensor readings are compared, and the overall
 * direction of the object's movement is determined based on a lookup table.
 *
 * Once the direction is determined, it is indicate by turning on one of the
 * LEDs on the controller board and (optionally) by serial output to a
 * terminal device.  If the direction cannot be determined, all indicator
 * LEDs will be blinked rapidly.
 *
 * The application then resets by returning to a low-power sleep mode until
 * the next proximity event is detected.
 */
int main(void)
{
	uint8_t start_channels;    /* First channels detecting proximity */
	uint8_t current_channels;  /* Current channels detecting proximity */
	uint8_t end_channels;      /* Final channels detecting proximity */
	direction_t direction;     /* Calculated gesture direction */
	int i;

	/* Initialize the board (Xplained UC3 or XMEGA & Xplained Sensor boards)
	 * I/O pin mappings and any other configurable resources selected in
	 * the build configuration.
	 */
	sensor_platform_init();

	/* Turn on LEDs while initialization completes */
	LED_On(UP_LED);
	LED_On(DOWN_LED);
	LED_On(LEFT_LED);
	LED_On(RIGHT_LED);

	/* Initialize the MCU sleep manager API and specify a sleep mode. */
	sleepmgr_init();
	sleepmgr_lock_mode(SLEEP_MODE);

	/* Attach and initialize proximity sensor */
	sensor_attach(&prox_dev, SENSOR_TYPE_PROXIMITY, 0, 0);

	if (prox_dev.err) {
		puts("\r\nProximity sensor initialization error.");

		while (true) {
			/* Error occurred, loop forever */
		}
	}

#if (USE_PRINTF == true)
	uint32_t id;      /* Device ID */
	uint8_t version;  /* Device version */

	sensor_device_id(&prox_dev, &id, &version);
	printf("\r\nProximity sensor: %s    ID = 0x%02x ver. 0x%02x\r\n",
			prox_dev.drv->caps.name, (unsigned)id,
			(unsigned)version);
#endif

	/* Set sample rate */
	sensor_set_sample_rate(&prox_dev, PROX_SAMPLE_RATE);

	/* Select all proximity sensor channels */
	sensor_set_channel(&prox_dev, SENSOR_CHANNEL_ALL);
	
#if (SET_PROX_THRESHOLD == true)
	/* Manually  set proximity threshold values for each channel */
	/*  Otherwise, sensor will use values previously stored in nvram. */
	sensor_set_threshold(&prox_dev, SENSOR_THRESHOLD_NEAR_PROXIMITY,
			PROX_THRESHOLD);
#endif

#if (SET_PROX_CURRENT == true)
	/* Manually set LED current value for each channel */
	/*  Otherwise, sensor will use default values */
	sensor_set_current(&prox_dev, PROX_CURRENT_mA);
#endif

	/* Set up close proximity event to wakeup system */
	sensor_add_event(&prox_dev, SENSOR_EVENT_NEAR_PROXIMITY,
			prox_event_handler, 0, false);

	while (true) {
		/* Enable proximity event */
		sensor_enable_event(&prox_dev, SENSOR_EVENT_NEAR_PROXIMITY);

		/* Delay before putting device to sleep */
		delay_ms(10);

		/* Put device in low power sleep mode; wait for an interrupt to
		 * wake. */
		LED_Off(UP_LED);
		LED_Off(DOWN_LED);
		LED_Off(LEFT_LED);
		LED_Off(RIGHT_LED);

		/* Enter specified sleep mode */
		sleepmgr_enter_sleep();

		/* Only do sensor processing if proximity event woke device up */
		if (prox_event_occurred) {
			prox_event_occurred = false;

			/* Disable new proximity events during gesture sampling */
			sensor_disable_event(&prox_dev,
					SENSOR_EVENT_NEAR_PROXIMITY);

			/* Get starting value saved by event handler routine */
			start_channels = test_channels(&prox_data);
			end_channels = start_channels;

			/* Loop until no longer detecting proximity */
			do {
				/* Get new readings from sensor */
				sensor_get_proximity(&prox_dev, &prox_data);

				current_channels = test_channels(&prox_data);

				/* Update end value if proximity is still
				 * detected */
				if (current_channels != CHAN_NONE) {
					end_channels = current_channels;
				}
			} while (current_channels != CHAN_NONE);

			/* Get direction from lookup table based on start/end
			 * channel sets */
			direction = dir_tbl [start_channels] [end_channels];

#if USE_PRINTF
			/* Display direction */
			printf("Start: %s  End: %s  Direction: %s \r\n",
					channel_labels[start_channels],
					channel_labels[end_channels],
					direction_labels[direction]);
#endif

			/* Use LEDs to display direction */
			switch (direction) {
			case UP:
				LED_On(UP_LED);
				break;

			case DOWN:
				LED_On(DOWN_LED);
				break;

			case LEFT:
				LED_On(LEFT_LED);
				break;

			case RIGHT:
				LED_On(RIGHT_LED);
				break;

			default: 
				/* Unknown - blink all LEDs to indicate */
				for (i = 0; i < (ERR_BLINK_COUNT * 2); i++) {
					LED_Toggle(UP_LED);
					LED_Toggle(DOWN_LED);
					LED_Toggle(LEFT_LED);
					LED_Toggle(RIGHT_LED);

					delay_ms(50);
				}
				break;
			}
		}
		
		delay_ms(500);
	}
	
	return 0;
}