void print(){ printX(); printY(); printZ(); }
//_______________________________________________________________________________________________________ int main(int argc, char** argv) { parseArgs(argc, argv); printf("\n"); printY("[TEST] Test conditions:\n"); if (m_start_dsp) printG("\tDisplay\n"); else printR("\tDisplay\n"); if (m_start_imu) printG("\tIMU\n"); else printR("\tIMU\n"); if (m_start_imu && m_start_env) printG("\tEnvSens\n"); else if (m_start_imu && !m_start_env) printR("\tEnvSens\n"); else if (!m_start_imu && m_start_env) printR("\tskipping EnvSens (IMU needs to be enabled!)\n"); else printR("\tEnvSens\n"); if (m_start_ldc) printG("\tLDC\n"); else printR("\tLDC\n"); if (m_start_bat) printG("\tBatGauge\n"); else printR("\tBatGauge\n"); printf("\n"); printY("[TEST] Init devices...\n"); printf("\n"); fflush(stdout); // Set up display if (m_start_dsp) m_dsp = new display_edison(m_dsp_resolution, m_dsp_hands); // Set up IMU if (m_start_imu) { m_imu = new imu_edison(m_i2c_bus, m_mpu_address, m_start_env); m_imu->setupIMU(); } // Set up LDC if (m_start_ldc) m_ldc = new ldc_edison(m_i2c_bus); // Start battery gauge if (m_start_bat) { m_bat = new batgauge_edison(m_i2c_bus); m_bat->setAlertThreshold(m_alert_threshold); } printf("\n"); usleep(1000000); // start testing bool success = true; // test display if (m_start_dsp) { printY("[TEST] Drawing clock on display...\n"); printf("\n"); m_dsp->clear(); m_dsp->analogClock(true); m_dsp->flush(); } // test IMU if (m_start_imu) { printY("[TEST] Testing IMU...\n"); printf("IMU "); if (!IDtest(m_imu->getID(), m_imu_ID)) success = false; printf("MAG "); if (!IDtest(m_imu->getMagID(), m_mag_ID)) success = false; if (!m_idonly) { std::vector<float> data = m_imu->toReadable(m_imu->readRawIMU()); float mx, my, mz; m_imu->getCompassData(mx, my, mz); printf("Temperature [DegC]:\n\t%f\n", data[6]); printf("Accelerometer [m/s^2]:\n"); printf("\tX: %f\n", data[0]); printf("\tY: %f\n", data[1]); printf("\tZ: %f\n", data[2]); printf("Gyroscope [deg/s]:\n"); printf("\tX: %f\n", data[3]); printf("\tY: %f\n", data[4]); printf("\tZ: %f\n", data[5]); printf("Compass [mGs]:\n"); printf("\tX: %f\n", mx); printf("\tY: %f\n", my); printf("\tZ: %f\n", mz); } printf("\n"); fflush(stdout); } // test EnvSens if (m_start_imu && m_start_env) { printY("[TEST] Testing environmental sensor...\n"); if (!IDtest(m_imu->getEnvID(), m_env_ID)) success = false; if (!m_idonly) { float T, P, H; m_imu->getEnvData(T, P, H); printf("Temperature [DegC]: %f\n", T); printf("Pressure [hPa]: %f\n", P); printf("Humidity [%%RH]: %f\n", H); } printf("\n"); fflush(stdout); } // test LDC if (m_start_ldc) { printY("[TEST] Testing LDC...\n"); if (!IDtest(m_ldc->getVersion(), m_ldc_ID)) success = false; if (!m_idonly) { std::vector<uint16_t> LDC(2, 0); LDC = m_ldc->getADC(); printf("ADC0 (vis/IR) [raw]: %i\n", LDC[0]); printf("ADC1 (IR) [raw]: %i\n", LDC[1]); } printf("\n"); fflush(stdout); } // test BatGauge if (m_start_bat) { printY("[TEST] Testing battery gauge...\n"); if (!IDtest(m_bat->getVersion(), m_bat_ID)) success = false; if (!m_idonly) { printf("Voltage: %fV\n", m_bat->getVCell()); printf("State of Charge: %i%%\n", m_bat->getSoC()); printf("Alert Threshold: %i%%\n", m_bat->getAlertThreshold()); } printf("\n"); fflush(stdout); } if (success) printG("[TEST] All ID tests successful.\n"); else printR("[TEST] Some ID tests failed!\n"); if (m_start_bat) delete m_bat; if (m_start_ldc) delete m_ldc; if (m_start_imu) delete m_imu; if (m_start_dsp) delete m_dsp; if (success) return 0; else return 1; }