Remove millis calls from transmit_rs485

This commit is contained in:
Daniel Öster 2025-05-11 21:13:45 +03:00
parent 3369639795
commit 3d1644c14e
3 changed files with 5 additions and 8 deletions

View file

@ -151,7 +151,7 @@ void setup_battery(void);
void update_values_battery();
#ifdef RS485_BATTERY_SELECTED
void transmit_rs485();
void transmit_rs485(unsigned long currentMillis);
void receive_RS485();
#else
void handle_incoming_can_frame_battery(CAN_frame rx_frame);

View file

@ -154,24 +154,21 @@ void decode_packet(uint8_t command, uint8_t data[8]) {
}
}
void transmit_rs485() {
void transmit_rs485(unsigned long currentMillis) {
static uint8_t nextCommand = 0x90;
if (millis() - lastPacket > 60) {
if (currentMillis - lastPacket > 60) {
lastPacket = currentMillis;
uint8_t tx_buff[13] = {0};
tx_buff[0] = 0xA5;
tx_buff[1] = 0x40;
tx_buff[2] = nextCommand;
tx_buff[3] = 8;
tx_buff[12] = calculate_checksum(tx_buff);
#ifdef DEBUG_VIA_USB
dump_buff("transmitting: ", tx_buff, 13);
#endif
Serial2.write(tx_buff, 13);
lastPacket = millis();
nextCommand++;
if (nextCommand > 0x98)
nextCommand = 0x90;