void AD770X::init(byte channel, byte clkDivider, byte polarity, byte gain, byte updRate) { setNextOperation(REG_CLOCK, channel, 0); writeClockRegister(0, clkDivider, updRate); setNextOperation(REG_SETUP, channel, 0); writeSetupRegister(MODE_SELF_CAL, gain, polarity, 0, 0); while (!dataReady(channel)) { }; }
double AD770X::readADResult(byte channel, float refOffset) { while (!dataReady(channel)) { }; setNextOperation(REG_DATA, channel, 1); return readADResult() * 1.0 / 65536.0 * VRef - refOffset; }
STDMETHODIMP ProgressWrap::SetNextOperation(IN_BSTR aNextOperationDescription, ULONG aNextOperationsWeight) { LogRelFlow(("{%p} %s:enter aNextOperationDescription=%ls aNextOperationsWeight=%RU32\n", this, "Progress::setNextOperation", aNextOperationDescription, aNextOperationsWeight)); VirtualBoxBase::clearError(); HRESULT hrc; try { AutoCaller autoCaller(this); if (FAILED(autoCaller.rc())) throw autoCaller.rc(); hrc = setNextOperation(BSTRInConverter(aNextOperationDescription).str(), aNextOperationsWeight); } catch (HRESULT hrc2) { hrc = hrc2; } catch (...) { hrc = VirtualBoxBase::handleUnexpectedExceptions(this, RT_SRC_POS); } LogRelFlow(("{%p} %s: leave hrc=%Rhrc\n", this, "Progress::setNextOperation", hrc)); return hrc; }
bool AD770X::dataReady(byte channel) { setNextOperation(REG_CMM, channel, 1); digitalWrite(pinCS, LOW); byte b1 = SPI.transfer(0x0); digitalWrite(pinCS, HIGH); return (b1 & 0x80) == 0x0; }