void doIout() { // enable current reporting if module is so equipped if (hasRGB) return; // feature disabled if we're an rgb controller int16_t adc0, adc1, adc2, adc3; if (!hasI2C) return; memset(amps0Chr,0,sizeof(amps0Chr)); memset(amps1Chr,0,sizeof(amps1Chr)); memset(voltsChr,0,sizeof(voltsChr)); adc0 = ads.readADC_SingleEnded(1) ; // adc channel 1 = switch 0 (switch one) raw0 = adc0; float voltage0 = (adc0 / 32767.0) * 4096.0; float amps0 = (voltage0 - ACSoffset) / mvPerA; // 44.0 = mv per amp from datasheet adc1 = ads.readADC_SingleEnded(0) ; // adc channel 0 = switch 1 (switch two) raw1 = adc1; float voltage1 = (adc1 / 32767.0) * 4096.0; float amps1 = (voltage1 - ACSoffset) / mvPerA; // 44.0 = mv per amp from datasheet adc2 = ads.readADC_SingleEnded(2) ; // adc channel 2 = battery voltage divider raw2 = adc2; float voltage2 = 0.0; if (altAdcvbat) voltage2 = (adc2 + vccOffset) / 1000.0; // funky method for original current switch else voltage2 = (adc2 / 32767.0) * vccDivisor; // proper method, 6.8k / 2.2k voltage divider if (amps0<0.080) amps0=0.0; if (amps1<0.080) amps1=0.0; if (voltage2<0.1) voltage2=0.0; char a0[9] = {}; char a1[9] = {}; char v2[9] = {}; /* dtostrf(amps1, 6, 3, a1); // convert precision decimal 6 digits to string? a1[8] = '\0'; sprintf(amps1Chr, "amps1=%s", a1); // copy strings together dtostrf(amps0, 6, 3, a0); // convert float to precision decimal 6 digits? a0[8] = '\0'; sprintf(amps0Chr, "amps0=%s", a0); // copy strings together dtostrf(voltage2, 6, 3, v2); // convert float to precision decimal 6 digits? v2[8] = '\0'; sprintf(voltsChr, "bat=%s", v2); // copy strings together */ String tmp0 = String("amps0=") + String(amps0,3); tmp0.toCharArray(amps0Chr, tmp0.length()+1); String tmp1 = String("amps1=") + String(amps1,3); tmp1.toCharArray(amps1Chr, tmp1.length()+1); String tmp2 = String("bat=") + String(voltage2,3); tmp2.toCharArray(voltsChr, tmp2.length()+1); }
uint16_t gc_dev_batt_read(void){ uint16_t value = 4000; #ifndef SEN_STUB /* Multiply the result by 2.0 because the ADC is connected to a voltage divider circuit that halves the original battery voltage. Note: the cranberry v3.5.0 schematic is incorrect because the values for R21 and R20 are described with values of 150k and 51k respectively. In reality, R21 and R20 are equal to each other (the values are still unkown as of 2016-10-24). */ value = 2.0*((float)adc.readADC_SingleEnded(2)*188.0)/(1000.0); #endif return value; }