Esempio n. 1
0
void usb_hid_com_send_report_in(void)
{
	// Fill HID report fields
	report_to_send.light = adc_sensor_get_light();
	report_to_send.temperature = adc_sensor_get_temperature();
	report_to_send.ext_voltage = adc_sensor_get_ext_voltage();
	report_to_send.potentiometer = adc_sensor_get_potentiometer();
	report_to_send.buttons = ui_button();
	report_to_send.sensor_selected = main_get_sensor_selected();
	// Send HID report in background
	udi_hid_generic_send_report_in((uint8_t*)&report_to_send);
}
Esempio n. 2
0
void main_sof_action(void)
{
	// LCD strings for on-board sensors
	static uint8_t lcd_txt_light[LCD_TEXT_STRING_SIZE + 2 * LCD_TEST_DISPLAY_SIZE]
			= "LIGHT SENSOR     ";
	static uint8_t lcd_txt_ntc[LCD_TEXT_STRING_SIZE + 2 * LCD_TEST_DISPLAY_SIZE]
			= "TEMPERATURE SENSOR     ";
	static uint8_t lcd_txt_pot[LCD_TEXT_STRING_SIZE + 2 * LCD_TEST_DISPLAY_SIZE]
			= "POTENTIOMETER INPUT     ";
	static uint8_t lcd_txt_ext_v[LCD_TEXT_STRING_SIZE + 2 * LCD_TEST_DISPLAY_SIZE]
			= "EXTERNAL VOLTAGE    ";

	static uint8_t old_button;

	if (main_timeout_user_message) {
		// Currently LCD is busy displaying user message from USB
		// Wait end of timeout to display again sensor message
		if (--main_timeout_user_message == 0) {
			switch (main_sensor_selected) {
			case LIGHT_SENSOR:
				ui_display_text(lcd_txt_light,
					sizeof(lcd_txt_light));
				break;
			case TEMPERATURE_SENSOR:
				ui_display_text(lcd_txt_ntc,
					sizeof(lcd_txt_ntc));
				break;
			case POTENTIOMETER_SENSOR:
				ui_display_text(lcd_txt_pot,
					sizeof(lcd_txt_pot));
				break;
			case EXT_VOLTAGE_INPUT:
				ui_display_text(lcd_txt_ext_v,
					sizeof(lcd_txt_ext_v));
			default:
				break;
			}
		}
	}

	// Change LOCAL text display when a button is pressed...
	if (old_button!=ui_button()) {
		old_button=ui_button();
		if (ui_pusb_button_0()) {
			ui_display_text(lcd_txt_light, sizeof(lcd_txt_light));
			main_sensor_selected = LIGHT_SENSOR;
		}
		if (ui_pusb_button_1()) {
			ui_display_text(lcd_txt_ntc, sizeof(lcd_txt_ntc));
			main_sensor_selected = TEMPERATURE_SENSOR;
		}
		if (ui_pusb_button_2()) {
			ui_display_text(lcd_txt_pot, sizeof(lcd_txt_pot));
			main_sensor_selected = POTENTIOMETER_SENSOR;
		}
		if (ui_pusb_button_3()) {
			ui_display_text(lcd_txt_ext_v, sizeof(lcd_txt_ext_v));
			main_sensor_selected = EXT_VOLTAGE_INPUT;
		}
		// If hid generic interface is not up and running, do nothing
		if (!main_b_generic_enable) {
			return;
		}
	}

	// Prepare new report each HID_SEND_REPORT_MS ms
	if ((udd_get_frame_number() % HID_SEND_REPORT_MS) == 0) {
		usb_hid_com_send_report_in();
	}

	// Prepare new ADC samples each ADC_NEW_SAMPLE_MS ms
	if ((udd_get_frame_number() % ADC_NEW_SAMPLE_MS) == 0) {
		adc_sensors_start_conversions();
	}

	// Each LCD_SCROLLING_MS ms Performs LCD scrolling
	if ((udd_get_frame_number() % LCD_SCROLLING_MS) == 0) {
		ui_scroll_text();
	}

	// Refresh on-board sensors LCD display
	// each LCD_SENSOR_MS and if no user message is displayed
	if (((udd_get_frame_number() % LCD_SENSOR_MS) == 0)
		&& (main_timeout_user_message == 0)) {
		switch (main_sensor_selected) {
		case LIGHT_SENSOR:
			ui_display_sensor(adc_sensor_get_light(),
					UI_UNIT_NONE);
			break;
		case TEMPERATURE_SENSOR:
			ui_display_sensor(adc_sensor_get_temperature(),
					UI_UNIT_DEGREE_C);
			break;
		case POTENTIOMETER_SENSOR:
			ui_display_sensor(adc_sensor_get_potentiometer(),
					UI_UNIT_MILIVOLT);
			break;
		case EXT_VOLTAGE_INPUT:
			ui_display_sensor(adc_sensor_get_ext_voltage(),
					UI_UNIT_MILIVOLT);
		default:
			break;
		}
	}
}