4 static const uint16_t Tic03aCurrentTable[33] =
45 if (product == TicProduct::T500)
47 for (uint8_t i = 0; i < 33; i++)
49 if (Tic03aCurrentTable[i] <= limit)
59 else if (product == TicProduct::T249)
63 else if (product == TicProduct::Tic36v4)
65 if (limit < 72) { code = 0; }
66 else if (limit >= 9095) { code = 127; }
69 code = ((uint32_t)limit * 768 - 55000 / 2) / 55000;
70 if (code < 127 && (((uint32_t)55000 * (code + 1) + 384) / 768) <= limit)
81 commandW7(TicCommand::SetCurrentLimit, code);
86 uint8_t code = getVar8(VarOffset::CurrentLimit);
87 if (product == TicProduct::T500)
89 if (code > 32) { code = 32; }
90 return Tic03aCurrentTable[code];
92 else if (product == TicProduct::T249)
96 else if (product == TicProduct::Tic36v4)
98 return ((uint32_t)55000 * code + 384) / 768;
108 void TicSerial::commandW32(
TicCommand cmd, uint32_t val)
110 sendCommandHeader(cmd);
117 serialW7(((val >> 7) & 1) |
130 void TicSerial::commandW7(
TicCommand cmd, uint8_t val)
132 sendCommandHeader(cmd);
138 void TicSerial::getSegment(
TicCommand cmd, uint8_t offset,
139 uint8_t length,
void * buffer)
142 sendCommandHeader(cmd);
143 serialW7(offset & 0x7F);
144 serialW7(length | (offset >> 1 & 0x40));
146 uint8_t byteCount = _stream->readBytes((uint8_t *)buffer, length);
147 if (byteCount != length)
153 memset(buffer, 0, length);
160 void TicSerial::sendCommandHeader(
TicCommand cmd)
162 if (_deviceNumber == 255)
165 _stream->write((uint8_t)cmd);
170 _stream->write(0xAA);
171 serialW7(_deviceNumber);
172 serialW7((uint8_t)cmd);
181 Wire.beginTransmission(_address);
182 Wire.write((uint8_t)cmd);
186 void TicI2C::commandW32(
TicCommand cmd, uint32_t val)
188 Wire.beginTransmission(_address);
189 Wire.write((uint8_t)cmd);
190 Wire.write(val >> 0);
191 Wire.write(val >> 8);
192 Wire.write(val >> 16);
193 Wire.write(val >> 24);
197 void TicI2C::commandW7(
TicCommand cmd, uint8_t val)
199 Wire.beginTransmission(_address);
200 Wire.write((uint8_t)cmd);
201 Wire.write(val & 0x7F);
205 void TicI2C::getSegment(
TicCommand cmd, uint8_t offset,
206 uint8_t length,
void * buffer)
208 Wire.beginTransmission(_address);
209 Wire.write((uint8_t)cmd);
216 memset(buffer, 0, length);
220 uint8_t byteCount = Wire.requestFrom(_address, (uint8_t)length);
221 if (byteCount != length)
224 memset(buffer, 0, length);
229 uint8_t * ptr = (uint8_t *)buffer;
230 for (uint8_t i = 0; i < length; i++)
void setCurrentLimit(uint16_t limit)
const uint8_t TicT249CurrentUnits
const uint8_t TicCurrentUnits
uint16_t getCurrentLimit()