Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Allow overriding ANTProfile::ProcessMessage() #6

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/ANTProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,14 @@ uint32_t ANTProfile::Setup(uint8_t channel)
}
}

if (_BeforeOpenChannel) {
err_code = _BeforeOpenChannel(m_channel_number);
if (err_code != NRF_SUCCESS)
{
return err_code;
}
}

err_code = sd_ant_channel_open(m_channel_number);
if (err_code != NRF_SUCCESS)
{
Expand Down
8 changes: 5 additions & 3 deletions src/ANTProfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,18 @@ class ANTProfile

ANTProfile(ANTTransmissionMode mode);

//profile operartions
//profile operations
uint32_t Setup(uint8_t channel);

//Profile name
void setName(const char* pname) {name=pname;}
const char* getName(void) {return name;}
uint8_t getChannelNumber(void) { return m_channel_number;}

void ProcessMessage(ant_evt_t* evt);
virtual void ProcessMessage(ant_evt_t* evt);
void setUnhandledEventListener(void (*fp)(ant_evt_t* evt)) { _AntUnhandledEventLister = fp; };
void setAllEventListener(void (*fp)(ant_evt_t* evt)) { _AntAllEventLister = fp; };
void setBeforeOpenChannel(uint32_t (*fp)(uint8_t channel)) { _BeforeOpenChannel = fp; };
//void setCustomDataPtr(void* ptr) { m_customDataPtr = ptr;}
//void* getCustomDataPtr(void) {return m_customDataPtr;}
bool newRxData = false;
Expand All @@ -114,7 +115,8 @@ class ANTProfile
virtual void EncodeMessage() = 0;
uint32_t SendMessage();
void (*_AntUnhandledEventLister)(ant_evt_t* evt) = NULL;
void (*_AntAllEventLister)(ant_evt_t* evt) = NULL;
void (*_AntAllEventLister)(ant_evt_t* evt) = NULL;
uint32_t (*_BeforeOpenChannel)(uint8_t chan) = NULL;
const char * name = "";

uint8_t m_channel_number; ///< Channel number assigned to the profile.
Expand Down
2 changes: 0 additions & 2 deletions src/profiles/BicycleSpeedCadence.h
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,6 @@ class BicycleSpeedCadence : public ANTProfile
public:
BicycleSpeedCadence(BSCDeviceType d_t, ANTTransmissionMode mode);

void ProcessMessage(ant_evt_t*);

// void SetSpeed(float val);
// float GetSpeed() { return m_speed; };

Expand Down
2 changes: 1 addition & 1 deletion src/profiles/Environment.hh
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public:
EnvironmentSensor(ANTTransmissionMode mode);
//~EnvironmentRx();
//bool Setup();
//void ProcessMessage(ant_evt_t*);
void ProcessMessage(ant_evt_t*) override;
void SetOnTemperatureData(void (*fp)(int16_t)) {_OnTemperatureData_cb = fp;}
};

Expand Down
2 changes: 0 additions & 2 deletions src/profiles/HeartRateMonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,6 @@ class HeartRateMonitor : public ANTProfile
public:
HeartRateMonitor(ANTTransmissionMode mode);

void ProcessMessage(ant_evt_t*);

void SetOnComputedHeartRate(void (*fp)(int)) { _OnComputedHeartRate_cb = fp;}


Expand Down