/* * to sort a band, we have */ void band::sortBand (void) { int MadeChange = true; int i; /* * just a simple bubblesort, since the amount of elements * is limited, and the function is only called on set up */ while (MadeChange) { MadeChange = false; for (i = 0; i < amount - 1; i ++) if (getFrequency (i) > getFrequency (i + 1)) { int f1, v1; f1 = getFrequency (i + 1); v1 = getVoltage (i + 1); setFrequency (i + 1, getFrequency (i)); setVoltage (i + 1, getVoltage (i)); setFrequency (i, f1); setVoltage (i, v1); MadeChange = true; } } setLowerBound (getFrequency (0)); setUpperBound (getFrequency (amount - 1)); }
void controlCharging(void) { float BAT1 = getVoltage(BAT1_ID); float BAT2 = getVoltage(BAT2_ID); float BAT3 = getVoltage(BAT3_ID); checkBatteryCharging(BAT1, PANEL1_ID); checkBatteryCharging(BAT2, PANEL2_ID); checkBatteryCharging(BAT3, DCDC1_ID); }
uint8_t ProgramData::printVoltageString() const { if(battery.type == Unknown) { lcdPrintVoltage(getVoltage(), 7); return 7; } else { uint8_t r = 5+2+1; lcdPrintVoltage(getVoltage(), 5); lcdPrintChar('/'); lcdPrintUInt(battery.cells); lcdPrintChar('C'); return r; } }
void ISR_BATTERY_CHECK(void) { static byte bLowBatteryCount; GB_ADC0_VOLTAGE = getVoltage(); //if ( GB_ADC0_VOLTAGE <= VOLTAGE_LEVEL_0 ) { if ( GB_ADC0_VOLTAGE <= VOLTAGE_LEVEL_1 && GB_ADC0_VOLTAGE > 130) { if (bLowBatteryCount < LOW_BATTERY_COUNT) bLowBatteryCount++; } else { bLowBatteryCount = 0; } if ( bLowBatteryCount == LOW_BATTERY_COUNT ) { setBuzzerPlayLength(SOUND_LOW_VOLTAGE_LENGTH); setBuzzerData(SOUND_LOW_VOLTAGE_DATA); if(!getBuzzerState()) { PlayBuzzer(); } } }
int IrSensor::getDistance() { try { voltage_ = getVoltage(); distanceMm_ = gp2Convert(type_, voltage_); logger().debug() << "getDistance type=" << type_ << " " << adcPin_ << " dist=" << distanceMm_ << " v=" << voltage_ << logs::end; } catch (logs::Exception * e) { logger().error() << "Exception IrSensor getDistance: " << e->what() << logs::end; } if (distanceMm_ >= 9999.0) { distanceMm_ = 9999.0; } return (int) distanceMm_; }
int QBatteryInfoPrivate::voltage(int battery) { if (!watchVoltage) return getVoltage(battery); return voltages.value(battery); }
/******************* Eens hij aan het algoritme begonnen is, gaat hij het blijven volhouden tot hij klaar is met laden tenzij de state aangepast wordt. *******************/ int charge_NiMH(int socLoad){ int V_bat; int sleepTime,sleepTime_fin; init_V_max(); setCurrentCharger(C); // Slaaptijd tussen opeenvolgende metingen, in milliseconden sleepTime = 100; sleepTime_fin =5000; while (getLoadFactor()>0) { setLEDS(getLoadFactor()); if (isAtChargeLimit(socLoad)) return 2; V_bat=getVoltage(); if(V_max<V_bat){ V_max=V_bat; } if(V_bat<V_max*0.9975){ //hoe kan je controleren of dit 5 sec lang zo blijft (andere tijdsduur is ook goed, maar men stelt 5 sec voor) usleep(sleepTime_fin*1000); if(V_bat<V_max*0.9975){ return 1; } } usleep(sleepTime*1000); } return 0; }
void securityCheck(void) { for (int i=0; i < countVoltagePins; i++) { if (getVoltage(i) > BAT_ALARM_HIGH) { die(); } } }
double NoiseLevelSensor::averageVoltage() { double sum = 0; for (int i = 0; i < _bufferSize; i++) { sum = sum + getVoltage(_buffer[i]); } double avg = sum / ((double) _bufferSize); return avg; }
double NoiseLevelSensor::stdevVoltage() { double m = averageVoltage(); double sum = 0; for (int i = 0; i < _bufferSize; i++) { sum = sum + pow(getVoltage(_buffer[i]) - m, 2); } return sqrt( (1/((double) _bufferSize)) * sum ); }
void BatteryFioVThree::getVoltage(uint8_t* voltage) { double v = getVoltage(); //just get the whole number voltage[0] = (uint8_t)floor(v); //just get the decimal part, shift it by 2 places, then round to the nearest int voltage[1] = round((v - voltage[0]) * 100); }
void testTask(void *pvParameters) { for (;;) { Serial_print("Voltage: "); Serial_printInteger(getVoltage(ADC_readValue(0)), 10); Serial_print("V\n"); vTaskDelay(1000); } vTaskDelete(NULL); }
float Photoresistor::read(Photoresistor::Unit unit) { switch (unit) { case Photoresistor::VOLT: return getVoltage(); break; case Photoresistor::LUX: return getLightLevel(); break; } }
uint16_t bq34z100::CalibrateVoltageDivider(uint16_t currentVoltage) { if(currentVoltage<5000) return 0; //So do this we set the voltage divider to 1.5 Times the current pack voltage (to start with) float setVoltage = ((float)readVDivider()); //chg104Table((uint16_t)setVoltage);//set voltage divider float readVoltage = (float)getVoltage(); float newSetting = (currentVoltage/readVoltage)*setVoltage; chg104Table((uint16_t)newSetting,0,0);//set new divider ratio return (uint16_t)newSetting; }
boolean BatteryFioVThree::update() { boolean rv = false; double voltage = getVoltage(); //logic here is that the 3.7V lipo battery should not be able to reach over CHARGING_THRESHOLD volts //so if that is the case we're going to assume we are not battery powered _chargeState = (voltage > CHARGING_THRESHOLD ? 1 : 0); //logic here is that if the 3.7V lipo battery goes under LOW_BATTERY_THRESHOLD volts //then we're going to alert _lowBatteryAlert = (voltage < LOW_BATTERY_THRESHOLD ? true : false); return rv; }
uint16_t ProgramData::getMaxIc() const { uint32_t i; uint16_t v; v = getVoltage(VCharge); i = MAX_CHARGE_P; i *= ANALOG_VOLT(1); i /= v; if(i > MAX_CHARGE_I) i = MAX_CHARGE_I; return i; }
double Adc::getSampledVoltage(byte channel, uint8_t numSamples) { double adcVoltage = 0; for (int i = 0; i < numSamples; i++) { adcVoltage += getVoltage(channel); } adcVoltage /= numSamples; return adcVoltage; }
char* slave_read( unsigned ch ) { double val = 50.0 + (getVoltage(ADC_3, 5.0) - 2.5) * 100.0; static char str[20]; str[0] = 't'; str[1] = 'e'; str[2] = 'm'; str[3] = 'p'; str[4] = ':'; dtostrf( val, 5, 3, &str[5] ); str[10] = ':'; str[11] = 'F'; str[12] = '\n'; str[13] = 0; return str; };
void displayVoltages(){ char buffer[BUFSIZE]; lcd.setCursor(0, 1); for (int i=0; i < countVoltagePins; i++) { ftoa(buffer, getVoltage(i), 1); lcd.print(buffer); lcd.print(" "); } /* Serial debug */ Serial.print(millis()); Serial.print(","); for (int i=0; i < countVoltagePins; i++) { Serial.print(getVoltage(i)); Serial.print(","); } Serial.println(); }
float AccelerometerADXL335::getAcceleration(int _pin, int _n_readings, float _bias) { //local variables float volts, accel; //get raw voltage at incicated pin volts = getVoltage(_pin, _n_readings); //convert to acceleration [m/s^2] accel = voltage2acceleration(volts, _bias); //return return accel; }
static void showHipInfo(void) { if (!CONFIGB(isHip9011Enabled)) { scheduleMsg(logger, "hip9011 driver not active"); return; } printSpiState(logger, boardConfiguration); scheduleMsg(logger, "enabled=%s state=%s bore=%.2fmm freq=%.2fkHz PaSDO=%d", boolToString(CONFIGB(isHip9011Enabled)), getHip_state_e(instance.state), engineConfiguration->cylinderBore, getHIP9011Band(PASS_HIP_PARAMS), engineConfiguration->hip9011PrescalerAndSDO); char *outputName = getPinNameByAdcChannel("hip", engineConfiguration->hipOutputChannel, hipPinNameBuffer); scheduleMsg(logger, "band_index=%d gain %.2f/index=%d output=%s", instance.currentBandIndex, engineConfiguration->hip9011Gain, instance.currentGainIndex, outputName); scheduleMsg(logger, "integrator index=%d knockVThreshold=%.2f knockCount=%d maxKnockSubDeg=%.2f", instance.currentIntergratorIndex, engineConfiguration->knockVThreshold, engine->knockCount, engineConfiguration->maxKnockSubDeg); const char * msg = instance.invalidHip9011ResponsesCount > 0 ? "NOT GOOD" : "ok"; scheduleMsg(logger, "spi=%s IntHold@%s/%d response count=%d incorrect response=%d %s", getSpi_device_e(engineConfiguration->hip9011SpiDevice), hwPortname(CONFIGB(hip9011IntHoldPin)), CONFIGB(hip9011IntHoldPinMode), instance.correctResponsesCount, instance.invalidHip9011ResponsesCount, msg); scheduleMsg(logger, "CS@%s updateCount=%d", hwPortname(CONFIGB(hip9011CsPin)), instance.settingUpdateCount); #if EFI_PROD_CODE scheduleMsg(logger, "hip %.2fv/last=%.2f@%s/max=%.2f adv=%d", engine->knockVolts, getVoltage("hipinfo", engineConfiguration->hipOutputChannel), getPinNameByAdcChannel("hip", engineConfiguration->hipOutputChannel, pinNameBuffer), hipValueMax, CONFIGB(useTpicAdvancedMode)); scheduleMsg(logger, "mosi=%s", hwPortname(getMosiPin(engineConfiguration->hip9011SpiDevice))); scheduleMsg(logger, "miso=%s", hwPortname(getMisoPin(engineConfiguration->hip9011SpiDevice))); scheduleMsg(logger, "sck=%s", hwPortname(getSckPin(engineConfiguration->hip9011SpiDevice))); #endif /* EFI_PROD_CODE */ scheduleMsg(logger, "start %.2f end %.2f", engineConfiguration->knockDetectionWindowStart, engineConfiguration->knockDetectionWindowEnd); hipValueMax = 0; engine->printKnockState(); }
char* slave_read( unsigned ch ) { double val = getVoltage(ADC_3, 5.0); static char str[20]; int i = 0; str[i++] = 'a'; str[i++] = 'd'; str[i++] = 'c'; str[i++] = ':'; dtostrf( val, 5, 3, &str[i] ); i += 5; str[i++] = ':'; str[i++] = 'r'; str[i++] = 'a'; str[i++] = 'w'; str[i++] = '\n'; str[i++] = 0; return str; };
static float getUa() { #if ! EFI_UNIT_TEST if (CONFIG(cj125ua) != EFI_ADC_NONE) { #if EFI_PROD_CODE if (engineConfiguration->cj125isUaDivided) { return getVoltageDivided("cj125ua", CONFIG(cj125ua)); } else { return getVoltage("cj125ua", CONFIG(cj125ua)); } #endif /* EFI_PROD_CODE */ } return 0.0f; #else /* EFI_UNIT_TEST */ return 0; #endif /* EFI_UNIT_TEST */ }
/** * @brief Event method that is fired when it's time to calculate the output of the input * * Event method that fires when the button is clicked. This calculates the result of the electrolib functionality. * @return void **/ static void calculateAndPresentOutput(){ int RESISTANCEOUTPUTLABELROW = 6; int VOLTAGEOUTPUTLABELROW = 7; int E12OUTPUTLABELROW = 8; float* replaceResistanceValues = calloc(3,sizeof(float)); float totalresistance = calc_resistance(getNumberOfComponents(), getConnectionType(), getResistanceItems()); float totalpower = calc_power_r(getVoltage(), totalresistance); int numberOfResistors = e_resistance(totalresistance, replaceResistanceValues); char formatedMessage[100]; sprintf(formatedMessage, "Ersättningsresistance: %.1f ohm", totalresistance); addOutputLabel(_mainGrid, formatedMessage, 1, RESISTANCEOUTPUTLABELROW, 2); sprintf(formatedMessage, "Effekt: %.2f W", totalpower); addOutputLabel(_mainGrid, formatedMessage, 1, VOLTAGEOUTPUTLABELROW, 2); sprintf(formatedMessage, "Ersättningsresistans i E12-serien koppliade i serie: %.0f, %.0f, %.0f", *replaceResistanceValues, *(replaceResistanceValues+1), *(replaceResistanceValues+2)); addOutputLabel(_mainGrid, formatedMessage, 1, E12OUTPUTLABELROW, 2); }
static float getUr() { #if ! EFI_UNIT_TEST if (CONFIG(cj125ur) != EFI_ADC_NONE) { #if EFI_PROD_CODE #ifdef EFI_CJ125_DIRECTLY_CONNECTED_UR // in case of directly connected Ur signal from CJ125 to the ADC pin of MCU return getVoltage("cj125ur", CONFIG(cj125ur)); #else // if a standard voltage division scheme with OpAmp is used return getVoltageDivided("cj125ur", CONFIG(cj125ur)); #endif /* EFI_CJ125_DIRECTLY_CONNECTED_UR */ #endif /* EFI_PROD_CODE */ } return 0.0f; #else /* EFI_UNIT_TEST */ return 0; #endif /* EFI_UNIT_TEST */ }
void statusTask(void) { static time_t last = 100; // Don't begin immediately static uint32_t lastDuration = 0; if (((getSystemTime() - last) >= STATUSDELAY) && (!(state & STATE_OUTPUT))) { last = getSystemTime(); printf("p%.2f %.2f %.2f\n", orientation.vPitch, orientation.vRoll, orientation.vYaw); printf("q%li %li\n", sumFlightTask / countFlightTask, lastDuration); printf("r%.2f %.2f\n", pidStates[0].intMin, pidStates[0].intMax); printf("s%.2f %.2f\n", pidStates[0].outMin, pidStates[0].outMax); printf("t%.3f %.3f %.3f\n", pidStates[0].kp, pidStates[0].ki, pidStates[0].kd); printf("u%.2f %.2f\n", pidOutput[PITCH], pidOutput[ROLL]); printf("v%i %i %i %i\n", motorSpeed[0], motorSpeed[1], motorSpeed[2], motorSpeed[3]); printf("w%.2f\n", orientation.pitch); printf("x%.2f\n", orientation.roll); printf("y%.2f\n", orientation.yaw); printf("z%.2f\n", getVoltage()); lastDuration = getSystemTime() - last; } }
void eapsUta12Port::updateValues() { checkInTimeCount(); if( _emitVoltage || _emitPower || _emitResistance ) { getVoltage(); } if( _emitCurrent || _emitPower || _emitResistance ) { getCurrent(); } updateNumInTimeValues(); if( _setValueType != setValueType::setTypeNone && _autoAdjust ) { adjustValues(); } }
static void showHipInfo(void) { if (!boardConfiguration->isHip9011Enabled) { scheduleMsg(logger, "hip9011 driver not active"); return; } printSpiState(logger, boardConfiguration); scheduleMsg(logger, "enabled=%s state=%d bore=%fmm freq=%fkHz PaSDO=%d", boolToString(boardConfiguration->isHip9011Enabled), state, engineConfiguration->cylinderBore, getBand(), engineConfiguration->hip9011PrescalerAndSDO); scheduleMsg(logger, "band_index=%d gain %f/index=%d", currentBandIndex, boardConfiguration->hip9011Gain, currentGainIndex); scheduleMsg(logger, "integrator index=%d knockVThreshold=%f knockCount=%d maxKnockSubDeg=%f", currentIntergratorIndex, engineConfiguration->knockVThreshold, engine->knockCount, engineConfiguration->maxKnockSubDeg); scheduleMsg(logger, "spi=%s IntHold@%s response count=%d incorrect response=%d", getSpi_device_e(hipSpiDevice), hwPortname(boardConfiguration->hip9011IntHoldPin), correctResponse, invalidResponse); scheduleMsg(logger, "CS@%s updateCount=%d", hwPortname(boardConfiguration->hip9011CsPin), settingUpdateCount); scheduleMsg(logger, "hip %fv/last=%f@%s/max=%f spiCount=%d adv=%d", engine->knockVolts, getVoltage("hipinfo", engineConfiguration->hipOutputChannel), getPinNameByAdcChannel("hip", engineConfiguration->hipOutputChannel, pinNameBuffer), hipValueMax, spiCount, boardConfiguration->useTpicAdvancedMode); scheduleMsg(logger, "mosi=%s", hwPortname(getMosiPin(hipSpiDevice))); scheduleMsg(logger, "miso=%s", hwPortname(getMisoPin(hipSpiDevice))); scheduleMsg(logger, "sck=%s", hwPortname(getSckPin(hipSpiDevice))); scheduleMsg(logger, "start %f end %f", engineConfiguration->knockDetectionWindowStart, engineConfiguration->knockDetectionWindowEnd); hipValueMax = 0; engine->printKnockState(); }
static void printAnalogInfo(void) { scheduleMsg(&logger, "analogInputDividerCoefficient: %f", engineConfiguration->analogInputDividerCoefficient); printAnalogChannelInfo("hip9011", engineConfiguration->hipOutputChannel); printAnalogChannelInfo("fuel gauge", engineConfiguration->fuelLevelSensor); printAnalogChannelInfo("TPS", engineConfiguration->tpsAdcChannel); printAnalogChannelInfo("pPS", engineConfiguration->pedalPositionChannel); if (engineConfiguration->clt.adcChannel != EFI_ADC_NONE) { printAnalogChannelInfo("CLT", engineConfiguration->clt.adcChannel); } if (engineConfiguration->iat.adcChannel != EFI_ADC_NONE) { printAnalogChannelInfo("IAT", engineConfiguration->iat.adcChannel); } if (hasMafSensor()) { printAnalogChannelInfo("MAF", engineConfiguration->mafAdcChannel); } for (int i = 0; i < FSIO_ADC_COUNT ; i++) { adc_channel_e ch = engineConfiguration->fsioAdc[i]; if (ch != EFI_ADC_NONE) { printAnalogChannelInfo("fsio", ch); } } printAnalogChannelInfo("AFR", engineConfiguration->afr.hwChannel); if (hasMapSensor(PASS_ENGINE_PARAMETER_F)) { printAnalogChannelInfo("MAP", engineConfiguration->map.sensor.hwChannel); } if (hasBaroSensor(PASS_ENGINE_PARAMETER_F)) { printAnalogChannelInfo("BARO", engineConfiguration->baroSensor.hwChannel); } if (engineConfiguration->externalKnockSenseAdc != EFI_ADC_NONE) { printAnalogChannelInfo("extKno", engineConfiguration->externalKnockSenseAdc); } printAnalogChannelInfo("A/C sw", engineConfiguration->acSwitchAdc); printAnalogChannelInfo("HIP9011", engineConfiguration->hipOutputChannel); printAnalogChannelInfoExt("Vbatt", engineConfiguration->vbattAdcChannel, getVoltage("vbatt", engineConfiguration->vbattAdcChannel), engineConfiguration->vbattDividerCoeff); }
// Loop the execute temperature reads and waving actions void loop() { /* * Turn lights on, read temperature, and possibly wave if it's too hot! */ digitalWrite(led2, HIGH); // Turn on the sanity LED float temperature = getVoltage(tempPin); // Read in the current temperature in voltage form temperature = (temperature - .33) * 100; // Convert the temperature from voltage to degrees Celsius // Remove the 330mV offset and convert String table = "TemperatureData"; // Gets the appropriate Azure held table the store the temperature data char buffer[100]; // Create the buffer string snprintf(buffer, sizeof(buffer), "{\"Temperature\":\"%d\"}", &temperature); // Load the current temperature data into the buffer string ams.create(table, buffer); // Add the data to the data to the Azure table // Determine if it's hot enough for waveBot to tell you to cool down through a wave if (temperature >= 21.1) { // 21.1 degrees Celsius it 70 degrees Fahrenheit motorSpeed = 210; // Set the arm motors speed analogWrite(motorPin, motorSpeed); // Turn on the motor at the decided speed digitalWrite(ledEye1, HIGH); // Turn ON the LED pins digitalWrite(ledEye2, HIGH); // Turn ON the LED pins } delay(2500); // Wait for 2500mS = 2.5 second /* * Turn off the lights and motor */ motorSpeed = 0; // Set the motor speed to off analogWrite(motorPin, motorSpeed); // Turn the motor off digitalWrite(ledEye1, LOW); // Turn off the 1st eye LED digitalWrite(ledEye2, LOW); // Turn off the 2nd eye LED digitalWrite(led2, LOW); // Turn off the sanity LED delay(2500); // Wait for 2.5 second in off mode }