/* Initializes the BMP085 configuration to * the I2C1 module. Automatically enables interrupts, * I2C1 module, and the GPIO A Peripheral, and the * callback application for the BMP085 created by TI. * * Input: * abI2cModule * Returns: * none * */ void bmp085Init(uint32_t i2cModule){ if(!bmpI2CInited){ i2cInit(AB_I2C_MODULE_1); I2CMInit(&bmpI2cModuleInstance, i2cGetBase(i2cModule), i2cGetInterruptID(i2cModule), 0xff, 0xff, ROM_SysCtlClockGet()); bmpI2CInited = 1; } BMP180Init(&bmpAppInstance[bmpStructCounter], &bmpI2cModuleInstance, BMP085_I2C_ADDRESS, bmp085AppCallback, &bmpAppInstance[bmpStructCounter]); bmpStructCounter++; while(bmp085_dataFlag == 0); bmp085_dataFlag = 0; }
int main(void) { int delay; float fTemperature, fPressure, fAltitude, fK_Altitude, fAltitude_sum,fK_Altitude_sum; int count,i; // static float f_meas[VAR_COUNT], fAlt_Mean, fAlt_Var; unsigned short sw1_count, sw2_count; unsigned char sw1_was_cleared = 0, sw2_was_cleared = 0; // Set the clocking to run directly from the external crystal/oscillator. MAP_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | WRFL_XTAL); //init ports and peripherals PlatformInit(); Nokia5110_Init(); Nokia5110_Clear(); Nokia5110_DrawFullImage(gears_logo); for(delay=0; delay<1000000; delay=delay+1); Nokia5110_Clear(); Nokia5110_SetCursor(3, 1); Nokia5110_OutString("WRFL"); Nokia5110_SetCursor(1, 2); Nokia5110_OutString("Prototype"); Nokia5110_SetCursor(2, 4); Nokia5110_OutString("VER 0.1"); Nokia5110_SetCursor(0, 5); Nokia5110_OutString("NightMecanic"); for(delay=0; delay<1000000; delay=delay+1); Nokia5110_Clear(); // // Enable interrupts to the processor. // MAP_IntMasterEnable(); // // Initialize I2C1 peripheral. // I2CMInit(&g_sI2CInst, BMP180_I2C_BASE, BMP180_I2C_INT, 0xff, 0xff, MAP_SysCtlClockGet()); // // Initialize the BMP180 // BMP180Init(&g_sBMP180Inst, &g_sI2CInst, BMP180_I2C_ADDRESS, BMP180AppCallback, &g_sBMP180Inst); // // Wait for initialization callback to indicate reset request is complete. // while(g_vui8DataFlag == 0) { // // Wait for I2C Transactions to complete. // } // // Reset the data ready flag // g_vui8DataFlag = 0; //set oversampling to 8x g_sBMP180Inst.ui8Mode = 0xC0; //Initialize the Kalman filter Kalman_Init(&Alt_KState, 0.0f, 1.0f, ALT_KALMAN_R, ALT_KALMAN_Q); // // Enable the system ticks at 10 hz. // MAP_SysTickPeriodSet(MAP_SysCtlClockGet() / (40 * 3)); MAP_SysTickIntEnable(); MAP_SysTickEnable(); Nokia5110_SetCursor(0, 0); Nokia5110_OutString("SW1:"); Nokia5110_SetCursor(0, 2); Nokia5110_OutString("SW2:"); //config done count = 0; // // Begin the data collection and printing. Loop Forever. // while(1) { // SW1 if (sw_state & SW1){ if (sw1_was_cleared){ sw1_was_cleared = 0; sw1_count++; Nokia5110_SetCursor(5, 0); Nokia5110_OutUDec(sw1_count); } }else sw1_was_cleared = 1; //SW2 if (sw_state & SW2){ if (sw2_was_cleared){ sw2_was_cleared = 0; sw2_count++; Nokia5110_SetCursor(5, 2); Nokia5110_OutUDec(sw2_count); } }else sw2_was_cleared = 1; // handle BMP180 data (display average every 50 samples) if (g_vui8DataFlag ){ // // Reset the data ready flag. // g_vui8DataFlag = 0; // // Get a local copy of the latest temperature data in float format. // BMP180DataTemperatureGetFloat(&g_sBMP180Inst, &fTemperature); // // Print temperature with three digits of decimal precision. // //Nokia5110_SetCursor(0, 0); //Nokia5110_OutString("Temp:"); //Nokia5110_OutFloatp3(fTemperature); // // Get a local copy of the latest air pressure data in float format. // BMP180DataPressureGetFloat(&g_sBMP180Inst, &fPressure); // // Print Pressure with three digits of decimal precision. // //Nokia5110_SetCursor(0, 1); // Nokia5110_OutString("Pres:"); //Nokia5110_SetCursor(0, 2); //display in hPa //Nokia5110_OutFloatp3((fPressure / 100.0f)); // // Calculate the altitude. // //fAltitude = 44330.0f * (1.0f - powf(fPressure / 101325.0f, // 1.0f / 5.255f)); //corrected: fAltitude = 44330.0f * (1.0f - powf(fPressure / LOC_ALT_P0, 1.0f / 5.255f)); // Kalman filtered altitude Kalman_Update (&Alt_KState, fAltitude); fK_Altitude = Alt_KState.X; fAltitude_sum += fAltitude; fK_Altitude_sum += fK_Altitude; count++; if (count>=50){ Nokia5110_SetCursor(0, 3); Nokia5110_OutString("Alt:"); Nokia5110_OutFloatp3(fAltitude_sum/50.0); Nokia5110_SetCursor(0, 5); Nokia5110_OutString("KAlt:"); Nokia5110_OutFloatp3(fK_Altitude_sum/50.0); fAltitude_sum = 0; fK_Altitude_sum = 0; count = 0; } /* //calculate variance f_meas[count]=fK_Altitude; count++; if (count>=VAR_COUNT){ fAlt_Mean = 0.0f; fAlt_Var = 0.0f; // calculate mean for(i=0; i<VAR_COUNT; i++){ fAlt_Mean = fAlt_Mean +f_meas[i]; } fAlt_Mean = fAlt_Mean/((float) VAR_COUNT); // Calculate Var for(i=0; i<VAR_COUNT; i++){ fAlt_Var = fAlt_Var + powf((f_meas[i] - fAlt_Mean),2.0f); } fAlt_Var = fAlt_Var/((float) VAR_COUNT); // // Print altitude with three digits of decimal precision. // Nokia5110_SetCursor(0, 4); Nokia5110_OutString("Var:"); Nokia5110_OutFloatp3(fAlt_Var); count = 0; } */ // // Delay to keep printing speed reasonable. About 100msec. // //MAP_SysCtlDelay(MAP_SysCtlClockGet() / (10 * 3)); } }//while end }
void initI2C(void) { uint8_t ui8Mask; SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH); SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C7); GPIOPinConfigure(GPIO_PD0_I2C7SCL); GPIOPinConfigure(GPIO_PD1_I2C7SDA); GPIOPinTypeI2CSCL(GPIO_PORTD_BASE, GPIO_PIN_0); GPIOPinTypeI2C(GPIO_PORTD_BASE, GPIO_PIN_1); // // Configure and Enable the GPIO interrupt. Used for INT signal from the // ISL29023 // GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, GPIO_PIN_5); GPIOIntEnable(GPIO_PORTE_BASE, GPIO_PIN_5); GPIOIntTypeSet(GPIO_PORTE_BASE, GPIO_PIN_5, GPIO_FALLING_EDGE); IntEnable(INT_GPIOE); I2CMInit(&g_sI2CInst, I2C7_BASE, INT_I2C7, 0xff, 0xff, g_SysClock); // // Initialize the SHT21. // SHT21Init(&g_sSHT21Inst, &g_sI2CInst, SHT21_I2C_ADDRESS, SHT21AppCallback, &g_sSHT21Inst); SysCtlDelay(g_SysClock / (100 * 3)); // // Initialize the TMP006 // TMP006Init(&g_sTMP006Inst, &g_sI2CInst, TMP006_I2C_ADDRESS, TMP006AppCallback, &g_sTMP006Inst); SysCtlDelay(g_SysClock / (100 * 3)); // // Initialize the BMP180. // BMP180Init(&g_sBMP180Inst, &g_sI2CInst, BMP180_I2C_ADDRESS, BMP180AppCallback, &g_sBMP180Inst); SysCtlDelay(g_SysClock / (100 * 3)); IntPrioritySet(INT_I2C7, 0x00); IntPrioritySet(INT_GPIOM, 0x00); IntPrioritySet(INT_TIMER0A, 0x80); IntPrioritySet(INT_TIMER1A, 0x40); IntPrioritySet(INT_GPIOE, 0x80); IntPrioritySet(INT_UART0, 0x80); // // Initialize the ISL29023 Driver. // ISL29023Init(&g_sISL29023Inst, &g_sI2CInst, ISL29023_I2C_ADDRESS, ISL29023AppCallback, &g_sISL29023Inst); SysCtlDelay(g_SysClock / (100 * 3)); // // Configure the ISL29023 to measure ambient light continuously. Set a 8 // sample persistence before the INT pin is asserted. Clears the INT flag. // Persistence setting of 8 is sufficient to ignore camera flashes. // ui8Mask = (ISL29023_CMD_I_OP_MODE_M | ISL29023_CMD_I_INT_PERSIST_M | ISL29023_CMD_I_INT_FLAG_M); ISL29023ReadModifyWrite(&g_sISL29023Inst, ISL29023_O_CMD_I, ~ui8Mask, (ISL29023_CMD_I_OP_MODE_ALS_CONT | ISL29023_CMD_I_INT_PERSIST_8), ISL29023AppCallback, &g_sISL29023Inst); // // Configure the upper threshold to 80% of maximum value // g_sISL29023Inst.pui8Data[1] = 0xCC; g_sISL29023Inst.pui8Data[2] = 0xCC; ISL29023Write(&g_sISL29023Inst, ISL29023_O_INT_HT_LSB, g_sISL29023Inst.pui8Data, 2, ISL29023AppCallback, &g_sISL29023Inst); // // Wait for transaction to complete // SysCtlDelay(g_SysClock / (100 * 3)); // // Configure the lower threshold to 20% of maximum value // g_sISL29023Inst.pui8Data[1] = 0x33; g_sISL29023Inst.pui8Data[2] = 0x33; ISL29023Write(&g_sISL29023Inst, ISL29023_O_INT_LT_LSB, g_sISL29023Inst.pui8Data, 2, ISL29023AppCallback, &g_sISL29023Inst); // // Wait for transaction to complete // SysCtlDelay(g_SysClock / (100 * 3)); // // Write the command to start a humidity measurement. // SHT21Write(&g_sSHT21Inst, SHT21_CMD_MEAS_RH, g_sSHT21Inst.pui8Data, 0, SHT21AppCallback, &g_sSHT21Inst); // // Wait for transaction to complete // SysCtlDelay(g_SysClock / (100 * 3)); // // Initialize the MPU9150 Driver. // MPU9150Init(&g_sMPU9150Inst, &g_sI2CInst, MPU9150_I2C_ADDRESS, MPU9150AppCallback, &g_sMPU9150Inst); SysCtlDelay(g_SysClock / (100 * 3)); // // Write application specifice sensor configuration such as filter settings // and sensor range settings. // g_sMPU9150Inst.pui8Data[0] = MPU9150_CONFIG_DLPF_CFG_94_98; g_sMPU9150Inst.pui8Data[1] = MPU9150_GYRO_CONFIG_FS_SEL_250; g_sMPU9150Inst.pui8Data[2] = (MPU9150_ACCEL_CONFIG_ACCEL_HPF_5HZ | MPU9150_ACCEL_CONFIG_AFS_SEL_2G); MPU9150Write(&g_sMPU9150Inst, MPU9150_O_CONFIG, g_sMPU9150Inst.pui8Data, 3, MPU9150AppCallback, &g_sMPU9150Inst); SysCtlDelay(g_SysClock / (100 * 3)); // // Initialize the DCM system. 50 hz sample rate. // accel weight = .2, gyro weight = .8, mag weight = .2 // CompDCMInit(&g_sCompDCMInst, 1.0f / 50.0f, 0.2f, 0.6f, 0.2f); SysCtlDelay(g_SysClock / (100 * 3)); ui32CompDCMStarted = 0; // // Print the basic outline of our data table. Done once and then kept as we // print only the data. // // CLI_Write("\033[2J\033[H"); // CLI_Write("MPU9150 9-Axis Simple Data Application Example\n\r\n\r"); // CLI_Write("\033[20GX\033[31G|\033[43GY\033[54G|\033[66GZ\n\r\n\r"); // CLI_Write("Accel\033[8G|\033[31G|\033[54G|\n\r\n\r"); // CLI_Write("Gyro\033[8G|\033[31G|\033[54G|\n\r\n\r"); // CLI_Write("Mag\033[8G|\033[31G|\033[54G|\n\r\n\r"); // CLI_Write("\n\033[20GRoll\033[31G|\033[43GPitch\033[54G|\033[66GYaw\n\r\n\r"); // CLI_Write("Eulers\033[8G|\033[31G|\033[54G|\n\r\n\r"); // CLI_Write("\n\033[17GQ1\033[26G|\033[35GQ2\033[44G|\033[53GQ3\033[62G|" // "\033[71GQ4\n\r\n\r"); // CLI_Write("Q\033[8G|\033[26G|\033[44G|\033[62G|\n\r\n\r"); TimerEnable(TIMER1_BASE, TIMER_A); }
//***************************************************************************** // // Main 'C' Language entry point. // //***************************************************************************** int main(void) { float fTemperature, fPressure, fAltitude; int32_t i32IntegerPart; int32_t i32FractionPart; // // Setup the system clock to run at 40 MHz from PLL with crystal reference // ROM_SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN); // // Initialize the UART. // ConfigureUART(); // // Print the welcome message to the terminal. // UARTprintf("\033[2JBMP180 Example\n"); // // Set the color to a white approximation. // g_pui32Colors[RED] = 0x8000; g_pui32Colors[BLUE] = 0x8000; g_pui32Colors[GREEN] = 0x8000; // // Initialize RGB driver. Use a default intensity and blink rate. // RGBInit(0); RGBColorSet(g_pui32Colors); RGBIntensitySet(0.5f); RGBEnable(); // // The I2C3 peripheral must be enabled before use. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C3); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); // // Configure the pin muxing for I2C3 functions on port D0 and D1. // This step is not necessary if your part does not support pin muxing. // ROM_GPIOPinConfigure(GPIO_PD0_I2C3SCL); ROM_GPIOPinConfigure(GPIO_PD1_I2C3SDA); // // Select the I2C function for these pins. This function will also // configure the GPIO pins pins for I2C operation, setting them to // open-drain operation with weak pull-ups. Consult the data sheet // to see which functions are allocated per pin. // GPIOPinTypeI2CSCL(GPIO_PORTD_BASE, GPIO_PIN_0); ROM_GPIOPinTypeI2C(GPIO_PORTD_BASE, GPIO_PIN_1); // // Initialize the GPIO for the LED. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1); ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, 0x00); // // Enable interrupts to the processor. // ROM_IntMasterEnable(); // // Initialize the I2C3 peripheral. // I2CMInit(&g_sI2CInst, I2C3_BASE, INT_I2C3, 0xff, 0xff, ROM_SysCtlClockGet()); // // Initialize the BMP180. // BMP180Init(&g_sBMP180Inst, &g_sI2CInst, BMP180_I2C_ADDRESS, BMP180AppCallback, &g_sBMP180Inst); // // Wait for initialization callback to indicate reset request is complete. // while(g_vui8DataFlag == 0) { // // Wait for I2C Transactions to complete. // } // // Reset the data ready flag // g_vui8DataFlag = 0; // // Enable the system ticks at 10 Hz. // ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / (10 * 3)); ROM_SysTickIntEnable(); ROM_SysTickEnable(); // // After all the init and config we start blink the LED // RGBBlinkRateSet(1.0f); // // Begin the data collection and printing. Loop Forever. // while(1) { // // Read the data from the BMP180 over I2C. This command starts a // temperature measurement. Then polls until temperature is ready. // Then automatically starts a pressure measurement and polls for that // to complete. When both measurement are complete and in the local // buffer then the application callback is called from the I2C // interrupt context. Polling is done on I2C interrupts allowing // processor to continue doing other tasks as needed. // BMP180DataRead(&g_sBMP180Inst, BMP180AppCallback, &g_sBMP180Inst); while(g_vui8DataFlag == 0) { // // Wait for the new data set to be available. // } // // Reset the data ready flag. // g_vui8DataFlag = 0; // // Get a local copy of the latest temperature data in float format. // BMP180DataTemperatureGetFloat(&g_sBMP180Inst, &fTemperature); // // Convert the floats to an integer part and fraction part for easy // print. // i32IntegerPart = (int32_t) fTemperature; i32FractionPart =(int32_t) (fTemperature * 1000.0f); i32FractionPart = i32FractionPart - (i32IntegerPart * 1000); if(i32FractionPart < 0) { i32FractionPart *= -1; } // // Print temperature with three digits of decimal precision. // UARTprintf("Temperature %3d.%03d\t\t", i32IntegerPart, i32FractionPart); // // Get a local copy of the latest air pressure data in float format. // BMP180DataPressureGetFloat(&g_sBMP180Inst, &fPressure); // // Convert the floats to an integer part and fraction part for easy // print. // i32IntegerPart = (int32_t) fPressure; i32FractionPart =(int32_t) (fPressure * 1000.0f); i32FractionPart = i32FractionPart - (i32IntegerPart * 1000); if(i32FractionPart < 0) { i32FractionPart *= -1; } // // Print Pressure with three digits of decimal precision. // UARTprintf("Pressure %3d.%03d\t\t", i32IntegerPart, i32FractionPart); // // Calculate the altitude. // fAltitude = 44330.0f * (1.0f - powf(fPressure / 101325.0f, 1.0f / 5.255f)); // // Convert the floats to an integer part and fraction part for easy // print. // i32IntegerPart = (int32_t) fAltitude; i32FractionPart =(int32_t) (fAltitude * 1000.0f); i32FractionPart = i32FractionPart - (i32IntegerPart * 1000); if(i32FractionPart < 0) { i32FractionPart *= -1; } // // Print altitude with three digits of decimal precision. // UARTprintf("Altitude %3d.%03d", i32IntegerPart, i32FractionPart); // // Print new line. // UARTprintf("\n"); // // Delay to keep printing speed reasonable. About 100 milliseconds. // ROM_SysCtlDelay(ROM_SysCtlClockGet() / (10 * 3)); }//while end }
//***************************************************************************** // // Main 'C' Language entry point. // //***************************************************************************** int main(void) { float fTemperature, fPressure, fAltitude; int32_t i32IntegerPart; int32_t i32FractionPart; tContext sContext; uint32_t ui32SysClock; char pcBuf[15]; // // Setup the system clock to run at 40 Mhz from PLL with crystal reference // ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 40000000); // // Configure the device pins. // PinoutSet(); // // Initialize the display driver. // Kentec320x240x16_SSD2119Init(ui32SysClock); // // Initialize the graphics context. // GrContextInit(&sContext, &g_sKentec320x240x16_SSD2119); // // Draw the application frame. // FrameDraw(&sContext, "bmp180"); // // Flush any cached drawing operations. // GrFlush(&sContext); // // Enable UART0 // MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); // // Initialize the UART for console I/O. // UARTStdioConfig(0, 115200, ui32SysClock); // // Print the welcome message to the terminal. // UARTprintf("\033[2JBMP180 Example\n"); // // The I2C3 peripheral must be enabled before use. // MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C3); // // Configure the pin muxing for I2C3 functions on port G4 and G5. // This step is not necessary if your part does not support pin muxing. // MAP_GPIOPinConfigure(GPIO_PG4_I2C3SCL); MAP_GPIOPinConfigure(GPIO_PG5_I2C3SDA); // // Select the I2C function for these pins. This function will also // configure the GPIO pins pins for I2C operation, setting them to // open-drain operation with weak pull-ups. Consult the data sheet // to see which functions are allocated per pin. // MAP_GPIOPinTypeI2CSCL(GPIO_PORTG_BASE, GPIO_PIN_4); MAP_GPIOPinTypeI2C(GPIO_PORTG_BASE, GPIO_PIN_5); // // Enable interrupts to the processor. // MAP_IntMasterEnable(); // // Initialize I2C3 peripheral. // I2CMInit(&g_sI2CInst, I2C3_BASE, INT_I2C3, 0xff, 0xff, ui32SysClock); // // Initialize the BMP180 // BMP180Init(&g_sBMP180Inst, &g_sI2CInst, BMP180_I2C_ADDRESS, BMP180AppCallback, &g_sBMP180Inst); // // Wait for initialization callback to indicate reset request is complete. // while(g_vui8DataFlag == 0) { // // Wait for I2C Transactions to complete. // } // // Reset the data ready flag // g_vui8DataFlag = 0; // // Enable the system ticks at 10 hz. // MAP_SysTickPeriodSet(ui32SysClock / (10 * 3)); MAP_SysTickIntEnable(); MAP_SysTickEnable(); // // Configure PQ4 to control the blue LED. // MAP_GPIOPinTypeGPIOOutput(GPIO_PORTQ_BASE, GPIO_PIN_4); // // Print temperature, pressure and altitude labels once on the LCD. // GrStringDraw(&sContext, "Temperature", 11, ((GrContextDpyWidthGet(&sContext) / 2) - 96), ((GrContextDpyHeightGet(&sContext) - 32) / 2) - 24, 1); GrStringDraw(&sContext, "Pressure", 8, ((GrContextDpyWidthGet(&sContext) / 2) - 63), (GrContextDpyHeightGet(&sContext) - 32) / 2, 1); GrStringDraw(&sContext, "Altitude", 8, ((GrContextDpyWidthGet(&sContext) / 2) - 59), ((GrContextDpyHeightGet(&sContext) - 32) / 2) + 24, 1); // // Begin the data collection and printing. Loop Forever. // while(1) { // // Read the data from the BMP180 over I2C. This command starts a // temperature measurement. Then polls until temperature is ready. // Then automatically starts a pressure measurement and polls for that // to complete. When both measurement are complete and in the local // buffer then the application callback is called from the I2C // interrupt context. Polling is done on I2C interrupts allowing // processor to continue doing other tasks as needed. // BMP180DataRead(&g_sBMP180Inst, BMP180AppCallback, &g_sBMP180Inst); while(g_vui8DataFlag == 0) { // // Wait for the new data set to be available. // } // // Reset the data ready flag. // g_vui8DataFlag = 0; // // Get a local copy of the latest temperature data in float format. // BMP180DataTemperatureGetFloat(&g_sBMP180Inst, &fTemperature); // // Convert the floats to an integer part and fraction part for easy // print. // i32IntegerPart = (int32_t) fTemperature; i32FractionPart =(int32_t) (fTemperature * 1000.0f); i32FractionPart = i32FractionPart - (i32IntegerPart * 1000); if(i32FractionPart < 0) { i32FractionPart *= -1; } // // Print temperature with three digits of decimal precision to LCD and // terminal. // usnprintf(pcBuf, sizeof(pcBuf), "%03d.%03d ", i32IntegerPart, i32FractionPart); GrStringDraw(&sContext, pcBuf, 8, ((GrContextDpyWidthGet(&sContext) / 2) + 16), ((GrContextDpyHeightGet(&sContext) - 32) / 2) - 24, 1); UARTprintf("Temperature %3d.%03d\t\t", i32IntegerPart, i32FractionPart); // // Get a local copy of the latest air pressure data in float format. // BMP180DataPressureGetFloat(&g_sBMP180Inst, &fPressure); // // Convert the floats to an integer part and fraction part for easy // print. // i32IntegerPart = (int32_t) fPressure; i32FractionPart =(int32_t) (fPressure * 1000.0f); i32FractionPart = i32FractionPart - (i32IntegerPart * 1000); if(i32FractionPart < 0) { i32FractionPart *= -1; } // // Print Pressure with three digits of decimal precision to LCD and // terminal. // usnprintf(pcBuf, sizeof(pcBuf), "%3d.%03d ", i32IntegerPart, i32FractionPart); GrStringDraw(&sContext, pcBuf, -1, ((GrContextDpyWidthGet(&sContext) / 2) + 16), (GrContextDpyHeightGet(&sContext) - 32) / 2, 1); UARTprintf("Pressure %3d.%03d\t\t", i32IntegerPart, i32FractionPart); // // Calculate the altitude. // fAltitude = 44330.0f * (1.0f - powf(fPressure / 101325.0f, 1.0f / 5.255f)); // // Convert the floats to an integer part and fraction part for easy // print. // i32IntegerPart = (int32_t) fAltitude; i32FractionPart =(int32_t) (fAltitude * 1000.0f); i32FractionPart = i32FractionPart - (i32IntegerPart * 1000); if(i32FractionPart < 0) { i32FractionPart *= -1; } // // Print altitude with three digits of decimal precision to LCD and // terminal. // usnprintf(pcBuf, sizeof(pcBuf), "%3d.%03d ", i32IntegerPart, i32FractionPart); GrStringDraw(&sContext, pcBuf, 8, ((GrContextDpyWidthGet(&sContext) / 2) + 16), ((GrContextDpyHeightGet(&sContext) - 32) / 2) + 24, 1); UARTprintf("Altitude %3d.%03d", i32IntegerPart, i32FractionPart); // // Print new line. // UARTprintf("\n"); // // Delay to keep printing speed reasonable. About 100 milliseconds. // MAP_SysCtlDelay(ui32SysClock / (10 * 3)); } }