void poll() { uint8_t times; for(times = 0; times < 20;times++) { get_battery(); mos_mdelay(750); } }
/** * Collects data synchronously and return datapoint */ struct tracker_datapoint* collect_data(void) { /** * ---- Analogue ---- */ datapoint.battery = get_battery(); /* Will return zero by default */ datapoint.solar = get_solar(); /* Will return zero by default */ datapoint.radio_die_temperature = telemetry_si_temperature(); datapoint.thermistor_temperature = thermistor_voltage_to_temperature(get_thermistor()); /** * ---- Barometer ---- */ struct barometer* b = get_barometer(); datapoint.main_pressure = b->pressure; datapoint.bmp180_temperature = (float)b->temperature; /** * ---- GPS ---- */ if (gps_update_position_pending() || (gps_get_error_state() != GPS_NOERROR)) { /* Error updating GPS position */ /* TODO: Hit reset on the GPS? */ /* In the meantime just wait for the watchdog */ while (1); } else { /* GPS position updated correctly */ /* GPS Status */ struct ubx_nav_sol sol = gps_get_nav_sol(); datapoint.satillite_count = sol.payload.numSV; /* GPS Position */ if (gps_is_locked()) { struct ubx_nav_posllh pos = gps_get_nav_posllh(); datapoint.latitude = pos.payload.lat; datapoint.longitude = pos.payload.lon; datapoint.altitude = pos.payload.height; } /* GPS Powersave */ gps_set_powersave_auto(); } return &datapoint; }
//============================================= void gradient_generate_data() { uint16_t temperatures[11]; uint8_t battery; frameInfo_t * freeSlot = QfindFreeSlot(OUTQ); if (freeSlot) { //get_adc_temperatures(&(temperatures[1])); temperatures[0] = get_msp_temperature(); temperatures[1] = get_adc_temperatures(15); temperatures[2] = get_adc_temperatures(14); temperatures[3] = get_adc_temperatures(13); temperatures[4] = get_adc_temperatures(12); temperatures[5] = get_adc_temperatures(5); temperatures[6] = get_adc_temperatures(4); temperatures[7] = get_adc_temperatures(3); temperatures[8] = get_adc_temperatures(2); temperatures[9] = get_adc_temperatures(1); temperatures[10] = get_adc_temperatures(0); battery = get_battery(); gradient_build_DATA_payload(&(freeSlot->mrfiPkt), myAddr, seq, temperatures, battery); seq++; } }
int main() { savepoint("=========================="); char buf_bat[200] = {0}; char buf_back[200] = {0}; char buf_net[200] = {0}; char buf_audio[200] = {0}; char buf_date[200] = {0}; char buf_ws[300] = {0}; savepoint("allocation"); get_workspace(buf_ws); savepoint("workspace"); get_battery(buf_bat); savepoint("battery"); get_audio(buf_audio); savepoint("audio"); get_date(buf_date); savepoint("date"); if (get_network(buf_net) == 1) { get_backlight(buf_back, COLOR_BG_NET); savepoint("backlight"); printf("%%{l}%s %%{r}%s %s %s %s %s%%{F%s}%%{B%s}\n", buf_ws, buf_audio, buf_net, buf_back, buf_bat, buf_date, COLOR_BG, COLOR_BG); } else { get_backlight(buf_back, COLOR_BG_AUDIO); savepoint("backlight"); printf("%%{F%s}%%{B%s}%%{l}%s%%{F%s}%%{B%s} %%{r}%s %s %s %s%%{F%s}%%{B%s}\n",COLOR_BG, COLOR_BG, buf_ws, COLOR_BG, COLOR_BG, buf_audio, buf_back, buf_bat, buf_date, COLOR_BG, COLOR_BG); } savepoint("print"); savepoint("=========================="); return 0; }
int main(void) { char *status; char *datetime; char *battery_status; int bat0; char hostname[16]; //hostname[15] = '\0'; gethostname(hostname, 15); int is_laptop; is_laptop = strcmp(hostname, "miku"); if (!(dpy = XOpenDisplay(NULL))) { fprintf(stderr, "Cannot open display.\n"); return 1; } if((status = malloc(200)) == NULL) exit(1); for(;;sleep(10)) { datetime = get_datetime(); if(!is_laptop) { battery_status = get_battery_status(); bat0 = get_battery(); snprintf(status, 200, "%s%d%% | %s", battery_status, bat0, datetime); } else { snprintf(status, 200, "%s", datetime); } setstatus(status); } free(datetime); free(status); XCloseDisplay(dpy); return 0; }
int Device::create_readings_raw(char *buf) { int flags = 0; int n_readings = 0; if(uid == -1) { buf[0] = 0xFF; buf[1] = 0xFF; buf[2] = 0xFF; buf[3] = 0xFF; } else { buf[0] = uid; buf[1] = uid>>8; buf[2] = uid>>16; buf[3] = uid>>24; } if(get_battery() < LOW_BATTERY_LEVEL) flags |= LOW_BATTERY_FLAG; if(state == SHUTDOWN) flags |= SHUTDOWN_FLAG; n_readings = num_readings(); if(n_readings > 9) n_readings = 9; buf[4] = flags; buf[5] = n_readings; std::map<time_t,int>::iterator it = readings.begin(); for(int i = 0; i < n_readings; i++) { for(int n = 0; n < 4; n++) { buf[6+(i*(4+4))+n] = it->first >> n*8; buf[6+(i*(4+4))+4+n] = it->second >> n*8; } it++; } return n_readings; }
static float get_mybatt(void){ return (float) ((get_battery()*2.500*2)/4096);}