Hi, sorry for my noobish question, I just started in using C++ ☹
I was wondering how do I add a second “Device Type” using the ANT library you created? For example, I like to read Muscle Oxygen data and HR data, do I need to create a separate class for each device type?
I manage to read Muscle Oxygen using your example code “callBacks” example:
void setup()
{
AssignChannel ac;
ResetSystem rs;
SetNetworkKey snk;
ChannelId ci;
ChannelPeriod cp;
ChannelRfFrequency crf;
OpenChannel oc;
StartUpMessage sm;
Serial1.begin(BAUD_RATE);
ant.onBroadcastData(handleBroadcastMessage);
ant.onStartUpMessage(handleStartUpMessage);
ant.onPacketError(handleAntError);
ant.onChannelEventResponse(handleChannelEventResponse);
ant.onOtherResponse(handleMessageWithNoCallback);
ant.begin(Serial1);
Serial.begin(BAUD_RATE);
delay(1000);
// Delay to give the user time to connect on serial
Serial.println("Running");
ant.send(rs);
ant.waitFor(sm, 2000, itsAlive); // wait 2s for device to start
snk = SetNetworkKey();
snk.setNetwork(0);
snk.setKey((uint8_t*)NETWORK_KEY);
ant.send(snk);
if(ant.waitForStatus(snk.getMsgId(), 1000)) {
Serial.println("No Response for setting network key");
} else {
ChannelEventResponse cer = ChannelEventResponse();
ant.getResponse().getChannelEventResponseMsg(cer);
handleChannelEventResponse(cer, 0);
}
ac = AssignChannel();
ac.setChannel(0);
ac.setChannelType(CHANNEL_TYPE_BIDIRECTIONAL_RECEIVE); //can't wildcard this
ac.setChannelNetwork(0);
if (ant.sendAndWait(ac, 2000)) {
Serial.println("No Response for assigning channel");
} else {
ChannelEventResponse cer = ChannelEventResponse();
ant.getResponse().getChannelEventResponseMsg(cer);
handleChannelEventResponse(cer, 0);
}
ci = ChannelId();
ci.setChannel(0);
ci.setDeviceNumber(0);
ci.setDeviceType(31);
ci.setTransmissionType(0);
ant.send(ci);
ant.loop();
cp = ChannelPeriod();
cp.setChannel(0);
cp.setPeriod(8192); //can't wildcard this
ant.send(cp);
ant.loop();
crf = ChannelRfFrequency();
crf.setChannel(0);
crf.setRfFrequency(57); //can't wildcard this
ant.send(crf);
ant.loop();
oc = OpenChannel();
oc.setChannel(0);
ant.send(oc);
ant.loop();
}
Do I need to create a second class for the HR data?
PS thanks for your ANT library.
void setup(){ AssignChannel ac;
/* setup the driver here*/
// setup muscle oxygen channel here here ci = ChannelId(); ci.setChannel(0); // <-- Note: Channel 0 here ci.setDeviceNumber(0); ci.setDeviceType(MUSCLE_OXYGEN_DEVICE_TYPE); ci.setTransmissionType(0); ant.send(ci); ant.loop();
ci.setChannel(1); // <-- Note: Channel 1 here ci.setDeviceNumber(0); ci.setDeviceType(HR_DEVICE_TYPE); ci.setTransmissionType(0); ant.send(ci); ant.loop();
/* do the rest of the setup */}