2020-07-04 10:10:43 -07:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
/* Copyright (c) 2018-2020 FIRST. All Rights Reserved. */
|
|
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
|
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
2020-07-15 23:48:09 -07:00
|
|
|
#include "frc/simulation/CallbackStore.h"
|
2020-07-04 10:10:43 -07:00
|
|
|
|
2020-07-15 23:48:09 -07:00
|
|
|
struct HAL_AddressableLEDData;
|
2020-07-04 10:10:43 -07:00
|
|
|
|
|
|
|
|
namespace frc {
|
2020-07-15 23:48:09 -07:00
|
|
|
|
|
|
|
|
class AddressableLED;
|
|
|
|
|
|
2020-07-04 10:10:43 -07:00
|
|
|
namespace sim {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class to control a simulated addressable LED.
|
|
|
|
|
*/
|
|
|
|
|
class AddressableLEDSim {
|
|
|
|
|
public:
|
|
|
|
|
/**
|
|
|
|
|
* Constructs for the first addressable LED.
|
|
|
|
|
*/
|
2020-07-15 23:48:09 -07:00
|
|
|
AddressableLEDSim();
|
2020-07-04 10:10:43 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Constructs from an AddressableLED object.
|
|
|
|
|
*
|
|
|
|
|
* @param addressableLED AddressableLED to simulate
|
|
|
|
|
*/
|
2020-07-15 23:48:09 -07:00
|
|
|
explicit AddressableLEDSim(const AddressableLED& addressableLED);
|
2020-07-04 10:10:43 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates an AddressableLEDSim for a PWM channel.
|
|
|
|
|
*
|
|
|
|
|
* @param pwmChannel PWM channel
|
|
|
|
|
* @return Simulated object
|
|
|
|
|
* @throws std::out_of_range if no AddressableLED is configured for that
|
|
|
|
|
* channel
|
|
|
|
|
*/
|
2020-07-15 23:48:09 -07:00
|
|
|
static AddressableLEDSim CreateForChannel(int pwmChannel);
|
2020-07-04 10:10:43 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates an AddressableLEDSim for a simulated index.
|
|
|
|
|
* The index is incremented for each simulated AddressableLED.
|
|
|
|
|
*
|
|
|
|
|
* @param index simulator index
|
|
|
|
|
* @return Simulated object
|
|
|
|
|
*/
|
2020-07-15 23:48:09 -07:00
|
|
|
static AddressableLEDSim CreateForIndex(int index);
|
2020-07-04 10:10:43 -07:00
|
|
|
|
|
|
|
|
std::unique_ptr<CallbackStore> RegisterInitializedCallback(
|
2020-07-15 23:48:09 -07:00
|
|
|
NotifyCallback callback, bool initialNotify);
|
|
|
|
|
|
|
|
|
|
bool GetInitialized() const;
|
|
|
|
|
|
|
|
|
|
void SetInitialized(bool initialized);
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<CallbackStore> RegisterOutputPortCallback(
|
|
|
|
|
NotifyCallback callback, bool initialNotify);
|
|
|
|
|
|
|
|
|
|
int GetOutputPort() const;
|
|
|
|
|
|
|
|
|
|
void SetOutputPort(int outputPort);
|
2020-07-04 10:10:43 -07:00
|
|
|
|
|
|
|
|
std::unique_ptr<CallbackStore> RegisterLengthCallback(NotifyCallback callback,
|
2020-07-15 23:48:09 -07:00
|
|
|
bool initialNotify);
|
2020-07-04 10:10:43 -07:00
|
|
|
|
2020-07-15 23:48:09 -07:00
|
|
|
int GetLength() const;
|
2020-07-04 10:10:43 -07:00
|
|
|
|
2020-07-15 23:48:09 -07:00
|
|
|
void SetLength(int length);
|
2020-07-04 10:10:43 -07:00
|
|
|
|
|
|
|
|
std::unique_ptr<CallbackStore> RegisterRunningCallback(
|
2020-07-15 23:48:09 -07:00
|
|
|
NotifyCallback callback, bool initialNotify);
|
2020-07-04 10:10:43 -07:00
|
|
|
|
2020-07-15 23:48:09 -07:00
|
|
|
int GetRunning() const;
|
2020-07-04 10:10:43 -07:00
|
|
|
|
2020-07-15 23:48:09 -07:00
|
|
|
void SetRunning(bool running);
|
2020-07-04 10:10:43 -07:00
|
|
|
|
|
|
|
|
std::unique_ptr<CallbackStore> RegisterDataCallback(NotifyCallback callback,
|
2020-07-15 23:48:09 -07:00
|
|
|
bool initialNotify);
|
|
|
|
|
|
|
|
|
|
int GetData(struct HAL_AddressableLEDData* data) const;
|
|
|
|
|
|
|
|
|
|
void SetData(struct HAL_AddressableLEDData* data, int length);
|
2020-07-04 10:10:43 -07:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
explicit AddressableLEDSim(int index) : m_index{index} {}
|
|
|
|
|
|
|
|
|
|
int m_index;
|
|
|
|
|
};
|
|
|
|
|
} // namespace sim
|
|
|
|
|
} // namespace frc
|