int sens_inquire(SENSOR *sense){ sense->buf[0]=0; read_request(sense->fd,sense->buf); sensor_data(sense->fd,sense->buf); //Check data unsigned int read_status = sense->buf[0]>>6; if (read_status >1) { printf("Status is : %i", read_status); } else{ if (read_status == 1){ printf("Status is : %i so it has been already fetched", read_status); } //parse data sense->hum=get_humidity( sense->buf[0], sense->buf[1]); sense->temp=get_temperature( sense->buf[2], sense->buf[3]); sleep(1); } return 1; }
int main(){ DI();//disable interrupts or hell breaks loose during hardware config construct_system();//bind device addresses init_system();//init devices //clear all interrupts clearall_interrupts(); EI();//enable interrupts: we have UART_recieve //set the lcd contrast //lcd_contrast(0x42); lcd_contrast(0x32); //clear the lcd clearram(); //show boot up message show_bootup(); //clear boot message clearram(); //screen layout screen_layout(); send(1, 225); send(1, 255); send(1, 2); while(1) { get_temperature1(); get_temperature2(); get_light(); get_pressure(); get_humidity(); get_soilwetness(); display(); delay_ms(800); } return 0; }
void fetch (void) { uint8_t i; if (have_ts) { if (t_delay++ > 4) { for (i = 0; i <= t_sensors_count - 1; i++) t_val[i] = (float) read_meas (i) / 10; t_delay = 0; } else { start_meas (); } } for (i = 0; i <= H_SENSORS - 1; i++) h_val[i] = get_humidity (i); if (have_ac) { if (acceleration_data_cell < ACCEL_DATA_SIZE) { latest_accel[X] = acceleration_data[acceleration_data_cell][X] = lis_rxa (); latest_accel[Y] = acceleration_data[acceleration_data_cell][Y] = lis_rya (); latest_accel[Z] = acceleration_data[acceleration_data_cell][Z] = lis_rza (); acceleration_data_cell++; } else { latest_accel[X] = lis_rxa (); latest_accel[Y] = lis_rya (); latest_accel[Z] = lis_rza (); } } }
/** Periodic function */ void meteo_stick_periodic(void) { // Read ADC #ifdef MS_PRESSURE_SLAVE_IDX ads1220_periodic(&meteo_stick.pressure); #endif #ifdef MS_DIFF_PRESSURE_SLAVE_IDX ads1220_periodic(&meteo_stick.diff_pressure); #endif #ifdef MS_TEMPERATURE_SLAVE_IDX ads1220_periodic(&meteo_stick.temperature); #endif // Read PWM #ifdef MS_HUMIDITY_PWM_INPUT meteo_stick.humidity_period = pwm_input_period_tics[MS_HUMIDITY_PWM_INPUT]; meteo_stick.current_humidity = get_humidity(meteo_stick.humidity_period); #endif #if USE_MS_EEPROM if (meteo_stick.eeprom.data_available) { // Extract calibration data if (!mtostk_populate_cal_from_buffer(&meteo_stick.calib, (uint8_t *)(meteo_stick.eeprom.rx_buf + 3))) { // Extraction failed // Force number of calibration to 0 for all sensors int i; for (i = 0; i < MTOSTK_NUM_SENSORS; i++) { meteo_stick.calib.params[i].num_temp = 0; } } } else if (meteo_stick.eeprom.spi_trans.status == SPITransDone) { // Load reading request (reading 1Kb from address 0x0) eeprom25AA256_read(&meteo_stick.eeprom, 0x0, 1024); } #endif // Log data #if LOG_MS if (pprzLogFile != -1) { if (!log_ptu_started) { #if USE_MS_EEPROM if (meteo_stick.eeprom.data_available) { // Print calibration data in the log header sdLogWriteLog(pprzLogFile, "# Calibration data (UUID: %s)\n#\n", meteo_stick.calib.uuid); int i, j, k; for (i = 0; i < MTOSTK_NUM_SENSORS; i++) { sdLogWriteLog(pprzLogFile, "# Sensor: %d, time: %d, num_temp: %d, num_coeff: %d\n", i, meteo_stick.calib.params[i].timestamp, meteo_stick.calib.params[i].num_temp, meteo_stick.calib.params[i].num_coeff); if (meteo_stick.calib.params[i].timestamp == 0) { continue; // No calibration } for (j = 0; j < meteo_stick.calib.params[i].num_temp; j++) { sdLogWriteLog(pprzLogFile, "# Reference temp: %.2f\n", meteo_stick.calib.params[i].temps[j]); sdLogWriteLog(pprzLogFile, "# Coeffs:"); for (k = 0; k < meteo_stick.calib.params[i].num_coeff; k++) { sdLogWriteLog(pprzLogFile, " %.5f", meteo_stick.calib.params[i].coeffs[j][k]); } sdLogWriteLog(pprzLogFile, "\n"); } } sdLogWriteLog(pprzLogFile, "#\n"); sdLogWriteLog(pprzLogFile, "P(adc) T(adc) H(ticks) P_diff(adc) P(hPa) T(C) H(\%) CAS(m/s) FIX TOW(ms) WEEK Lat(1e7rad) Lon(1e7rad) HMSL(mm) GS(cm/s) course(1e7rad) VZ(cm/s)\n"); log_ptu_started = TRUE; } #else sdLogWriteLog(pprzLogFile, "P(adc) T(adc) H(ticks) P_diff(adc) P(hPa) T(C) H(\%) CAS(m/s) FIX TOW(ms) WEEK Lat(1e7rad) Lon(1e7rad) HMSL(mm) GS(cm/s) course(1e7rad) VZ(cm/s)\n"); log_ptu_started = TRUE; #endif } else {