On this page
Remote
import taproot library
#include "tap/board/board.hpp"
#include "drivers_singleton.hpp"
#include "tap/communication/serial/uart_terminal_device.hpp"
use tap::communication::serial
namespace for printing
using namespace tap::communication::serial;
get drivers and initialize the board and terminal
//get drivers(controls basically everything)
src::Drivers *drivers = src::DoNotUse_getDrivers();
UartTerminalDevice ter(drivers);
ter.initialize();
modm::IOStream s(ter);
Board::initialize();
drivers->remote.initialize(); // init remote
initialize the remote
drivers->remote.initialize(); // init remote
in the main while loop read the remote with drivers->remote.read()
and check if its connected with drivers->remote.isConnected()
Then to read any value on the remote use drivers->remote.getChannel
In this case, we are reading the left joystick horizontal channel
drivers->remote.read(); // Reading the remote before we check if it is connected yet or not.
if (drivers->remote.isConnected())
{
// get remote value
double remoteValue = drivers->remote.getChannel(tap::communication::serial::Remote::Channel::LEFT_HORIZONTAL);
s.printf("remote: %f\n", remoteValue); // print out value
modm::delay_us(10000);
}
Code:
#include "tap/board/board.hpp"
#include "drivers_singleton.hpp"
#include "tap/communication/serial/uart_terminal_device.hpp"
using namespace tap::communication::serial;
int main()
{
//get drivers(controls basically everything)
src::Drivers *drivers = src::DoNotUse_getDrivers();
UartTerminalDevice ter(drivers);
ter.initialize();
modm::IOStream s(ter);
Board::initialize();
drivers->remote.initialize(); // init remote
while (1)
{
// Reading the remote before we check if it is connected yet or not.
drivers->remote.read();
if (drivers->remote.isConnected())
{
// get remote value
double remoteValue = drivers->remote.getChannel(tap::communication::serial::Remote::Channel::LEFT_HORIZONTAL);
s.printf("remote: %f\n", remoteValue); // print out value
modm::delay_us(10000);
}else{
s.printf(".");
}
modm::delay_us(10);
}
}