0xCAFEDECAF / VanBus

Vehicle Area Network (VAN) bus packet reader/writer for ESP8266 and ESP32
MIT License
40 stars 5 forks source link

Writing negative temperatures on VAN Bus #7

Closed mijanto closed 12 months ago

mijanto commented 1 year ago

Hello, how do I write negative temperature on VAN Bus? There is unsinged integer for the data rmtTemperatureBytes[].

uint8_t rmtTemperatureBytes[] = {0x0F, 0x07, 0x00, 0x00, 0x00, 0x00, Temperature * 2 + 0x50};

As I set Temperature variable to negative number, it is written as positive in that array.

mijanto commented 1 year ago

Ok, theoretically I figured it out, still needs to be tested. Calculation of the number in array was just slightly edited. Theoretically should work up to -40°C, so the variable would be 0 (-40 * 2 + 0x50 = 0). Edited formula:

uint8_t rmtTemperatureBytes[] = {0x0F, 0x07, 0x00, 0x00, 0x00, 0x00, ((Temperature * 2) + 0x50)};
0xCAFEDECAF commented 1 year ago

Hi Mijanto, thanks for noticing! I pushed a fix in commit 0285958 .