INA233 power monitoring driver#1250
Conversation
|
This looks pretty great. It will be our first sensor implemented in TypeScript. ;) I noted a couple of small things to correct. I'll write those up when I have a little time. |
Combining these comments, you might rework the constructor: constructor(options: Options) {
try {
const io = (this.#io = new options.sensor.io({
hz: 400_000,
address: 0x40,
...options.sensor,
}))
// verify that we're talking to an ina233
const modelBuf = this.#io.readBuffer(COMMANDS.MFR_MODEL, 7)
const model = new TextDecoder().decode(new Uint8Array(modelBuf, 1))
if (model !== "INA233")
throw new Error(`Wrong model: ${model}`)
this.#io.sendByte(COMMANDS.RESTORE_DEFAULT_ALL)
// ensure certain configuration options get set now
this.configure({shuntOhms: 0.01, maxCurrent: 10, averaging: 1});
}
catch (e) {
this.close();
throw e;
}
}
|
|
Thanks for the review! I think I need an "ECMA-419 driver checklist" 😆 |
Agenda item for the December 6 workshop: "Making ECMA-419 more approachable for developers". This is exactly the kind of thing that we should do. (cc @HipsterBrown @dtex). |
|
Fixing this driver may take a little while 'cause of a testing bottleneck on my end. I only have one INA233 chip operational (dead-bugged) and I'm not sure I want to mess-up the firmware of the device it's in... I should make a breakout board... |
This PR adds support for the Texas Instruments INA233 power monitoring chip. It is typically used in battery systems to monitor battery voltage, current as well as overall power consumption. A special feature of this chip is to accumulate power internally allowing accurate
energy consumption measurements with relatively infrequent polling.
This driver is intended to conform with ECMA-419 and only supports a simple polling interface which is sufficient to keep track of what the battery pack is doing. It does not support a number of the chip's features, such as threshold alarms.