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:
|
|
|
|
|
/**
|
2025-07-21 21:52:10 -07:00
|
|
|
* Constructs an addressable LED for a specific channel.
|
|
|
|
|
*
|
|
|
|
|
* @param channel output channel
|
2020-07-04 10:10:43 -07:00
|
|
|
*/
|
2025-07-21 21:52:10 -07:00
|
|
|
explicit AddressableLEDSim(int channel);
|
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
|
|
|
|
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
|
|
|
/**
|
2025-07-21 21:52:10 -07:00
|
|
|
* Register a callback on the start.
|
2021-01-11 21:55:45 -08:00
|
|
|
*
|
2025-07-21 21:52:10 -07:00
|
|
|
* @param callback the callback that will be called whenever the start
|
2021-01-11 21:55:45 -08:00
|
|
|
* 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]]
|
2025-07-21 21:52:10 -07:00
|
|
|
std::unique_ptr<CallbackStore> RegisterStartCallback(NotifyCallback callback,
|
|
|
|
|
bool initialNotify);
|
2020-07-15 23:48:09 -07:00
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
2025-07-21 21:52:10 -07:00
|
|
|
* Get the start.
|
2021-01-11 21:55:45 -08:00
|
|
|
*
|
2025-07-21 21:52:10 -07:00
|
|
|
* @return the start
|
2021-01-11 21:55:45 -08:00
|
|
|
*/
|
2025-07-21 21:52:10 -07:00
|
|
|
int GetStart() const;
|
2020-07-15 23:48:09 -07:00
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
2025-07-21 21:52:10 -07:00
|
|
|
* Change the start.
|
2021-01-11 21:55:45 -08:00
|
|
|
*
|
2025-07-21 21:52:10 -07:00
|
|
|
* @param start the new start
|
2021-01-11 21:55:45 -08:00
|
|
|
*/
|
2025-07-21 21:52:10 -07:00
|
|
|
void SetStart(int start);
|
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
|
|
|
/**
|
2025-07-21 21:52:10 -07:00
|
|
|
* Get the LED data.
|
2021-01-11 21:55:45 -08:00
|
|
|
*
|
2025-07-21 21:52:10 -07:00
|
|
|
* @param data output parameter to fill with LED data
|
|
|
|
|
* @return the length of the LED data
|
2021-01-11 21:55:45 -08:00
|
|
|
*/
|
2025-07-21 21:52:10 -07:00
|
|
|
int GetData(struct HAL_AddressableLEDData* data) const;
|
2020-07-04 10:10:43 -07:00
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
2025-07-21 21:52:10 -07:00
|
|
|
* Change the LED data.
|
2021-01-11 21:55:45 -08:00
|
|
|
*
|
2025-07-21 21:52:10 -07:00
|
|
|
* @param data the new data
|
2021-01-11 21:55:45 -08:00
|
|
|
*/
|
2025-07-21 21:52:10 -07:00
|
|
|
void SetData(struct HAL_AddressableLEDData* data);
|
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]]
|
2025-07-21 21:52:10 -07:00
|
|
|
static 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
|
|
|
/**
|
2025-07-21 21:52:10 -07:00
|
|
|
* Get the global LED data.
|
2021-01-11 21:55:45 -08:00
|
|
|
*
|
2025-07-21 21:52:10 -07:00
|
|
|
* @param start the start of the LED data
|
|
|
|
|
* @param length the length of the LED data
|
2021-01-11 21:55:45 -08:00
|
|
|
* @param data output parameter to fill with LED data
|
|
|
|
|
* @return the length of the LED data
|
|
|
|
|
*/
|
2025-07-21 21:52:10 -07:00
|
|
|
static int GetGlobalData(int start, int length,
|
|
|
|
|
struct HAL_AddressableLEDData* data);
|
2020-07-15 23:48:09 -07:00
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
2025-07-21 21:52:10 -07:00
|
|
|
* Change the global LED data.
|
2021-01-11 21:55:45 -08:00
|
|
|
*
|
2025-07-21 21:52:10 -07:00
|
|
|
* @param start the start of the LED data
|
2021-01-11 21:55:45 -08:00
|
|
|
* @param length the length of the LED data
|
2025-07-21 21:52:10 -07:00
|
|
|
* @param data the new data
|
2021-01-11 21:55:45 -08:00
|
|
|
*/
|
2025-07-21 21:52:10 -07:00
|
|
|
static void SetGlobalData(int start, int length,
|
|
|
|
|
struct HAL_AddressableLEDData* data);
|
2020-07-04 10:10:43 -07:00
|
|
|
|
|
|
|
|
private:
|
2025-07-21 21:52:10 -07:00
|
|
|
int m_channel;
|
2020-07-04 10:10:43 -07:00
|
|
|
};
|
|
|
|
|
} // namespace sim
|
|
|
|
|
} // namespace frc
|