2018-05-11 12:38:23 -07:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2020-06-27 22:11:24 -07:00
|
|
|
/* Copyright (c) 2018-2020 FIRST. All Rights Reserved. */
|
2018-05-11 12:38:23 -07:00
|
|
|
/* 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>
|
|
|
|
|
#include <utility>
|
|
|
|
|
|
2020-06-27 22:11:24 -07:00
|
|
|
#include <hal/simulation/DriverStationData.h>
|
|
|
|
|
|
2018-05-11 12:38:23 -07:00
|
|
|
#include "CallbackStore.h"
|
|
|
|
|
|
|
|
|
|
namespace frc {
|
|
|
|
|
namespace sim {
|
2020-07-04 10:10:43 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class to control a simulated driver station.
|
|
|
|
|
*/
|
2018-05-11 12:38:23 -07:00
|
|
|
class DriverStationSim {
|
|
|
|
|
public:
|
2020-07-04 10:10:43 -07:00
|
|
|
static std::unique_ptr<CallbackStore> RegisterEnabledCallback(
|
2018-05-11 12:38:23 -07:00
|
|
|
NotifyCallback callback, bool initialNotify) {
|
|
|
|
|
auto store = std::make_unique<CallbackStore>(
|
|
|
|
|
-1, callback, &HALSIM_CancelDriverStationEnabledCallback);
|
|
|
|
|
store->SetUid(HALSIM_RegisterDriverStationEnabledCallback(
|
|
|
|
|
&CallbackStoreThunk, store.get(), initialNotify));
|
2018-05-16 19:45:46 -07:00
|
|
|
return store;
|
2018-05-11 12:38:23 -07:00
|
|
|
}
|
2018-08-16 01:17:59 -04:00
|
|
|
|
2020-07-04 10:10:43 -07:00
|
|
|
static bool GetEnabled() { return HALSIM_GetDriverStationEnabled(); }
|
2018-08-16 01:17:59 -04:00
|
|
|
|
2020-07-04 10:10:43 -07:00
|
|
|
static void SetEnabled(bool enabled) {
|
|
|
|
|
HALSIM_SetDriverStationEnabled(enabled);
|
|
|
|
|
}
|
2018-05-11 12:38:23 -07:00
|
|
|
|
2020-07-04 10:10:43 -07:00
|
|
|
static std::unique_ptr<CallbackStore> RegisterAutonomousCallback(
|
2018-05-11 12:38:23 -07:00
|
|
|
NotifyCallback callback, bool initialNotify) {
|
|
|
|
|
auto store = std::make_unique<CallbackStore>(
|
|
|
|
|
-1, callback, &HALSIM_CancelDriverStationAutonomousCallback);
|
|
|
|
|
store->SetUid(HALSIM_RegisterDriverStationAutonomousCallback(
|
|
|
|
|
&CallbackStoreThunk, store.get(), initialNotify));
|
2018-05-16 19:45:46 -07:00
|
|
|
return store;
|
2018-05-11 12:38:23 -07:00
|
|
|
}
|
2018-08-16 01:17:59 -04:00
|
|
|
|
2020-07-04 10:10:43 -07:00
|
|
|
static bool GetAutonomous() { return HALSIM_GetDriverStationAutonomous(); }
|
2018-08-16 01:17:59 -04:00
|
|
|
|
2020-07-04 10:10:43 -07:00
|
|
|
static void SetAutonomous(bool autonomous) {
|
2018-05-11 12:38:23 -07:00
|
|
|
HALSIM_SetDriverStationAutonomous(autonomous);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-04 10:10:43 -07:00
|
|
|
static std::unique_ptr<CallbackStore> RegisterTestCallback(
|
|
|
|
|
NotifyCallback callback, bool initialNotify) {
|
2018-05-11 12:38:23 -07:00
|
|
|
auto store = std::make_unique<CallbackStore>(
|
|
|
|
|
-1, callback, &HALSIM_CancelDriverStationTestCallback);
|
|
|
|
|
store->SetUid(HALSIM_RegisterDriverStationTestCallback(
|
|
|
|
|
&CallbackStoreThunk, store.get(), initialNotify));
|
2018-05-16 19:45:46 -07:00
|
|
|
return store;
|
2018-05-11 12:38:23 -07:00
|
|
|
}
|
2018-08-16 01:17:59 -04:00
|
|
|
|
2020-07-04 10:10:43 -07:00
|
|
|
static bool GetTest() { return HALSIM_GetDriverStationTest(); }
|
2018-08-16 01:17:59 -04:00
|
|
|
|
2020-07-04 10:10:43 -07:00
|
|
|
static void SetTest(bool test) { HALSIM_SetDriverStationTest(test); }
|
2018-05-11 12:38:23 -07:00
|
|
|
|
2020-07-04 10:10:43 -07:00
|
|
|
static std::unique_ptr<CallbackStore> RegisterEStopCallback(
|
|
|
|
|
NotifyCallback callback, bool initialNotify) {
|
2018-05-11 12:38:23 -07:00
|
|
|
auto store = std::make_unique<CallbackStore>(
|
|
|
|
|
-1, callback, &HALSIM_CancelDriverStationEStopCallback);
|
|
|
|
|
store->SetUid(HALSIM_RegisterDriverStationEStopCallback(
|
|
|
|
|
&CallbackStoreThunk, store.get(), initialNotify));
|
2018-05-16 19:45:46 -07:00
|
|
|
return store;
|
2018-05-11 12:38:23 -07:00
|
|
|
}
|
2018-08-16 01:17:59 -04:00
|
|
|
|
2020-07-04 10:10:43 -07:00
|
|
|
static bool GetEStop() { return HALSIM_GetDriverStationEStop(); }
|
2018-08-16 01:17:59 -04:00
|
|
|
|
2020-07-04 10:10:43 -07:00
|
|
|
static void SetEStop(bool eStop) { HALSIM_SetDriverStationEStop(eStop); }
|
2018-05-11 12:38:23 -07:00
|
|
|
|
2020-07-04 10:10:43 -07:00
|
|
|
static std::unique_ptr<CallbackStore> RegisterFmsAttachedCallback(
|
2018-05-11 12:38:23 -07:00
|
|
|
NotifyCallback callback, bool initialNotify) {
|
|
|
|
|
auto store = std::make_unique<CallbackStore>(
|
|
|
|
|
-1, callback, &HALSIM_CancelDriverStationFmsAttachedCallback);
|
|
|
|
|
store->SetUid(HALSIM_RegisterDriverStationFmsAttachedCallback(
|
|
|
|
|
&CallbackStoreThunk, store.get(), initialNotify));
|
2018-05-16 19:45:46 -07:00
|
|
|
return store;
|
2018-05-11 12:38:23 -07:00
|
|
|
}
|
2018-08-16 01:17:59 -04:00
|
|
|
|
2020-07-04 10:10:43 -07:00
|
|
|
static bool GetFmsAttached() { return HALSIM_GetDriverStationFmsAttached(); }
|
2018-08-16 01:17:59 -04:00
|
|
|
|
2020-07-04 10:10:43 -07:00
|
|
|
static void SetFmsAttached(bool fmsAttached) {
|
2018-05-11 12:38:23 -07:00
|
|
|
HALSIM_SetDriverStationFmsAttached(fmsAttached);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-04 10:10:43 -07:00
|
|
|
static std::unique_ptr<CallbackStore> RegisterDsAttachedCallback(
|
2018-05-11 12:38:23 -07:00
|
|
|
NotifyCallback callback, bool initialNotify) {
|
|
|
|
|
auto store = std::make_unique<CallbackStore>(
|
|
|
|
|
-1, callback, &HALSIM_CancelDriverStationDsAttachedCallback);
|
|
|
|
|
store->SetUid(HALSIM_RegisterDriverStationDsAttachedCallback(
|
|
|
|
|
&CallbackStoreThunk, store.get(), initialNotify));
|
2018-05-16 19:45:46 -07:00
|
|
|
return store;
|
2018-05-11 12:38:23 -07:00
|
|
|
}
|
2018-08-16 01:17:59 -04:00
|
|
|
|
2020-07-04 10:10:43 -07:00
|
|
|
static bool GetDsAttached() { return HALSIM_GetDriverStationDsAttached(); }
|
2018-08-16 01:17:59 -04:00
|
|
|
|
2020-07-04 10:10:43 -07:00
|
|
|
static void SetDsAttached(bool dsAttached) {
|
2018-05-11 12:38:23 -07:00
|
|
|
HALSIM_SetDriverStationDsAttached(dsAttached);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-04 10:10:43 -07:00
|
|
|
static void NotifyNewData() { HALSIM_NotifyDriverStationNewData(); }
|
2019-01-09 23:47:42 -08:00
|
|
|
|
2020-07-04 10:10:43 -07:00
|
|
|
static void ResetData() { HALSIM_ResetDriverStationData(); }
|
2018-05-11 12:38:23 -07:00
|
|
|
};
|
|
|
|
|
} // namespace sim
|
|
|
|
|
} // namespace frc
|