int main(void) { // Initialize the UART,Timers, and I2C1v Board_init(); Board_configure(USE_SERIAL | USE_LCD | USE_TIMER); dbprint("Check encoder addr\n"); I2C_init(ENCODER_I2C_ID, I2C_CLOCK_FREQ); uint8_t pitchAddress = readDevice(SLAVE_PITCH_READ_ADDRESS, SLAVE_PITCH_WRITE_ADDRESS, READ_DIAGNOSTIC_ADDRESS); uint8_t yawAddress = readDevice(SLAVE_YAW_READ_ADDRESS, SLAVE_YAW_WRITE_ADDRESS, READ_DIAGNOSTIC_ADDRESS); dbprint("Pitch=0x%X\nYaw=0x%X\n",pitchAddress, yawAddress); return SUCCESS; }
static void accumulateAngle(uint8_t deviceReadAddress, uint8_t deviceWriteAddress) { float rawAngle = readDevice(deviceReadAddress, deviceWriteAddress, READ_ANGLE_ADDRESS) * DEGREE_PER_NUMBER; // Decide which edge to stay on if (accumulatorIndex == 0) { accumulateOnLowEdge = (rawAngle <= (MIN_DEGREE + DELTA_DEGREE))? TRUE : FALSE; } // Did we start on 0 side, and teetered over to 360 side? if (accumulateOnLowEdge && (rawAngle >= (MAX_DEGREE - DELTA_DEGREE))) rawAngle -= MAX_DEGREE; // makes it negative // Did we start on 360 side and teetered over to the 0 side? if (!accumulateOnLowEdge && (rawAngle <= (MIN_DEGREE + DELTA_DEGREE))) rawAngle += MAX_DEGREE; /* if (accumulateOnLowEdge && (rawAngle <= MAX_DEGREE && rawAngle >= (MAX_DEGREE - DELTA_DEGREE)) || !accumulateOnLowEdge && (rawAngle >= MIN_DEGREE && rawAngle <= (MIN_DEGREE + DELTA_DEGREE))) rawAngle = 0.0f; */ angleAccumulator += rawAngle; }
void TrackEditor::connectDevice() { // QDialog *devdlg = new QDialog(this); // Ui::DeviceDialog dlg; // dlg.setupUi(devdlg); CDeviceDialog *devdlg = new CDeviceDialog(this); devdlg->setModal(true); int retval = devdlg->exec(); if(retval == QDialog::Accepted) { qDebug("OK pressed."); CSerialPortSettings settings = devdlg->getPortSettings(); m_serial_port = new QextSerialPort(settings.getName(), settings); bool res = m_serial_port->open( QIODevice::ReadWrite ); connect(m_serial_port, SIGNAL(readyRead()), this, SLOT(readDevice())); // openTTY("/dev/rfcomm0", 115200); m_device_io = new CWintec("WBT201"); connect(this, SIGNAL(emitData(QByteArray)), m_device_io, SLOT(addData(QByteArray))); connect(m_device_io, SIGNAL(sendData(QByteArray)), this, SLOT(sendData(QByteArray))); connect(m_device_io, SIGNAL(nemaString(QString)), ui.nemaText, SLOT(appendPlainText(QString))); connect(m_device_io, SIGNAL(progress(int)), this, SLOT(progress(int))); connect(m_device_io, SIGNAL(readLogFinished()), this, SLOT(readLogFinished())); connect(m_device_io, SIGNAL(newTrack(Track*)), this, SLOT(newTrack(Track*))); connect(m_device_io, SIGNAL(newWayPoint(TrackPoint*)), this, SLOT(newWayPoint(TrackPoint*))); connect(m_device_io, SIGNAL(newLogPoint(TrackPoint*)), this, SLOT(newLogPoint(TrackPoint*))); // readDevice(); ui.action_Read_Log->setDisabled(false); }
void *run(void *ptr_shared_data) { char cTmp[MAX_LINE]; int l_change = 0; g_ptr_shared_data = (struct shared_data *) ptr_shared_data; // Initialize datarefs g_comFreq = g_ptr_shared_data->comFreq; last_mainloop_idle = sys_time_clock_get_time_usec(); // while stop == 0 calculate position. while (g_ptr_shared_data->stop == 0) { long loop_start_time = sys_time_clock_get_time_usec(); /////////////////////////////////////////////////////////////////////////// /// CRITICAL FAST 20 Hz functions /////////////////////////////////////////////////////////////////////////// if (us_run_every(50000, COUNTER3, loop_start_time)) { // read usb board values l_change = readDevice(&g_usb_data); // Update xplane updateHost(); // Update board updateBoard(); } /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// /// NON-CRITICAL SLOW 10 Hz functions /////////////////////////////////////////////////////////////////////////// else if (us_run_every(100000, COUNTER6, loop_start_time)) { //update_screen(); } /////////////////////////////////////////////////////////////////////////// if (loop_start_time - last_mainloop_idle >= 100000) { writeLog("CRITICAL WARNING! CPU LOAD TOO HIGH.\n"); last_mainloop_idle = loop_start_time;//reset to prevent multiple messages } else { //writeConsole(0, 0, "CPU LOAD OK."); } // wait 1 milliseconds #if IBM Sleep(1); #endif #if LIN usleep(10); #endif g_counter++; } sprintf(cTmp, "thread closing usb device %d...\n", 0); writeLog(cTmp); closeDevice(); sprintf(cTmp, "thread info : stopping thread #%d, %d!\n", g_ptr_shared_data->thread_id, g_counter); writeLog(cTmp); pthread_exit(NULL); return 0; }
QString KDesktopFile::readURL() const { if(hasDeviceType()) { QString device = readDevice(); KMountPoint::List mountPoints = KMountPoint::possibleMountPoints(); for(KMountPoint::List::ConstIterator it = mountPoints.begin(); it != mountPoints.end(); ++it) { KMountPoint *mp = *it; if(mp->mountedFrom() == device) { KURL u; u.setPath(mp->mountPoint()); return u.url(); } } return QString::null; } else { QString url = readPathEntry("URL"); if(!url.isEmpty() && !QDir::isRelativePath(url)) { // Handle absolute paths as such (i.e. we need to escape them) KURL u; u.setPath(url); return u.url(); } return url; } }
bool Database::read(MAHandle h) { DataHandler data(h); int nDevices; TEST(data.read(&nDevices, sizeof(int))); devices.resize(nDevices); for(int i=0; i<nDevices; i++) { TEST(readDevice(data, devices[i])); } return true; }
/** * Thread main loop : * This is the polling routine of the joystick handler. */ void *Joystick::run(void *) { struct timespec rqtp, rmtp; struct js_event jse; while(!done) { // read the Joystick file descriptor until no more events are available. while (readDevice(&jse) == true) { if (jse.type & 0x80) continue; // Skip JS_EVENT_INIT (0x80) events. switch(jse.type) { case JS_EVENT_BUTTON: { // Inform the listener that button event occurs. bool pressed = (jse.value != 0); listener->buttonChanged(jse.number, pressed); } break; case JS_EVENT_AXIS: { // Inform the listener that axis event occurs. switch(jse.number) { case 0: listener->xAxisChanged(jse.value); break; case 1: listener->yAxisChanged(jse.value); break; } } break; default: break; } } // No more event to handle. // Sleep for the polling period. rqtp.tv_sec = 0; rqtp.tv_nsec = pollingPeriod * 1000 * 1000; nanosleep(&rqtp, &rmtp); } return NULL; }
static int getInputPacket (unsigned char *packet) { return readDevice(0X80, packet, MT_INPUT_PACKET_LENGTH); }