5#include <frc/smartdashboard/SmartDashboard.h>
6#include <frc/util/Color8Bit.h>
7#include <frc2/command/CommandPtr.h>
8#include <frc2/command/InstantCommand.h>
9#include <frc2/command/SubsystemBase.h>
10#include <hal/SimDevice.h>
291 color = frc::Color8Bit(0, 0, 0);
296 return std::string(
"\tOffset: ") + std::to_string(
offset) +
"\n" +
297 std::string(
"\tCount: ") + std::to_string(
count) +
"\n" +
298 std::string(
"\tReversed: ") + std::to_string(
reversed) +
"\n" +
299 std::string(
"\tColor: ") + std::string(
color.HexString().c_str()) +
300 "\n" + std::string(
"\tPattern: ") +
301 std::to_string(
static_cast<uint8_t
>(
pattern)) +
"\n";
330 frc::I2C::Port port = frc::I2C::kMXP,
331 units::second_t connectorXDelay = 0.002_s);
354 return m_device.
ports[
static_cast<uint8_t
>(port)].zones[zoneIndex].pattern;
408 int16_t delay = -1, uint8_t zoneIndex = 0,
409 bool reversed =
false);
416 uint8_t zoneIndex = 0);
422 setColor(port, color.red, color.green, color.blue, zoneIndex);
431 setColor(port, (color >> 16) & 255, (color >> 8) & 255, color & 255,
439 return m_device.
ports[
static_cast<uint8_t
>(port)].zones[zoneIndex].color;
503 bool reversed =
false,
bool setReversed =
false);
508 return port.zones[port.currentZoneIndex];
523 bool expectResponse =
false);
525 void delaySeconds(units::second_t delaySeconds) {
526 std::this_thread::sleep_for(std::chrono::milliseconds(2));
529 std::unique_ptr<frc::I2C> _i2c;
530 uint8_t _slaveAddress;
532 units::second_t _delay;
535 hal::SimDevice m_simDevice;
536 hal::SimInt m_simColorR, m_simColorG, m_simColorB;
537 hal::SimBoolean m_simOn;
Driver for use with the I2C, V2 iteration of Connector-X.
bool initialize()
Start communication with the controller.
void sendRadioMessage(Message message)
Send a message via the radio; set team to 0xFFFF to broadcast to all.
void syncZones(LedPort port, const std::vector< uint8_t > &zones)
Sync up to 10 zones to the same 0 state.
void createZones(LedPort port, std::vector< Commands::NewZone > &&newZones)
Create up to 10 new zones.
Commands::CommandType lastCommand() const
Get the last command sent.
void setLedPort(LedPort port)
ConnectorXBoard(uint8_t slaveAddress, frc::I2C::Port port=frc::I2C::kMXP, units::second_t connectorXDelay=0.002_s)
Construct a new Connector-X driver instance.
void setConfig(Commands::Configuration config)
Store the config in board's EEPROM.
CachedZone & getCurrentZone()
void configureDigitalPin(DigitalPort port, PinMode mode)
Configure a digital IO pin. Think Arduino pinMode()
void setPattern(LedPort port, PatternType pattern, bool oneShot=false, int16_t delay=-1, uint8_t zoneIndex=0, bool reversed=false)
Send the PATTERN command.
frc::Color8Bit getCurrentColor(LedPort port, uint8_t zoneIndex=0)
Get the current on-board Color, not the cached one.
void setColor(LedPort port, uint8_t red, uint8_t green, uint8_t blue, uint8_t zoneIndex=0)
Set the color; must also call a pattern to see it.
bool readDigitalPin(DigitalPort port)
Read state of digital IO pin.
Commands::Configuration readConfig()
Read the config stored in EEPROM.
LedPort getCurrentLedPort()
Get the current port.
bool getPatternDone(LedPort port)
Read if pattern is done running.
Message getLatestRadioMessage()
Read the last received message.
void setColor(LedPort port, frc::Color8Bit color, uint8_t zoneIndex=0)
Set the color using frc::Color8Bit.
uint16_t readAnalogPin(AnalogPort port)
Read the ADC value. Ranges from 0 - 3.3v; 12 bits of precision.
void writeDigitalPin(DigitalPort port, bool value)
Set a digital IO pin.
CachedZone & setCurrentZone(LedPort port, uint8_t zoneIndex=0, bool reversed=false, bool setReversed=false)
Set the current zone for running patterns.
void setColor(LedPort port, uint32_t color, uint8_t zoneIndex=0)
Set the color; must also call a pattern to see it.
PatternType lastPattern(LedPort port, uint8_t zoneIndex=0) const
Get the last pattern sent.
CachedPort & getCurrentCachedPort()
std::vector< CachedPort > ports
std::vector< CachedZone > zones
Stores the state of the Connector-X device locally.
CachedZone(Commands::NewZone zone)
Commands::Configuration config
ResponseData responseData
CommandDigitalSetup commandDigitalSetup
CommandSetNewZones commandSetNewZones
CommandGetColor commandGetColor
CommandDigitalRead commandDigitalRead
CommandPattern commandPattern
CommandRadioGetLatestReceived commandRadioGetLatestReceived
CommandSetConfig commandSetConfig
CommandDigitalWrite commandDigitalWrite
CommandColor commandColor
CommandReadConfig commandReadConfig
CommandSetPatternZone commandSetPatternZone
CommandGetPort commandGetPort
CommandReadAnalog commandReadAnalog
CommandReadPatternDone commandReadPatternDone
CommandSyncZoneStates commandSyncZoneStates
CommandSetLedPort commandSetLedPort
CommandRadioSend commandRadioSend
ResponseReadPort responseReadPort
ResponseReadAnalog responseReadAnalog
ResponseRadioLastReceived responseRadioLastReceived
ResponsePatternDone responsePatternDone
ResponseDigitalRead responseDigitalRead
ResponseReadConfiguration responseReadConfiguration
ResponseReadColor responseReadColor