[hal] Rename PowerDistributionPanel to PowerDistribution (#3466)

Makes HAL more generic for the PDP, to enable the Rev PDH in the future.
This commit is contained in:
Thad House
2021-08-04 20:31:17 -07:00
committed by GitHub
parent 2014115bca
commit 1ac73a247e
50 changed files with 1612 additions and 1177 deletions

View File

@@ -1,67 +0,0 @@
// 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.
#include "../PortsInternal.h"
#include "PDPDataInternal.h"
using namespace hal;
namespace hal::init {
void InitializePDPData() {
static PDPData spd[kNumPDPModules];
::hal::SimPDPData = spd;
}
} // namespace hal::init
PDPData* hal::SimPDPData;
void PDPData::ResetData() {
initialized.Reset(false);
temperature.Reset(0.0);
voltage.Reset(12.0);
for (int i = 0; i < kNumPDPChannels; i++) {
current[i].Reset(0.0);
}
}
extern "C" {
void HALSIM_ResetPDPData(int32_t index) {
SimPDPData[index].ResetData();
}
#define DEFINE_CAPI(TYPE, CAPINAME, LOWERNAME) \
HAL_SIMDATAVALUE_DEFINE_CAPI(TYPE, HALSIM, PDP##CAPINAME, SimPDPData, \
LOWERNAME)
DEFINE_CAPI(HAL_Bool, Initialized, initialized)
DEFINE_CAPI(double, Temperature, temperature)
DEFINE_CAPI(double, Voltage, voltage)
HAL_SIMDATAVALUE_DEFINE_CAPI_CHANNEL(double, HALSIM, PDPCurrent, SimPDPData,
current)
void HALSIM_GetPDPAllCurrents(int32_t index, double* currents) {
auto& data = SimPDPData[index].current;
for (int i = 0; i < kNumPDPChannels; i++) {
currents[i] = data[i];
}
}
void HALSIM_SetPDPAllCurrents(int32_t index, const double* currents) {
auto& data = SimPDPData[index].current;
for (int i = 0; i < kNumPDPChannels; i++) {
data[i] = currents[i];
}
}
#define REGISTER(NAME) \
SimPDPData[index].NAME.RegisterCallback(callback, param, initialNotify)
void HALSIM_RegisterPDPAllNonCurrentCallbacks(int32_t index, int32_t channel,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
REGISTER(initialized);
REGISTER(temperature);
REGISTER(voltage);
}
} // extern "C"

View File

@@ -0,0 +1,68 @@
// 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.
#include "../PortsInternal.h"
#include "PowerDistributionDataInternal.h"
using namespace hal;
namespace hal::init {
void InitializePowerDistributionData() {
static PowerDistributionData spd[kNumPDPChannels];
::hal::SimPowerDistributionData = spd;
}
} // namespace hal::init
PowerDistributionData* hal::SimPowerDistributionData;
void PowerDistributionData::ResetData() {
initialized.Reset(false);
temperature.Reset(0.0);
voltage.Reset(12.0);
for (int i = 0; i < kNumPDPChannels; i++) {
current[i].Reset(0.0);
}
}
extern "C" {
void HALSIM_ResetPowerDistributionData(int32_t index) {
SimPowerDistributionData[index].ResetData();
}
#define DEFINE_CAPI(TYPE, CAPINAME, LOWERNAME) \
HAL_SIMDATAVALUE_DEFINE_CAPI(TYPE, HALSIM, PowerDistribution##CAPINAME, \
SimPowerDistributionData, LOWERNAME)
DEFINE_CAPI(HAL_Bool, Initialized, initialized)
DEFINE_CAPI(double, Temperature, temperature)
DEFINE_CAPI(double, Voltage, voltage)
HAL_SIMDATAVALUE_DEFINE_CAPI_CHANNEL(double, HALSIM, PowerDistributionCurrent,
SimPowerDistributionData, current)
void HALSIM_GetPowerDistributionAllCurrents(int32_t index, double* currents) {
auto& data = SimPowerDistributionData[index].current;
for (int i = 0; i < kNumPDPChannels; i++) {
currents[i] = data[i];
}
}
void HALSIM_SetPowerDistributionAllCurrents(int32_t index,
const double* currents) {
auto& data = SimPowerDistributionData[index].current;
for (int i = 0; i < kNumPDPChannels; i++) {
data[i] = currents[i];
}
}
#define REGISTER(NAME) \
SimPowerDistributionData[index].NAME.RegisterCallback(callback, param, \
initialNotify)
void HALSIM_RegisterPowerDistributionAllNonCurrentCallbacks(
int32_t index, int32_t channel, HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify) {
REGISTER(initialized);
REGISTER(temperature);
REGISTER(voltage);
}
} // extern "C"

View File

@@ -5,11 +5,11 @@
#pragma once
#include "../PortsInternal.h"
#include "hal/simulation/PDPData.h"
#include "hal/simulation/PowerDistributionData.h"
#include "hal/simulation/SimDataValue.h"
namespace hal {
class PDPData {
class PowerDistributionData {
HAL_SIMDATAVALUE_DEFINE_NAME(Initialized)
HAL_SIMDATAVALUE_DEFINE_NAME(Temperature)
HAL_SIMDATAVALUE_DEFINE_NAME(Voltage)
@@ -29,5 +29,5 @@ class PDPData {
virtual void ResetData();
};
extern PDPData* SimPDPData;
extern PowerDistributionData* SimPowerDistributionData;
} // namespace hal