some refactoring,

minor code changes
added a small class for SNESController reading
This commit is contained in:
2021-01-03 16:21:20 +01:00
parent ac74587ee7
commit 3babe3f1ef
8 changed files with 188 additions and 22 deletions

View File

@@ -19,7 +19,7 @@ public:
struct Voltages {
int vShunt; // in uV * 10(!!!)
int16_t vShunt; // in uV * 10(!!!)
int16_t vBus; // in mV
int getMilliAmps(int shunt_milliOhm) const {
@@ -68,24 +68,24 @@ public:
const uint8_t pg = (cfg & 0b01100000000000) >> 11;
const uint8_t brng = (cfg & 0b10000000000000) >> 13;
printf("INA219\n");
printf("- Mode: %d", mode);
printf("- SADC: %d", sadc);
printf("- BADC: %d", badc);
printf("PG (shunt divider) %d", (1<<pg));
if (brng) {printf("- bus voltage range [0:16]");}
else {printf("- bus voltage range [0:32]");}
printf("- Mode: %d\n", mode);
printf("- SADC: %d\n", sadc);
printf("- BADC: %d\n", badc);
printf("PG (shunt divider) %d\n", (1<<pg));
if (brng) {printf("- bus voltage range [0:16]\n");}
else {printf("- bus voltage range [0:32]\n");}
}
private:
/** convert to bytes into a mV reading */
int16_t getBusVoltage(const uint8_t* buf) {
return (getU16(buf) >> 3) * 4; // lower 3 bits are status indicators -> remove, the LSB equals 4 mV -> * 4
return (int16_t)((getU16(buf) >> 3) * 4); // lower 3 bits are status indicators -> remove, the LSB equals 4 mV -> * 4
}
/** convert to bytes into a uV reading */
int getShuntVoltage(const uint8_t* buf) {
return ((int)((int16_t)getU16(buf))); // NOTE: LSB = 10 uV
int16_t getShuntVoltage(const uint8_t* buf) {
return (int16_t)getU16(buf); // NOTE: LSB = 10 uV
}
uint16_t getU16(const uint8_t* buf) {