int main(){ char *i2c_device = "/dev/i2c-1"; int address = 0x77; void *bmp = bmp180_init(address, i2c_device); bmp180_eprom_t eprom; bmp180_dump_eprom(bmp, &eprom); bmp180_set_oss(bmp, 1); if(bmp != NULL){ float t = bmp180_temperature(bmp); long p = bmp180_pressure(bmp); float alt = bmp180_altitude(bmp); printf("t = %f, p = %lu, a= %f\n", t, p, alt); bmp180_close(bmp); } return 0; }
void ICACHE_FLASH_ATTR sensors_init(){ NODE_DBG("sensors_init"); //init data os_memset(&global_sensor_data,0,sizeof(sensor_data)); //init sensors dht22_init(); bmp180_init(); //Start os task system_os_task(sensor_read_task, SENSOR_TASK_PRIORITY ,sensor_read_task_queue, SENSOR_TASK_QUEUE_LEN); system_os_post(SENSOR_TASK_PRIORITY, SENSOR_TASK_SIG, NULL ); //arm sensor read timer os_memset(&sensor_read_timer,0,sizeof(os_timer_t)); os_timer_disarm(&sensor_read_timer); os_timer_setfn(&sensor_read_timer, (os_timer_func_t *)sensor_read_timer_cb, NULL); os_timer_arm(&sensor_read_timer, 2000, 1); }
void user_init(void) { // Setup HW user_setup(); // Just some infomations printf("\n"); printf("SDK version : %s\n", sdk_system_get_sdk_version()); printf("GIT version : %s\n", GITSHORTREV); // Use our user inform implementation bmp180_informUser = bmp180_i2c_informUser; // Init BMP180 Interface bmp180_init(SCL_PIN, SDA_PIN); // Create Main Communication Queue mainqueue = xQueueCreate(10, sizeof(my_event_t)); // Create user interface task xTaskCreate(bmp180_task, (const char * const)"bmp180_task", 256, &mainqueue, 2, NULL); // Create Timer (Trigger a measurement every second) timerHandle = xTimerCreate((const char * const)"BMP180 Trigger", 1000/portTICK_RATE_MS, pdTRUE, NULL, bmp180_i2c_timer_cb); if (timerHandle != NULL) { if (xTimerStart(timerHandle, 0) != pdPASS) { printf("%s: Unable to start Timer ...\n", __FUNCTION__); } } else { printf("%s: Unable to create Timer ...\n", __FUNCTION__); } }
/*lint -save -e970 Disable MISRA rule (6.3) checking. */ int main(void) /*lint -restore Enable MISRA rule (6.3) checking. */ { /* Write your local variable definition here */ uint8_t i ; //uint8_t send_buf[50] ; /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/ PE_low_level_init(); /*** End of Processor Expert internal initialization. ***/ GPIO1_ClearFieldBits(GPIO1_Ptr, LAMP_CTR, 1); //turn off the lamp modbus_init(); Ram_Init(); read_from_flash(); task_init(); bmp180_init(); opa_init(); Aq_Init(); /* Write your code here */ /* For example: */ for(;;) { // sprintf((char*)send_buf,"#C%05u P%07u TP%04d TH%04d H%04u AQ%04u\n\r", modbus.Co2, modbus.PP, modbus.PT, modbus.HT, modbus.HH, modbus.Aq); // AS1_SendBlock(AS1_ptr, send_buf, strlen((char*)send_buf)) ; // Delay(6); if(heartbeat == TRUE) //tick = 1ms { heartbeat = FALSE; if(serial_receive_timeout_count > 0) { serial_receive_timeout_count--; if(serial_receive_timeout_count == 0) { revce_count = 0; } } if(serial_response_delay > 0) serial_response_delay--; if((dealwithTag == TRUE) && (serial_response_delay == 0)) { dealwithTag = FALSE; dealwithData(); } heartbeat_counter++; if(heartbeat_counter >= OS_TICK) // 1 * 10 = 10ms { heartbeat_counter = 0; task_manage(); } } Co2_Detect(); // // AS2_SendBlock(AS2_ptr, "start\n\r", sizeof("start\n\r")) ; // print_status = AD1_CreateSampleGroup(AdDataPTR, &ADC_CO2_Sample, 1) ; // Delay(300); // // sprintf((void*)str, "P = %u\n\r", (uint16_t)print_status); // AS1_SendBlock(AS1_ptr, str, sizeof(str)) ; // Delay(300); // if(enter_adc) // { // enter_adc = 0 ; // AS2_SendBlock(AS2_ptr, "enteradc\n\r", sizeof("enteradc\n\r")) ; // } // Delay(300); // switch(print_status) // { // case ERR_PARAM_SAMPLE_COUNT: // AS2_SendBlock(AS2_ptr, "Para\n\r", sizeof("Para\n\r")) ; // break; // case ERR_BUSY: // AS2_SendBlock(AS2_ptr, "BSY\n\r", sizeof("BSY\n\r")) ; // break; // case ERR_OK: // AS2_SendBlock(AS2_ptr, "OK\n\r", sizeof("OK\n\r")) ; // break ; // case ERR_PARAM_INDEX: // AS2_SendBlock(AS2_ptr, "index\n\r", sizeof("index\n\r")) ; // break ; // } // AD1_CreateSampleGroup(AdDataPTR, (LDD_ADC_TSample *)&ADC_PM25_Sample, 1U); // AD1_StartSingleMeasurement(AdDataPTR); // while(AD1_GetMeasurementCompleteStatus(AdDataPTR) != TRUE); // AD1_GetMeasuredValues(AdDataPTR, (LDD_TData *)&PM25_AD) ; // sprintf((void*)str, "P%u\n\r", (uint16_t)PM25_AD); // AS1_SendBlock(AS1_ptr, str, strlen((const char*)str)) ; // Delay(3000) ; } /*** Don't write any code pass this line, or it will be deleted during code generation. ***/ /*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/ #ifdef PEX_RTOS_START PEX_RTOS_START(); /* Startup of the selected RTOS. Macro is defined by the RTOS component. */ #endif /*** End of RTOS startup code. ***/ /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/ for(;;){} /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/ } /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/