本文整理汇总了C++中Serial::poll方法的典型用法代码示例。如果您正苦于以下问题:C++ Serial::poll方法的具体用法?C++ Serial::poll怎么用?C++ Serial::poll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Serial
的用法示例。
在下文中一共展示了Serial::poll方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
/* declarations */
bool special_mode;
indications command, last_command;
indication_mode pattern;
unsigned char buffer[32];
Serial serial;
PID accel;
/* initialize hardware */
leds_init();
buttons_init();
timer1_init();
/* setup control loop for brake light */
pid_zeroize(&accel);
accel.proportional_gain = 1.0f;
accel.integral_gain = 0.0f;
accel.derivative_gain = 0.0f;
/* initialize and read the lsm303 */
lsm303_begin();
lsm303_read();
/* setup usb serial port */
serial.begin();
/* initialize pattern settings */
last_command = ind_off;
command = ind_off;
pattern = off;
/* set light/indication mode to PWM driven */
brake_lights(pwm);
//brake_lights(off);
/* reset leds and animation driver */
turn_signal(command, pattern);
leds_reset();
/* check to see if switch is depressed on startup */
command = get_signal_switch_status();
if(command != ind_off)
{
special_mode = true;
}
else
{
special_mode = false;
}
while(true)
{
/* control brake light using mag/accel data */
brake_light_control(&accel);
/* check to see if the user input has changed state */
command = get_signal_switch_status();
/* if "special mode" is enabled, play a fancy animation on idle */
if(special_mode && (command == ind_off))
{
/* animation selection */
command = ind_hazard;
pattern = loop;
}
else
{
/* default pattern, no command override */
pattern = scroll;
}
/* if the user input has changed, update the pattern driver state */
if (command != last_command)
{
leds_reset();
turn_signal(command, pattern);
}
if(serial.available()) {
int size = serial.read(buffer);
if (size!=0) {
serial.write((const uint8_t*)buffer, size);
serial.write('\n');
}
}
serial.poll();
/* debounce user input */
last_command = command;
_delay_ms(3);
}
return 0;
}