/* Timer driven function to sample ADC and emit signal if bounds call for it */ void gpio_sensor::adc_read(void) { int adc_reading = sensor_read(); // qDebug() << time_since_start.elapsed() << adc_reading; /* in_bounds means emit a signal if value is inside bounds */ if (in_bounds) { // qDebug() << "signaling if in_bounds"; if ((adc_reading > low_bound) && (adc_reading < high_bound)) { if (was_out_last_time) { emit (adc_signal(adc_reading)); } /* endif */ was_out_last_time = false; } else { was_out_last_time = true; } /* endif */ } else { /* Otherwise, emit a signal if value is outside bounds */ // qDebug() << "out_bounds"; if ((adc_reading < low_bound) || (adc_reading > high_bound)) { if (!was_out_last_time) { emit (adc_signal(adc_reading)); } /* endif */ was_out_last_time = true; } else { was_out_last_time = false; } /* endif */ } /* endif */ } /* adc_read */
void do_send(void * arg) { intercom::Sender sender(3); while (true) { sleep(1); intercom::DataMessage msg; msg.createTextMsg("Hello, World!"); sender.send(msg); sleep(1); const uint8_t can_data[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; msg.createCanMsg(0x100, sizeof(can_data), can_data); sender.send(msg); sleep(1); intercom::DataMessage::PwmSignal pwm_signal('Miry', 300, 10000); msg.createPwmMsg(pwm_signal); sender.send(msg); sleep(1); intercom::DataMessage::AdcSignal adc_signal('Miry', 31337); msg.createAdcMsg(adc_signal); sender.send(msg); } }