-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for trip computer reset
- Loading branch information
1 parent
d56a85b
commit c8e2be5
Showing
11 changed files
with
195 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// VanDisplayStatusStructs.h | ||
#pragma once | ||
|
||
#ifndef _VanDisplayStatusStructs_h | ||
#define _VanDisplayStatusStructs_h | ||
|
||
#include "../../Helpers/Serializer.h" | ||
#include "../AbstractVanMessageSender.h" | ||
|
||
// VANID: 5E4 | ||
const uint16_t VAN_ID_DISPLAY_STATUS = 0x5E4; | ||
|
||
// Read left to right in documentation | ||
typedef struct VanDisplayStatusStruct { | ||
uint8_t Byte0; | ||
uint8_t Byte1; | ||
}; | ||
|
||
typedef union VanDisplayStatusPacket { | ||
VanDisplayStatusStruct data; | ||
uint8_t VanDisplayStatusPacket[sizeof(VanDisplayStatusStruct)]; | ||
}; | ||
|
||
|
||
#pragma region Sender class | ||
class VanDisplayStatusPacketSender | ||
{ | ||
AbstractVanMessageSender * vanMessageSender; | ||
|
||
public: | ||
VanDisplayStatusPacketSender(AbstractVanMessageSender * object) | ||
{ | ||
vanMessageSender = object; | ||
} | ||
|
||
void SendReady(uint8_t channelId) | ||
{ | ||
VanDisplayStatusPacket packet; | ||
memset(&packet, 0, sizeof(packet)); | ||
|
||
packet.data.Byte0 = 0x20; | ||
packet.data.Byte1 = 0x1E; | ||
|
||
unsigned char *serializedPacket = Serialize<VanDisplayStatusPacket>(packet); | ||
vanMessageSender->set_channel_for_transmit_message(channelId, VAN_ID_DISPLAY_STATUS, serializedPacket, sizeof(packet), 1); | ||
memset(&packet, 0, 0); | ||
delete[] serializedPacket; | ||
} | ||
|
||
void SendTripReset(uint8_t channelId) | ||
{ | ||
VanDisplayStatusPacket packet; | ||
memset(&packet, 0, sizeof(packet)); | ||
|
||
packet.data.Byte0 = 0xA0; | ||
packet.data.Byte1 = 0x1E; | ||
|
||
unsigned char *serializedPacket = Serialize<VanDisplayStatusPacket>(packet); | ||
vanMessageSender->set_channel_for_transmit_message(channelId, VAN_ID_DISPLAY_STATUS, serializedPacket, sizeof(packet), 1); | ||
memset(&packet, 0, 0); | ||
delete[] serializedPacket; | ||
} | ||
|
||
void Disable(uint8_t channelId) | ||
{ | ||
vanMessageSender->disable_channel(channelId); | ||
} | ||
}; | ||
#pragma endregion | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// VanDisplayStatus.h | ||
#pragma once | ||
|
||
#ifndef _VanDisplayStatus_h | ||
#define _VanDisplayStatus_h | ||
|
||
#include "VanMessageWriterBase.h" | ||
#include "../AbstractVanMessageSender.h" | ||
#include "../../Van/Structs/VanDisplayStatusStructs.h" | ||
|
||
class VanDisplayStatus : public VanMessageWriterBase | ||
{ | ||
const static uint16_t SEND_STATUS_INTERVAL = 420; | ||
const static uint8_t SEND_STATUS_CHANNEL = 0; | ||
|
||
uint8_t _tripButtonState = 0; | ||
uint8_t _resetTrip = 0; | ||
uint8_t _resetSent = 0; | ||
unsigned long _tripButtonPressedTime = 0; | ||
|
||
VanDisplayStatusPacketSender* displayStatusSender; | ||
|
||
virtual void InternalProcess() override | ||
{ | ||
if (_resetTrip == 1 && _resetSent == 0) | ||
{ | ||
displayStatusSender->SendTripReset(SEND_STATUS_CHANNEL); | ||
_resetTrip = 0; | ||
_resetSent = 1; | ||
} | ||
else | ||
{ | ||
displayStatusSender->SendReady(SEND_STATUS_CHANNEL); | ||
} | ||
} | ||
|
||
public: | ||
VanDisplayStatus(AbstractVanMessageSender* vanMessageSender) : VanMessageWriterBase(vanMessageSender, SEND_STATUS_INTERVAL) | ||
{ | ||
displayStatusSender = new VanDisplayStatusPacketSender(vanMessageSender); | ||
displayStatusSender->SendReady(SEND_STATUS_CHANNEL); | ||
} | ||
|
||
void SetData(uint8_t tripButton, unsigned long currentTime) | ||
{ | ||
if (tripButton == 1 && _tripButtonState == 0) | ||
{ | ||
_tripButtonState = 1; | ||
_tripButtonPressedTime = currentTime; | ||
} | ||
if (tripButton == 0 && _tripButtonState == 1) | ||
{ | ||
_tripButtonState = 0; | ||
_resetSent = 0; | ||
_resetTrip = 0; | ||
} | ||
if (tripButton == 1 && _tripButtonState == 1 && currentTime - _tripButtonPressedTime > 2000) | ||
{ | ||
_resetTrip = 1; | ||
} | ||
} | ||
|
||
void Stop() | ||
{ | ||
displayStatusSender->Disable(SEND_STATUS_CHANNEL); | ||
} | ||
|
||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters