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-08-20 01:14:03 -04:00
|
|
|
|
|
|
|
|
#include "HALSimWSClient.h"
|
|
|
|
|
|
2024-09-20 17:43:39 -07:00
|
|
|
#include <memory>
|
|
|
|
|
|
2020-09-04 10:57:05 -07:00
|
|
|
#include <WSProviderContainer.h>
|
2020-12-31 20:34:34 -08:00
|
|
|
#include <WSProvider_AddressableLED.h>
|
2020-09-04 10:57:05 -07:00
|
|
|
#include <WSProvider_Analog.h>
|
2020-12-23 15:54:11 -08:00
|
|
|
#include <WSProvider_BuiltInAccelerometer.h>
|
2020-09-04 10:57:05 -07:00
|
|
|
#include <WSProvider_DIO.h>
|
|
|
|
|
#include <WSProvider_DriverStation.h>
|
|
|
|
|
#include <WSProvider_Encoder.h>
|
|
|
|
|
#include <WSProvider_Joystick.h>
|
2020-12-31 20:34:34 -08:00
|
|
|
#include <WSProvider_PCM.h>
|
2020-09-04 10:57:05 -07:00
|
|
|
#include <WSProvider_PWM.h>
|
|
|
|
|
#include <WSProvider_RoboRIO.h>
|
|
|
|
|
#include <WSProvider_SimDevice.h>
|
2020-12-31 20:34:34 -08:00
|
|
|
#include <WSProvider_Solenoid.h>
|
2020-09-04 10:57:05 -07:00
|
|
|
#include <WSProvider_dPWM.h>
|
2022-05-07 10:54:14 -07:00
|
|
|
#include <wpinet/EventLoopRunner.h>
|
2020-09-04 10:57:05 -07:00
|
|
|
|
|
|
|
|
using namespace wpilibws;
|
|
|
|
|
|
|
|
|
|
bool HALSimWSClient::Initialize() {
|
|
|
|
|
bool result = true;
|
|
|
|
|
runner.ExecSync([&](wpi::uv::Loop& loop) {
|
|
|
|
|
simws = std::make_shared<HALSimWS>(loop, providers, simDevices);
|
|
|
|
|
|
|
|
|
|
if (!simws->Initialize()) {
|
|
|
|
|
result = false;
|
|
|
|
|
return;
|
2020-08-20 01:14:03 -04:00
|
|
|
}
|
|
|
|
|
|
2020-09-04 10:57:05 -07:00
|
|
|
WSRegisterFunc registerFunc = [&](auto key, auto provider) {
|
|
|
|
|
providers.Add(key, provider);
|
|
|
|
|
};
|
2020-08-20 01:14:03 -04:00
|
|
|
|
2020-12-31 20:34:34 -08:00
|
|
|
HALSimWSProviderAddressableLED::Initialize(registerFunc);
|
2020-09-04 10:57:05 -07:00
|
|
|
HALSimWSProviderAnalogIn::Initialize(registerFunc);
|
|
|
|
|
HALSimWSProviderAnalogOut::Initialize(registerFunc);
|
2020-12-23 15:54:11 -08:00
|
|
|
HALSimWSProviderBuiltInAccelerometer::Initialize(registerFunc);
|
2020-09-04 10:57:05 -07:00
|
|
|
HALSimWSProviderDIO::Initialize(registerFunc);
|
|
|
|
|
HALSimWSProviderDigitalPWM::Initialize(registerFunc);
|
|
|
|
|
HALSimWSProviderDriverStation::Initialize(registerFunc);
|
|
|
|
|
HALSimWSProviderEncoder::Initialize(registerFunc);
|
|
|
|
|
HALSimWSProviderJoystick::Initialize(registerFunc);
|
2020-12-31 20:34:34 -08:00
|
|
|
HALSimWSProviderPCM::Initialize(registerFunc);
|
2020-09-04 10:57:05 -07:00
|
|
|
HALSimWSProviderPWM::Initialize(registerFunc);
|
|
|
|
|
HALSimWSProviderRoboRIO::Initialize(registerFunc);
|
2020-12-31 20:34:34 -08:00
|
|
|
HALSimWSProviderSolenoid::Initialize(registerFunc);
|
2020-08-20 01:14:03 -04:00
|
|
|
|
2020-09-04 10:57:05 -07:00
|
|
|
simDevices.Initialize(loop);
|
2020-08-20 01:14:03 -04:00
|
|
|
|
2020-09-04 10:57:05 -07:00
|
|
|
simws->Start();
|
2020-08-20 01:14:03 -04:00
|
|
|
});
|
|
|
|
|
|
2020-09-04 10:57:05 -07:00
|
|
|
return result;
|
2020-08-20 01:14:03 -04:00
|
|
|
}
|