6 void JrkG2Serial::commandW7(uint8_t cmd, uint8_t val)
8 sendCommandHeader(cmd);
14 void JrkG2Serial::commandWs14(uint8_t cmd, int16_t val)
17 sendCommandHeader(cmd);
24 uint8_t JrkG2Serial::commandR8(uint8_t cmd)
28 sendCommandHeader(cmd);
30 uint8_t byteCount = _stream->readBytes(&val, 1);
41 uint16_t JrkG2Serial::commandR16(uint8_t cmd)
45 sendCommandHeader(cmd);
47 uint8_t byteCount = _stream->readBytes(buffer, 2);
55 return ((uint16_t)buffer[0] << 0) | ((uint16_t)buffer[1] << 8);
58 void JrkG2Serial::segmentRead(uint8_t cmd, uint8_t offset,
59 uint8_t length, uint8_t * buffer)
62 if (length > 15) { length = 15; }
64 sendCommandHeader(cmd);
68 uint8_t byteCount = _stream->readBytes(buffer, length);
69 if (byteCount != length)
75 memset(buffer, 0, length);
82 void JrkG2Serial::segmentWrite(uint8_t cmd, uint8_t offset,
83 uint8_t length, uint8_t * buffer)
86 if (length > 7) { length = 7; }
88 sendCommandHeader(cmd);
94 for (uint8_t i = 0; i < length; i++)
97 msbs |= (buffer[i] >> 7 & 1) << i;
104 void JrkG2Serial::sendCommandHeader(uint8_t cmd)
106 if (_deviceNumber == 255)
109 _stream->write((uint8_t)cmd);
114 _stream->write(0xAA);
115 serialW7(_deviceNumber);
116 serialW7((uint8_t)cmd);
123 void JrkG2I2C::commandQuick(uint8_t cmd)
125 Wire.beginTransmission(_address);
130 void JrkG2I2C::commandW7(uint8_t cmd, uint8_t val)
132 Wire.beginTransmission(_address);
134 Wire.write(val & 0x7F);
138 void JrkG2I2C::commandWs14(uint8_t cmd, int16_t val)
141 Wire.beginTransmission(_address);
143 Wire.write(v & 0xFF);
144 Wire.write(v >> 8 & 0xFF);
148 uint8_t JrkG2I2C::commandR8(uint8_t cmd)
150 Wire.beginTransmission(_address);
155 uint8_t byteCount = Wire.requestFrom(_address, (uint8_t)1);
163 uint8_t val = Wire.read();
167 uint16_t JrkG2I2C::commandR16(uint8_t cmd)
169 Wire.beginTransmission(_address);
174 uint8_t byteCount = Wire.requestFrom(_address, (uint8_t)2);
182 uint8_t valL = Wire.read();
183 uint8_t valH = Wire.read();
184 return (uint16_t)valL | ((uint16_t)valH << 8);
187 void JrkG2I2C::segmentRead(uint8_t cmd, uint8_t offset,
188 uint8_t length, uint8_t * buffer)
191 if (length > 15) { length = 15; }
193 Wire.beginTransmission(_address);
201 memset(buffer, 0, length);
205 uint8_t byteCount = Wire.requestFrom(_address, (uint8_t)length);
206 if (byteCount != length)
209 memset(buffer, 0, length);
214 for (uint8_t i = 0; i < length; i++)
216 buffer[i] = Wire.read();
220 void JrkG2I2C::segmentWrite(uint8_t cmd, uint8_t offset,
221 uint8_t length, uint8_t * buffer)
224 if (length > 13) { length = 13; }
226 Wire.beginTransmission(_address);
227 Wire.write((uint8_t)cmd);
230 for (uint8_t i = 0; i < length; i++)
232 Wire.write(buffer[i]);
const uint8_t JrkG2CommReadError