Implement DriverStation::GetBatteryVoltage

Make the GetBatteryVoltage method work using the new tPower header

Change-Id: If504f8a46f3f7f737f0b729b72fc6b5da0d29ff9
This commit is contained in:
Thomas Clark
2014-08-08 14:56:22 -04:00
parent f4d542b212
commit d2cd5f3571
8 changed files with 217 additions and 6 deletions

View File

@@ -6,6 +6,7 @@
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj;
import java.nio.IntBuffer;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
@@ -13,6 +14,7 @@ import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary;
import edu.wpi.first.wpilibj.communication.HALControlWord;
import edu.wpi.first.wpilibj.communication.HALAllianceStationID;
import edu.wpi.first.wpilibj.hal.HALUtil;
import edu.wpi.first.wpilibj.hal.PowerJNI;
import edu.wpi.first.wpilibj.Timer;
/**
@@ -95,10 +97,7 @@ public class DriverStation implements RobotState.Interface {
m_semaphore = new Object();
m_dataSem = new Object();
m_packetDataAvailableSem = ByteBuffer.allocateDirect(4);
// set the byte order
m_packetDataAvailableSem.order(ByteOrder.LITTLE_ENDIAN);
m_packetDataAvailableSem = HALUtil.initializeMutexNormal();
FRCNetworkCommunicationsLibrary.setNewDataSem(m_packetDataAvailableSem);
m_thread = new Thread(new DriverStationTask(this), "FRCDriverStation");
@@ -209,7 +208,11 @@ public class DriverStation implements RobotState.Interface {
* @return The battery voltage.
*/
public double getBatteryVoltage() {
return 0.0; // TODO
IntBuffer status = ByteBuffer.allocateDirect(4).asIntBuffer();
float voltage = PowerJNI.getVinVoltage(status);
HALUtil.checkStatus(status);
return voltage;
}
/**

View File

@@ -0,0 +1,14 @@
package edu.wpi.first.wpilibj.hal;
import java.nio.IntBuffer;
public class PowerJNI extends JNIWrapper {
public static native float getVinVoltage(IntBuffer status);
public static native float getVinCurrent(IntBuffer status);
public static native float getUserVoltage6V(IntBuffer status);
public static native float getUserCurrent6V(IntBuffer status);
public static native float getUserVoltage5V(IntBuffer status);
public static native float getUserCurrent5V(IntBuffer status);
public static native float getUserVoltage3V3(IntBuffer status);
public static native float getUserCurrent3V3(IntBuffer status);
}