/*********************************************************************** * a wrapper to read temperature data and compose text string from ***********************************************************************/ void read_temperature(char *data) { uint32_t t1 = 0, t2 = 0; get_temperature(0, &t1); // 3E030000 -> 3E.03°C -> 62.(03/256)°C get_temperature(1, &t2); t1 = t1 >> 24; t2 = t2 >> 24; sprintf(data, "CPU:%iC, RSX:%iC", t1, t2); }
// calibrate the barometer. This must be called at least once before // the altitude() or climb_rate() interfaces can be used void AP_Baro::calibrate() { float ground_pressure = 0; float ground_temperature = 0; { uint32_t tstart = hal.scheduler->millis(); while (ground_pressure == 0 || !healthy) { read(); // Get initial data from absolute pressure sensor if (hal.scheduler->millis() - tstart > 500) { hal.scheduler->panic(PSTR("PANIC: AP_Baro::read unsuccessful " "for more than 500ms in AP_Baro::calibrate [1]\r\n")); } ground_pressure = get_pressure(); ground_temperature = get_temperature(); hal.scheduler->delay(20); } } // let the barometer settle for a full second after startup // the MS5611 reads quite a long way off for the first second, // leading to about 1m of error if we don't wait for (uint8_t i = 0; i < 10; i++) { uint32_t tstart = hal.scheduler->millis(); do { read(); if (hal.scheduler->millis() - tstart > 500) { hal.scheduler->panic(PSTR("PANIC: AP_Baro::read unsuccessful " "for more than 500ms in AP_Baro::calibrate [2]\r\n")); } } while (!healthy); ground_pressure = get_pressure(); ground_temperature = get_temperature(); hal.scheduler->delay(100); } // now average over 5 values for the ground pressure and // temperature settings for (uint16_t i = 0; i < 5; i++) { uint32_t tstart = hal.scheduler->millis(); do { read(); if (hal.scheduler->millis() - tstart > 500) { hal.scheduler->panic(PSTR("PANIC: AP_Baro::read unsuccessful " "for more than 500ms in AP_Baro::calibrate [3]\r\n")); } } while (!healthy); ground_pressure = (ground_pressure * 0.8) + (get_pressure() * 0.2); ground_temperature = (ground_temperature * 0.8) + (get_temperature() * 0.2); hal.scheduler->delay(100); } _ground_pressure.set_and_save(ground_pressure); _ground_temperature.set_and_save(ground_temperature / 10.0f); }
double tempcont::wait_setpoint_reached(double delta, size_t timeout) const { // poll temperature every second time_t end_polling=time(NULL)+timeout; double setpoint=get_setpoint(); double temperature=get_temperature(); while (fabs(temperature-setpoint)>delta && (timeout==0 || end_polling>=time(NULL))) { sleep(1); temperature=get_temperature(); } return temperature; }
static void print_info(const struct md *md) { double energy = md->potential_energy; double invariant = md->get_invariant(md); double temperature = get_temperature(md); msg("%30s %16.10lf\n", "POTENTIAL ENERGY", energy); msg("%30s %16.10lf\n", "INVARIANT", invariant); msg("%30s %16.10lf\n", "TEMPERATURE", temperature); if (cfg_get_enum(md->state->cfg, "ensemble") == ENSEMBLE_TYPE_NPT) { double pressure = get_pressure(md) / BAR_TO_AU; msg("%30s %16.10lf\n", "PRESSURE", pressure); } if (cfg_get_bool(md->state->cfg, "enable_pbc")) { double x = md->box.x * BOHR_RADIUS; double y = md->box.y * BOHR_RADIUS; double z = md->box.z * BOHR_RADIUS; msg("%30s %9.3lf %9.3lf %9.3lf\n", "PERIODIC BOX SIZE", x, y, z); } msg("\n\n"); }
int main(void) { int result, done, op; result = SusiDllInit(); if (result == FALSE) { printf("SusiDllInit() failed\n"); return 1; } result = SusiHWMAvailable(); if (result == FALSE) { printf("SusiHWMAvailable() failed\n"); SusiDllUnInit(); return 1; } result = show_platform_info(); done = 0; while (! done) { show_menu(); if (scanf("%i", &op) <= 0) op = -1; switch (op) { case 0: done = 1; continue; case 1: result = get_voltage(); break; case 2: result = get_temperature(); break; case 3: result = get_fan_speed(); break; case 4: result = set_fan_speed(); break; default: printf("\nUnknown choice!\n\n"); continue; } if (result != 0) { printf("Library returns with error.\n"); SusiDllUnInit(); return 1; } } result = SusiDllUnInit(); if (result == FALSE) { printf("SusiDllUnInit() failed\n"); return 1; } return 0; }
void loop() { float temp_celsius; float temp_fahrenheit; get_temperature(&temp_celsius, &temp_fahrenheit); record_sample(temp_celsius, temp_fahrenheit); }
void main(void) { init_pins(); init_oscillator(); SPI1_Initialize(); float temp = 0; // Set all pins RD1-7 to inputs, RD0 (MSB is set to output) //TRISD = 0b11111110; // RC2 is PWM pin TRISCbits.RC2 = 0; configure_adc(); configure_pwm(); int ticks = 0; while (1) { MAX_7221_INIT(); temp = get_temperature(0); set_fan_speed(temp); if(ticks % 125 == 0) { MAX_7221_WRITE_FLOAT(temp, 3); ticks = 0; } ticks++; } }
/*=== external functions =========================================================================*/ int8_t get_sensor_value(sensor_type_t sensor, sensor_result_t *res) { int8_t ret; switch (sensor) { case TEMPERATURE: ret = get_temperature(res); break; #if BOARD==SAMR21_XPLAINED_PRO case IO_SUPPLY: ret = get_io_supply(res); break; case ANALOG_PIN: ret = get_analog_pin(res); break; #endif default: ret = -1; break; } return ret; }
void EPD_GFX::display(boolean clear_first, boolean begin, boolean end) { // Erase old (optionally), display new // Optionally begins and ends the EPD/SPI. // There are delays in thos functions that only need to be pre/post use of the display if(begin) { this->EPD.begin(); this->EPD.setFactor( get_temperature() ); } if(clear_first) { this->EPD.clear(current_segment * this->pixel_height_segment, this->pixel_height_segment); } //NOTE: Although the expectation is that pixel_height_segment is going to be in an uint8_t keep an eye on this... assert( this->pixel_height_segment <= 255); this->EPD.image_sram(this->new_image, current_segment * this->pixel_height_segment, (uint8_t)this->pixel_height_segment); if(end) { this->EPD.end(); } }
static void handle_method_call( G_GNUC_UNUSED GDBusConnection *connection, G_GNUC_UNUSED const gchar *sender, G_GNUC_UNUSED const gchar *object_path, G_GNUC_UNUSED const gchar *interface_name, const gchar *method_name, G_GNUC_UNUSED GVariant *parameters, GDBusMethodInvocation *invocation, G_GNUC_UNUSED gpointer user_data) { if (g_strcmp0(method_name, "GetTemperature") == 0) { GVariant *result = g_variant_new("(d)", get_temperature()); g_dbus_method_invocation_return_value(invocation, result); } else if (g_strcmp0(method_name, "GetCO2") == 0) { GVariant *result = g_variant_new("(q)", get_co2()); g_dbus_method_invocation_return_value(invocation, result); } else { g_dbus_method_invocation_return_error(invocation, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, "Invalid method: '%s'", method_name); } }
static void update_display(thermal *th) { char buffer [60]; int i; int temp; GdkColor color; gchar *separator; temp = get_temperature(th, &i); if (i >= 2) color = th->cl_warning2; else if (i >= 1) color = th->cl_warning1; else color = th->cl_normal; if(temp == -1) lxpanel_draw_label_text(th->panel, th->namew, "NA", TRUE, 1, TRUE); else { snprintf(buffer, sizeof(buffer), "<span color=\"#%06x\"><b>%02d</b></span>", gcolor2rgb24(&color), temp); gtk_label_set_markup (GTK_LABEL(th->namew), buffer) ; } g_string_truncate(th->tip, 0); separator = ""; for (i = 0; i < th->numsensors; i++){ g_string_append_printf(th->tip, "%s%s:\t%2d°C", separator, th->sensor_name[i], th->temperature[i]); separator = "\n"; } gtk_widget_set_tooltip_text(th->namew, th->tip->str); }
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; }
void EPD_GFX::drawBitmapFast(const uint8_t PROGMEM *bitmap, boolean subsampled_by_2) { this->EPD.begin(); this->EPD.setFactor( get_temperature() ); this->EPD.clear(); this->EPD.image( bitmap, 0, this->pixel_height, subsampled_by_2 ); this->EPD.end(); }
// Setting PWM of the fans void TIM2_IRQHandler(void) { if (TIM_GetITStatus(TIM2, TIM_IT_Update) == SET) { TIM_ClearITPendingBit(TIM2, TIM_IT_Update); if(WORK == 1) { temp = get_temperature(1); set_ventillator_PWM(1, 100 * PID_Controller(&setpoint_1, temp, &error_previous_1, &actual_error_1, &P_1, &I_1, &D_1, Fan_1_PWM)); temp = get_temperature(3); set_ventillator_PWM(3, 100 * PID_Controller(&setpoint_3, temp, &error_previous_3, &actual_error_3, &P_3, &I_3, &D_3, Fan_3_PWM)); } else { set_ventillator_PWM(1,0); set_ventillator_PWM(3,0); } } }
static void timer_a0_ovf_irq(enum sys_message msg) { if (timer_a0_ovf >= tfr) { if (timer_a0_ovf > 65535 - SLOW_REFRESH_DELAY) { return; } tfr = timer_a0_ovf + SLOW_REFRESH_DELAY; get_temperature(); } }
void oled_update_temp() { #define OFFSET1 16 short temp = get_temperature(); OLED_ShowNum(OFFSET1, 0, temp/10, 2, 32); OLED_ShowChar(OFFSET1+8*2, 0, '.', 32, 1); OLED_ShowNum(OFFSET1+8*3, 0, temp%10, 1, 32); OLED_Refresh_Gram(); }
//绿灯处理函数 static char *Orther_CGIHandler( int iIndex, int iNumParams, char *pcParam[], char *pcValue[] ) { u8 buf[20]; clear_response_bufer(data_response_buf); //清除缓冲区的内容 get_temperature(data_response_buf); strcat((char *)(data_response_buf),";"); get_time(buf); strcat((char *)(data_response_buf),buf); return RESPONSE_PAGE_SET_CGI_RSP_URL; }
/** * \brief According to EPD size and temperature to get stage_time * \note Refer to COG document Section 5.3 for more details * * \param EPD_type_index The defined EPD size */ static void set_temperature_factor(uint8_t EPD_type_index) { int8_t temperature; temperature = get_temperature(); if (50 >= temperature && temperature > 40){ action__Waveform_param=(struct EPD_WaveformTable_Struct *)&E_Waveform[EPD_type_index][0]; }else if (40 >= temperature && temperature > 10){ action__Waveform_param=(struct EPD_WaveformTable_Struct *)&E_Waveform[EPD_type_index][1]; }else if (10 >= temperature && temperature > 0){ action__Waveform_param=(struct EPD_WaveformTable_Struct *)&E_Waveform[EPD_type_index][2]; }else action__Waveform_param=(struct EPD_WaveformTable_Struct *)&E_Waveform[EPD_type_index][1]; //Default }
void EPD_GFX::clear() { // erase display this->EPD.begin(); this->EPD.setFactor( get_temperature() ); this->EPD.clear(); this->EPD.end(); // clear buffers to white clear_new_image(); }
void set_weather_text_colour() { // Set weather text colour int temp = get_temperature(); if (temp < 10) { text_layer_set_text_color(s_weatherText, WEATHER_TEXT_FORE_COLOR_COLD); } else if (temp > 25) { text_layer_set_text_color(s_weatherText, WEATHER_TEXT_FORE_COLOR_HOT); } else { text_layer_set_text_color(s_weatherText, WEATHER_TEXT_FORE_COLOR_WARM); } }
/* * Open temperature sensor devices and initialize per sensor data structure. * Returns #sensors found. */ static int envd_setup_sensors(void) { int i; tempr_t temp; env_sensor_t *sensorp; char path[FILENAME_MAX]; int sensorcnt = 0; sensor_thresh_t *threshp; for (i = 0; (sensorp = envd_sensors[i]) != NULL; i++) { sensorp->fd = -1; sensorp->shutdown_initiated = B_FALSE; sensorp->warning_tstamp = 0; sensorp->shutdown_tstamp = 0; threshp = sensorp->temp_thresh; sensorp->cur_temp = threshp->target_temp; sensorp->error = 0; (void) strcpy(path, "/devices"); (void) strlcat(path, sensorp->devfs_path, sizeof (path)); sensorp->fd = open(path, O_RDWR); if (sensorp->fd == -1) { envd_log(LOG_WARNING, ENV_SENSOR_OPEN_FAIL, sensorp->name, sensorp->devfs_path, errno, strerror(errno)); sensorp->present = B_FALSE; continue; } sensorp->present = B_TRUE; sensorcnt++; if (monitor_temperature) { /* * Set low_power_off and high_power_off limits */ (void) ioctl(sensorp->fd, MAX1617_SET_LOW_LIMIT, &threshp->low_power_off); (void) ioctl(sensorp->fd, MAX1617_SET_HIGH_LIMIT, &threshp->high_power_off); } /* * Set cur_temp field to the current temperature value */ if (get_temperature(sensorp, &temp) == 0) { sensorp->cur_temp = temp; } } return (sensorcnt); }
void tempcont::maintain_history() { // wait for initialisation of derived class or failure pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS,NULL); // sleep 0.2 seconds, that assures a check every second timespec sleeptime; sleeptime.tv_sec=0; sleeptime.tv_nsec=200*1000*1000; while (1) { // do not maintain history until step is set to a reasonable value if (history_step!=0) { pthread_mutex_lock(&history_lock); time_t now=time(NULL); if (history_step<=difftime(now, history_latest_time)) { double new_temp; try { new_temp=get_temperature(); } catch (tempcont_error e) { pthread_mutex_unlock(&history_lock); fprintf(stderr,"history maintainance thread caught exception: %s, terminating\n",e.what()); device_failed=1; pthread_exit(NULL); } // append the new temperature value pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED,NULL); history_latest_time=now; if (history_used==0) { history_latest_index=0; history_buffer[0]=new_temp; history_used=1; } else { history_latest_index++; if (history_latest_index==history_length) history_latest_index=0; history_buffer[history_latest_index]=new_temp; if (history_used<history_length) history_used++; } pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS,NULL); pthread_mutex_unlock(&history_lock); // continue directly with next check continue; } else { pthread_mutex_unlock(&history_lock); } } nanosleep(&sleeptime,NULL); } return; }
// calibrate the barometer. This must be called at least once before // the altitude() or climb_rate() interfaces can be used void AP_Baro::calibrate(void (*callback)(unsigned long t)) { float ground_pressure = 0; float ground_temperature = 0; while (ground_pressure == 0 || !healthy) { read(); // Get initial data from absolute pressure sensor ground_pressure = get_pressure(); ground_temperature = get_temperature(); callback(20); } // let the barometer settle for a full second after startup // the MS5611 reads quite a long way off for the first second, // leading to about 1m of error if we don't wait for (uint16_t i = 0; i < 10; i++) { do { read(); } while (!healthy); ground_pressure = get_pressure(); ground_temperature = get_temperature(); callback(100); } // now average over 5 values for the ground pressure and // temperature settings for (uint16_t i = 0; i < 5; i++) { do { read(); } while (!healthy); ground_pressure = ground_pressure * 0.8 + get_pressure() * 0.2; ground_temperature = ground_temperature * 0.8 + get_temperature() * 0.2; callback(100); } _ground_pressure.set_and_save(ground_pressure); _ground_temperature.set_and_save(ground_temperature / 10.0f); }
int main(void) { const double c_delta = 1; double last_temperature; double temperature = -300; do { last_temperature = temperature; int status = get_temperature(&temperature); if ( status < 0) { printf("Read temerature failed. error no: %d\n", status); return status; } } while (abs(temperature - last_temperature) > c_delta); printf("Temperature: %.3f\n", temperature); return 0; }
void tempcont::set_history_stepsize(size_t step) { if (history_step==step) return; pthread_mutex_lock((pthread_mutex_t*)&history_lock); history_step=step; if (step==0) { // reinitalise history history_used=0; } else { history_latest_index=0; history_used=1; history_buffer[0]=get_temperature(); history_latest_time=time(NULL); } pthread_mutex_unlock((pthread_mutex_t*)&history_lock); }
static float pcsensor_get_temperature(usb_dev_handle* lvr_winusb, float *tempc) { int ret; switch (device_type(lvr_winusb)) { case 0: ret = get_temperature(lvr_winusb, tempc); break; case 1: control_transfer(lvr_winusb, uTemperatura); ret = interrupt_read_temperatura(lvr_winusb, tempc); break; } if (ret < 0) { return ret; } return 0; }
/* get the temperature in degrees C to be used for calibration purposes */ float AP_Baro::get_external_temperature(const uint8_t instance) const { // if we have a recent external temperature then use it if (_last_external_temperature_ms != 0 && AP_HAL::millis() - _last_external_temperature_ms < 10000) { return _external_temperature; } // if we don't have an external temperature then use the minimum // of the barometer temperature and 35 degrees C. The reason for // not just using the baro temperature is it tends to read high, // often 30 degrees above the actual temperature. That means the // EAS2TAS tends to be off by quite a large margin, as well as // the calculation of altitude difference betweeen two pressures // reporting a high temperature will cause the aircraft to // estimate itself as flying higher then it actually is. return MIN(get_temperature(instance), INTERNAL_TEMPERATURE_CLAMP); }
float pcsensor_get_temperature(usb_dev_handle* lvr_winusb){ float tempc; int ret; switch(device_type(lvr_winusb)){ case 0: ret = get_temperature(lvr_winusb, &tempc); break; case 1: control_transfer(lvr_winusb, uTemperatura ); ret = interrupt_read_temperatura(lvr_winusb, &tempc); break; } if(ret < 0){ return FLT_MIN; } return tempc; }
/* get the temperature in degrees C to be used for calibration purposes */ float AP_Baro::get_calibration_temperature(uint8_t instance) const { // if we have a recent external temperature then use it if (_last_external_temperature_ms != 0 && AP_HAL::millis() - _last_external_temperature_ms < 10000) { return _external_temperature; } // if we don't have an external temperature then use the minimum // of the barometer temperature and 25 degrees C. The reason for // not just using the baro temperature is it tends to read high, // often 30 degrees above the actual temperature. That means the // EAS2TAS tends to be off by quite a large margin float ret = get_temperature(instance); if (ret > 25) { ret = 25; } return ret; }
int main(void) { main_init(); timer_a0_init(); // PGA2311 needs to get the digital power after a delay // otherwise it will lock up timer_a0_delay_ccr4(_1s); pga_enable; spi_init(); spi_fast_mode(); // set chip selects high (deselect all slaves) P1OUT |= 0x54; P2OUT |= 0x1; P4OUT |= 0x84; settings_init(FLASH_ADDR); get_temperature(); #ifdef USE_UART uart1_init(); uart1_iface_init(); #endif #ifdef USE_I2C i2c_slave_init(); i2c_iface_init(); #endif sys_messagebus_register(&timer_a0_ovf_irq, SYS_MSG_TIMER0_IFG); led_off; while (1) { // go into low power mode until an IRQ wakes us up _BIS_SR(LPM0_bits + GIE); __no_operation(); //wake_up(); #ifdef USE_WATCHDOG WDTCTL = (WDTCTL & 0xff) | WDTPW | WDTCNTCL; #endif check_events(); } }