2020-12-26 14:12:05 -08:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
2020-07-04 10:10:43 -07:00
|
|
|
|
|
|
|
|
#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
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
|
|
|
|
* Register a callback on the Initialized property.
|
|
|
|
|
*
|
|
|
|
|
* @param callback the callback that will be called whenever the Initialized
|
|
|
|
|
* property is changed
|
|
|
|
|
* @param initialNotify if true, the callback will be run on the initial value
|
|
|
|
|
* @return the CallbackStore object storing this callback
|
|
|
|
|
*/
|
2023-05-31 22:10:53 -07:00
|
|
|
[[nodiscard]]
|
|
|
|
|
std::unique_ptr<CallbackStore> RegisterInitializedCallback(
|
2020-07-15 23:48:09 -07:00
|
|
|
NotifyCallback callback, bool initialNotify);
|
|
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
|
|
|
|
* Check if initialized.
|
|
|
|
|
*
|
|
|
|
|
* @return true if initialized
|
|
|
|
|
*/
|
2020-07-15 23:48:09 -07:00
|
|
|
bool GetInitialized() const;
|
|
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
|
|
|
|
* Change the Initialized value of the LED strip.
|
|
|
|
|
*
|
|
|
|
|
* @param initialized the new value
|
|
|
|
|
*/
|
2020-07-15 23:48:09 -07:00
|
|
|
void SetInitialized(bool initialized);
|
|
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
|
|
|
|
* Register a callback on the output port.
|
|
|
|
|
*
|
|
|
|
|
* @param callback the callback that will be called whenever the output port
|
|
|
|
|
* is changed
|
|
|
|
|
* @param initialNotify if true, the callback will be run on the initial value
|
|
|
|
|
* @return the CallbackStore object associated with this callback
|
|
|
|
|
*/
|
2023-05-31 22:10:53 -07:00
|
|
|
[[nodiscard]]
|
|
|
|
|
std::unique_ptr<CallbackStore> RegisterOutputPortCallback(
|
2020-07-15 23:48:09 -07:00
|
|
|
NotifyCallback callback, bool initialNotify);
|
|
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
|
|
|
|
* Get the output port.
|
|
|
|
|
*
|
|
|
|
|
* @return the output port
|
|
|
|
|
*/
|
2020-07-15 23:48:09 -07:00
|
|
|
int GetOutputPort() const;
|
|
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
|
|
|
|
* Change the output port.
|
|
|
|
|
*
|
|
|
|
|
* @param outputPort the new output port
|
|
|
|
|
*/
|
2020-07-15 23:48:09 -07:00
|
|
|
void SetOutputPort(int outputPort);
|
2020-07-04 10:10:43 -07:00
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
|
|
|
|
* Register a callback on the length.
|
|
|
|
|
*
|
|
|
|
|
* @param callback the callback that will be called whenever the length is
|
|
|
|
|
* changed
|
|
|
|
|
* @param initialNotify if true, the callback will be run on the initial value
|
|
|
|
|
* @return the CallbackStore object associated with this callback
|
|
|
|
|
*/
|
2023-05-31 22:10:53 -07:00
|
|
|
[[nodiscard]]
|
|
|
|
|
std::unique_ptr<CallbackStore> RegisterLengthCallback(NotifyCallback callback,
|
|
|
|
|
bool initialNotify);
|
2020-07-04 10:10:43 -07:00
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
|
|
|
|
* Get the length of the LED strip.
|
|
|
|
|
*
|
|
|
|
|
* @return the length
|
|
|
|
|
*/
|
2020-07-15 23:48:09 -07:00
|
|
|
int GetLength() const;
|
2020-07-04 10:10:43 -07:00
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
|
|
|
|
* Change the length of the LED strip.
|
|
|
|
|
*
|
|
|
|
|
* @param length the new value
|
|
|
|
|
*/
|
2020-07-15 23:48:09 -07:00
|
|
|
void SetLength(int length);
|
2020-07-04 10:10:43 -07:00
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
|
|
|
|
* Register a callback on whether the LEDs are running.
|
|
|
|
|
*
|
|
|
|
|
* @param callback the callback that will be called whenever the LED state is
|
|
|
|
|
* changed
|
|
|
|
|
* @param initialNotify if true, the callback will be run on the initial value
|
|
|
|
|
* @return the CallbackStore object associated with this callback
|
|
|
|
|
*/
|
2023-05-31 22:10:53 -07:00
|
|
|
[[nodiscard]]
|
|
|
|
|
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
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
|
|
|
|
* Check if the LEDs are running.
|
|
|
|
|
*
|
|
|
|
|
* @return true if they are
|
|
|
|
|
*/
|
2020-07-15 23:48:09 -07:00
|
|
|
int GetRunning() const;
|
2020-07-04 10:10:43 -07:00
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
|
|
|
|
* Change whether the LEDs are active.
|
|
|
|
|
*
|
|
|
|
|
* @param running the new value
|
|
|
|
|
*/
|
2020-07-15 23:48:09 -07:00
|
|
|
void SetRunning(bool running);
|
2020-07-04 10:10:43 -07:00
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
|
|
|
|
* Register a callback on the LED data.
|
|
|
|
|
*
|
|
|
|
|
* @param callback the callback that will be called whenever the LED data is
|
|
|
|
|
* changed
|
2021-10-14 18:09:38 -07:00
|
|
|
* @param initialNotify if true, the callback will be run on the initial value
|
2021-01-11 21:55:45 -08:00
|
|
|
* @return the CallbackStore object associated with this callback
|
|
|
|
|
*/
|
2023-05-31 22:10:53 -07:00
|
|
|
[[nodiscard]]
|
|
|
|
|
std::unique_ptr<CallbackStore> RegisterDataCallback(
|
2021-08-05 22:04:51 -04:00
|
|
|
ConstBufferCallback callback, bool initialNotify);
|
2020-07-15 23:48:09 -07:00
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
|
|
|
|
* Get the LED data.
|
|
|
|
|
*
|
|
|
|
|
* @param data output parameter to fill with LED data
|
|
|
|
|
* @return the length of the LED data
|
|
|
|
|
*/
|
2020-07-15 23:48:09 -07:00
|
|
|
int GetData(struct HAL_AddressableLEDData* data) const;
|
|
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
|
|
|
|
* Change the LED data.
|
|
|
|
|
*
|
|
|
|
|
* @param data the new data
|
|
|
|
|
* @param length the length of the LED data
|
|
|
|
|
*/
|
2020-07-15 23:48:09 -07:00
|
|
|
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
|