mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-26 01:51:41 +00:00
Compare commits
98 Commits
v2020.1.1-
...
v2020.1.1-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b058dcf64e | ||
|
|
0b9307fdf3 | ||
|
|
39be812b2e | ||
|
|
21e957ee42 | ||
|
|
e0bc97f66b | ||
|
|
3df44c874d | ||
|
|
a58dbec8aa | ||
|
|
9a8067465c | ||
|
|
ffa4b907c0 | ||
|
|
3d1ca856b2 | ||
|
|
5f85457a97 | ||
|
|
4ebae17123 | ||
|
|
fa85fbfc1c | ||
|
|
f62e23f1af | ||
|
|
5443fdabc1 | ||
|
|
c0e36df9d8 | ||
|
|
8c4d9f5415 | ||
|
|
45201d15fc | ||
|
|
845aba33fe | ||
|
|
500c43fb84 | ||
|
|
5891628112 | ||
|
|
b37b68daaf | ||
|
|
0e83c65d27 | ||
|
|
6f6c6da9f5 | ||
|
|
1894219ef6 | ||
|
|
77a9949bbf | ||
|
|
a4c9e4ec28 | ||
|
|
8ed2059074 | ||
|
|
59507b12dc | ||
|
|
5d39bf8065 | ||
|
|
841ef91c0f | ||
|
|
1b66ead49d | ||
|
|
db2c3dddd7 | ||
|
|
82b2170feb | ||
|
|
8280b7e3af | ||
|
|
5510960068 | ||
|
|
df10652183 | ||
|
|
bf5388393e | ||
|
|
b7bc1ea745 | ||
|
|
708009cd20 | ||
|
|
3cce61b89f | ||
|
|
565e1f3e79 | ||
|
|
1853f7b6b7 | ||
|
|
c5a0497124 | ||
|
|
f5446c7409 | ||
|
|
3e049e02f0 | ||
|
|
2da64d15f6 | ||
|
|
f04d95e50f | ||
|
|
d748c67a54 | ||
|
|
55a7f2b4ad | ||
|
|
486fa9c696 | ||
|
|
e3dd1c5d77 | ||
|
|
7dc7c71b58 | ||
|
|
5f33d6af12 | ||
|
|
94843adb8f | ||
|
|
9bcff37b93 | ||
|
|
326aecc9a0 | ||
|
|
00228678d4 | ||
|
|
ff39a96cee | ||
|
|
5ccad2e8a4 | ||
|
|
629e95776a | ||
|
|
6858a57f72 | ||
|
|
0ebe32823a | ||
|
|
384d00f9e6 | ||
|
|
1f6850adf2 | ||
|
|
7508aada93 | ||
|
|
f5b4be16db | ||
|
|
e6f5c93ab1 | ||
|
|
39f46ceab6 | ||
|
|
d93aa2b6b2 | ||
|
|
114ddaf81f | ||
|
|
f22d0961e3 | ||
|
|
3262c2badb | ||
|
|
96d40192ae | ||
|
|
ed30d5d40e | ||
|
|
2b6811eddb | ||
|
|
1d695a1660 | ||
|
|
509819d83f | ||
|
|
2ad15cae19 | ||
|
|
931b8ceefd | ||
|
|
0b3821eba3 | ||
|
|
6f159d1426 | ||
|
|
a769f1f227 | ||
|
|
c5186d8159 | ||
|
|
9ebd23d61e | ||
|
|
f6e311ef86 | ||
|
|
f33bd9f050 | ||
|
|
1c1e0c9a6a | ||
|
|
ea9bb651a3 | ||
|
|
cc07425182 | ||
|
|
16b34cce20 | ||
|
|
669127e49c | ||
|
|
9dc30797e4 | ||
|
|
f6b844ea30 | ||
|
|
a72f809911 | ||
|
|
916596cb01 | ||
|
|
5509a8e968 | ||
|
|
0be6b64756 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,6 +3,7 @@
|
||||
dependency-reduced-pom.xml
|
||||
doxygen.log
|
||||
build*/
|
||||
!buildSrc/
|
||||
|
||||
# Created by the jenkins test script
|
||||
test-reports
|
||||
|
||||
@@ -9,18 +9,10 @@ cppSrcFileInclude {
|
||||
}
|
||||
|
||||
generatedFileExclude {
|
||||
gtest/
|
||||
ni-libraries/include/
|
||||
ni-libraries/lib/
|
||||
FRCNetComm\.java$
|
||||
simulation/frc_gazebo_plugins/frcgazebo/
|
||||
simulation/gz_msgs/src/include/simulation/gz_msgs/msgs\.h$
|
||||
}
|
||||
|
||||
modifiableFileExclude {
|
||||
\.so$
|
||||
}
|
||||
|
||||
repoRootNameOverride {
|
||||
wpilib
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"enableCppIntellisense": true,
|
||||
"currentLanguage": "cpp",
|
||||
"projectYear": "2019",
|
||||
"projectYear": "Beta2020",
|
||||
"teamNumber": 0
|
||||
}
|
||||
|
||||
17
build.gradle
17
build.gradle
@@ -3,15 +3,14 @@ import edu.wpi.first.toolchain.*
|
||||
plugins {
|
||||
id 'base'
|
||||
id 'edu.wpi.first.wpilib.versioning.WPILibVersioningPlugin' version '4.0.1'
|
||||
id 'edu.wpi.first.wpilib.repositories.WPILibRepositoriesPlugin' version '2020.1'
|
||||
id 'edu.wpi.first.wpilib.repositories.WPILibRepositoriesPlugin' version '2020.2'
|
||||
id 'edu.wpi.first.NativeUtils' apply false
|
||||
id 'edu.wpi.first.GradleJni' version '0.9.1'
|
||||
id 'edu.wpi.first.GradleVsCode' version '0.9.4'
|
||||
id 'edu.wpi.first.GradleJni' version '0.10.1'
|
||||
id 'edu.wpi.first.GradleVsCode' version '0.10.0'
|
||||
id 'idea'
|
||||
id 'visual-studio'
|
||||
id 'com.gradle.build-scan' version '2.3'
|
||||
id 'net.ltgt.errorprone' version '0.6' apply false
|
||||
id 'com.github.johnrengelman.shadow' version '4.0.3' apply false
|
||||
id 'net.ltgt.errorprone' version '1.1.1' apply false
|
||||
id 'com.github.johnrengelman.shadow' version '5.2.0' apply false
|
||||
}
|
||||
|
||||
if (project.hasProperty('buildServer')) {
|
||||
@@ -99,7 +98,9 @@ subprojects {
|
||||
// Disables doclint in java 8.
|
||||
if (JavaVersion.current().isJava8Compatible()) {
|
||||
tasks.withType(Javadoc) {
|
||||
options.addStringOption('Xdoclint:none', '-quiet')
|
||||
if (project.name != "docs") {
|
||||
options.addStringOption('Xdoclint:none', '-quiet')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -109,5 +110,5 @@ ext.getCurrentArch = {
|
||||
}
|
||||
|
||||
wrapper {
|
||||
gradleVersion = '5.4.1'
|
||||
gradleVersion = '6.0'
|
||||
}
|
||||
|
||||
@@ -5,5 +5,5 @@ repositories {
|
||||
}
|
||||
}
|
||||
dependencies {
|
||||
compile "edu.wpi.first:native-utils:2020.1.4"
|
||||
implementation "edu.wpi.first:native-utils:2020.5.2"
|
||||
}
|
||||
|
||||
48
buildSrc/src/main/groovy/JREArtifact.groovy
Normal file
48
buildSrc/src/main/groovy/JREArtifact.groovy
Normal file
@@ -0,0 +1,48 @@
|
||||
import groovy.transform.CompileStatic
|
||||
import javax.inject.Inject
|
||||
import jaci.gradle.deploy.artifact.MavenArtifact
|
||||
import jaci.gradle.deploy.context.DeployContext
|
||||
import org.gradle.api.Project
|
||||
import jaci.gradle.ActionWrapper
|
||||
|
||||
import java.util.function.Function
|
||||
|
||||
@CompileStatic
|
||||
class JREArtifact extends MavenArtifact {
|
||||
Function<DeployContext, Boolean> buildRequiresJre = (Function<DeployContext, Boolean>){ true }
|
||||
|
||||
void setJreDependency(String dep) {
|
||||
dependency = project.dependencies.add(configuration(), dep)
|
||||
}
|
||||
|
||||
@Inject
|
||||
JREArtifact(String name, Project project) {
|
||||
super(name, project)
|
||||
configuration = project.configurations.create(configuration())
|
||||
|
||||
onlyIf = { DeployContext ctx ->
|
||||
(buildRequiresJre.apply(ctx) && jreMissing(ctx)) || project.hasProperty("force-redeploy-jre")
|
||||
}
|
||||
|
||||
predeploy << new ActionWrapper({ DeployContext ctx ->
|
||||
ctx.logger.log('Deploying RoboRIO JRE (this will take a while)...')
|
||||
})
|
||||
|
||||
directory = '/tmp'
|
||||
filename = 'frcjre.ipk'
|
||||
|
||||
postdeploy << new ActionWrapper({ DeployContext ctx ->
|
||||
ctx.logger.log('Installing JRE...')
|
||||
ctx.execute('opkg remove frc2020-openjdk*; opkg install /tmp/frcjre.ipk; rm /tmp/frcjre.ipk')
|
||||
ctx.logger.log('JRE Deployed!')
|
||||
})
|
||||
}
|
||||
|
||||
String configuration() {
|
||||
return name + 'frcjre'
|
||||
}
|
||||
|
||||
boolean jreMissing(DeployContext ctx) {
|
||||
return ctx.execute('if [[ -f "/usr/local/frc/JRE/bin/java" ]]; then echo OK; else echo MISSING; fi').result.contains("MISSING")
|
||||
}
|
||||
}
|
||||
@@ -7,16 +7,12 @@ cppSrcFileInclude {
|
||||
\.cpp$
|
||||
}
|
||||
|
||||
modifiableFileExclude {
|
||||
\.so$
|
||||
}
|
||||
|
||||
repoRootNameOverride {
|
||||
cameraserver
|
||||
}
|
||||
|
||||
includeOtherLibs {
|
||||
^HAL/
|
||||
^hal/
|
||||
^networktables/
|
||||
^opencv2/
|
||||
^support/
|
||||
|
||||
@@ -10,12 +10,12 @@ evaluationDependsOn(':hal')
|
||||
apply from: "${rootDir}/shared/javacpp/setupBuild.gradle"
|
||||
|
||||
dependencies {
|
||||
compile project(':wpiutil')
|
||||
compile project(':ntcore')
|
||||
compile project(':cscore')
|
||||
devCompile project(':wpiutil')
|
||||
devCompile project(':ntcore')
|
||||
devCompile project(':cscore')
|
||||
implementation project(':wpiutil')
|
||||
implementation project(':ntcore')
|
||||
implementation project(':cscore')
|
||||
devImplementation project(':wpiutil')
|
||||
devImplementation project(':ntcore')
|
||||
devImplementation project(':cscore')
|
||||
}
|
||||
|
||||
ext {
|
||||
|
||||
@@ -27,12 +27,12 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile 'com.google.code.gson:gson:2.8.5'
|
||||
implementation 'com.google.code.gson:gson:2.8.5'
|
||||
|
||||
compile project(':wpiutil')
|
||||
compile project(':ntcore')
|
||||
compile project(':cscore')
|
||||
compile project(':cameraserver')
|
||||
implementation project(':wpiutil')
|
||||
implementation project(':ntcore')
|
||||
implementation project(':cscore')
|
||||
implementation project(':cameraserver')
|
||||
}
|
||||
|
||||
model {
|
||||
|
||||
@@ -19,7 +19,8 @@ ext {
|
||||
sharedCvConfigs = [cscore : [],
|
||||
cscoreBase: [],
|
||||
cscoreDev : [],
|
||||
cscoreTest: []]
|
||||
cscoreTest: [],
|
||||
cscoreJNIShared: []]
|
||||
staticCvConfigs = [cscoreJNI: []]
|
||||
useJava = true
|
||||
useCpp = true
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include <exception>
|
||||
|
||||
#include <opencv2/core/core.hpp>
|
||||
#include <wpi/SmallString.h>
|
||||
#include <wpi/jni_util.h>
|
||||
#include <wpi/raw_ostream.h>
|
||||
@@ -33,6 +36,7 @@ static JClass rawFrameCls;
|
||||
static JException videoEx;
|
||||
static JException nullPointerEx;
|
||||
static JException unsupportedEx;
|
||||
static JException exceptionEx;
|
||||
// Thread-attached environment for listener callbacks.
|
||||
static JNIEnv* listenerEnv = nullptr;
|
||||
|
||||
@@ -45,7 +49,8 @@ static const JClassInit classes[] = {
|
||||
static const JExceptionInit exceptions[] = {
|
||||
{"edu/wpi/cscore/VideoException", &videoEx},
|
||||
{"java/lang/NullPointerException", &nullPointerEx},
|
||||
{"java/lang/UnsupportedOperationException", &unsupportedEx}};
|
||||
{"java/lang/UnsupportedOperationException", &unsupportedEx},
|
||||
{"java/lang/Exception", &exceptionEx}};
|
||||
|
||||
static void ListenerOnStart() {
|
||||
if (!jvm) return;
|
||||
@@ -67,6 +72,30 @@ static void ListenerOnExit() {
|
||||
jvm->DetachCurrentThread();
|
||||
}
|
||||
|
||||
/// throw java exception
|
||||
static void ThrowJavaException(JNIEnv* env, const std::exception* e) {
|
||||
wpi::SmallString<128> what;
|
||||
jclass je = 0;
|
||||
|
||||
if (e) {
|
||||
const char* exception_type = "std::exception";
|
||||
|
||||
if (dynamic_cast<const cv::Exception*>(e)) {
|
||||
exception_type = "cv::Exception";
|
||||
je = env->FindClass("org/opencv/core/CvException");
|
||||
}
|
||||
|
||||
what = exception_type;
|
||||
what += ": ";
|
||||
what += e->what();
|
||||
} else {
|
||||
what = "unknown exception";
|
||||
}
|
||||
|
||||
if (!je) je = exceptionEx;
|
||||
env->ThrowNew(je, what.c_str());
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
||||
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) {
|
||||
@@ -1096,10 +1125,16 @@ JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_cscore_CameraServerCvJNI_putSourceFrame
|
||||
(JNIEnv* env, jclass, jint source, jlong imageNativeObj)
|
||||
{
|
||||
cv::Mat& image = *((cv::Mat*)imageNativeObj);
|
||||
CS_Status status = 0;
|
||||
cs::PutSourceFrame(source, image, &status);
|
||||
CheckStatus(env, status);
|
||||
try {
|
||||
cv::Mat& image = *((cv::Mat*)imageNativeObj);
|
||||
CS_Status status = 0;
|
||||
cs::PutSourceFrame(source, image, &status);
|
||||
CheckStatus(env, status);
|
||||
} catch (const std::exception& e) {
|
||||
ThrowJavaException(env, &e);
|
||||
} catch (...) {
|
||||
ThrowJavaException(env, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// int width, int height, int pixelFormat, int totalData
|
||||
@@ -1555,11 +1590,19 @@ JNIEXPORT jlong JNICALL
|
||||
Java_edu_wpi_cscore_CameraServerCvJNI_grabSinkFrame
|
||||
(JNIEnv* env, jclass, jint sink, jlong imageNativeObj)
|
||||
{
|
||||
cv::Mat& image = *((cv::Mat*)imageNativeObj);
|
||||
CS_Status status = 0;
|
||||
auto rv = cs::GrabSinkFrame(sink, image, &status);
|
||||
CheckStatus(env, status);
|
||||
return rv;
|
||||
try {
|
||||
cv::Mat& image = *((cv::Mat*)imageNativeObj);
|
||||
CS_Status status = 0;
|
||||
auto rv = cs::GrabSinkFrame(sink, image, &status);
|
||||
CheckStatus(env, status);
|
||||
return rv;
|
||||
} catch (const std::exception& e) {
|
||||
ThrowJavaException(env, &e);
|
||||
return 0;
|
||||
} catch (...) {
|
||||
ThrowJavaException(env, 0);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1571,11 +1614,19 @@ JNIEXPORT jlong JNICALL
|
||||
Java_edu_wpi_cscore_CameraServerCvJNI_grabSinkFrameTimeout
|
||||
(JNIEnv* env, jclass, jint sink, jlong imageNativeObj, jdouble timeout)
|
||||
{
|
||||
cv::Mat& image = *((cv::Mat*)imageNativeObj);
|
||||
CS_Status status = 0;
|
||||
auto rv = cs::GrabSinkFrameTimeout(sink, image, timeout, &status);
|
||||
CheckStatus(env, status);
|
||||
return rv;
|
||||
try {
|
||||
cv::Mat& image = *((cv::Mat*)imageNativeObj);
|
||||
CS_Status status = 0;
|
||||
auto rv = cs::GrabSinkFrameTimeout(sink, image, timeout, &status);
|
||||
CheckStatus(env, status);
|
||||
return rv;
|
||||
} catch (const std::exception& e) {
|
||||
ThrowJavaException(env, &e);
|
||||
return 0;
|
||||
} catch (...) {
|
||||
ThrowJavaException(env, 0);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void SetRawFrameData(JNIEnv* env, jobject rawFrameObj,
|
||||
|
||||
@@ -10,6 +10,8 @@ evaluationDependsOn(':hal')
|
||||
evaluationDependsOn(':cameraserver')
|
||||
evaluationDependsOn(':wpilibc')
|
||||
evaluationDependsOn(':wpilibj')
|
||||
evaluationDependsOn(':wpilibOldCommands')
|
||||
evaluationDependsOn(':wpilibNewCommands')
|
||||
|
||||
def baseArtifactIdCpp = 'documentation'
|
||||
def artifactGroupIdCpp = 'edu.wpi.first.wpilibc'
|
||||
@@ -29,6 +31,8 @@ cppProjectZips.add(project(':ntcore').cppHeadersZip)
|
||||
cppProjectZips.add(project(':cscore').cppHeadersZip)
|
||||
cppProjectZips.add(project(':cameraserver').cppHeadersZip)
|
||||
cppProjectZips.add(project(':wpilibc').cppHeadersZip)
|
||||
cppProjectZips.add(project(':wpilibOldCommands').cppHeadersZip)
|
||||
cppProjectZips.add(project(':wpilibNewCommands').cppHeadersZip)
|
||||
|
||||
doxygen {
|
||||
executables {
|
||||
@@ -71,8 +75,8 @@ doxygen {
|
||||
}
|
||||
|
||||
tasks.register("zipCppDocs", Zip) {
|
||||
baseName = zipBaseNameCpp
|
||||
destinationDir = outputsFolder
|
||||
archiveBaseName = zipBaseNameCpp
|
||||
destinationDirectory = outputsFolder
|
||||
dependsOn doxygen
|
||||
from ("$buildDir/docs/doxygen/html")
|
||||
into '/'
|
||||
@@ -100,7 +104,7 @@ task generateJavaDocs(type: Javadoc) {
|
||||
classpath += project(":wpiutil").sourceSets.main.compileClasspath
|
||||
options.links("https://docs.oracle.com/en/java/javase/11/docs/api/")
|
||||
options.addStringOption "tag", "pre:a:Pre-Condition"
|
||||
options.addStringOption('Xdoclint:accessibility,html,missing,reference,syntax')
|
||||
options.addBooleanOption "Xdoclint:html,missing,reference,syntax", true
|
||||
options.addBooleanOption('html5', true)
|
||||
dependsOn project(':wpilibj').generateJavaVersion
|
||||
dependsOn project(':hal').generateUsageReporting
|
||||
@@ -110,6 +114,8 @@ task generateJavaDocs(type: Javadoc) {
|
||||
source project(':ntcore').sourceSets.main.java
|
||||
source project(':wpilibj').sourceSets.main.java
|
||||
source project(':cameraserver').sourceSets.main.java
|
||||
source project(':wpilibOldCommands').sourceSets.main.java
|
||||
source project(':wpilibNewCommands').sourceSets.main.java
|
||||
source configurations.javaSource.collect { zipTree(it) }
|
||||
include '**/*.java'
|
||||
failOnError = true
|
||||
@@ -130,8 +136,8 @@ task generateJavaDocs(type: Javadoc) {
|
||||
}
|
||||
|
||||
tasks.register("zipJavaDocs", Zip) {
|
||||
baseName = zipBaseNameJava
|
||||
destinationDir = outputsFolder
|
||||
archiveBaseName = zipBaseNameJava
|
||||
destinationDirectory = outputsFolder
|
||||
dependsOn generateJavaDocs
|
||||
from ("$buildDir/docs/javadoc")
|
||||
into '/'
|
||||
|
||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,5 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
||||
35
gradlew
vendored
35
gradlew
vendored
@@ -7,7 +7,7 @@
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -125,8 +125,8 @@ if $darwin; then
|
||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||
fi
|
||||
|
||||
# For Cygwin, switch paths to Windows format before running java
|
||||
if $cygwin ; then
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
@@ -154,19 +154,19 @@ if $cygwin ; then
|
||||
else
|
||||
eval `echo args$i`="\"$arg\""
|
||||
fi
|
||||
i=$((i+1))
|
||||
i=`expr $i + 1`
|
||||
done
|
||||
case $i in
|
||||
(0) set -- ;;
|
||||
(1) set -- "$args0" ;;
|
||||
(2) set -- "$args0" "$args1" ;;
|
||||
(3) set -- "$args0" "$args1" "$args2" ;;
|
||||
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
0) set -- ;;
|
||||
1) set -- "$args0" ;;
|
||||
2) set -- "$args0" "$args1" ;;
|
||||
3) set -- "$args0" "$args1" "$args2" ;;
|
||||
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
@@ -175,14 +175,9 @@ save () {
|
||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||
echo " "
|
||||
}
|
||||
APP_ARGS=$(save "$@")
|
||||
APP_ARGS=`save "$@"`
|
||||
|
||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
||||
|
||||
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
|
||||
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
|
||||
cd "$(dirname "$0")"
|
||||
fi
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
|
||||
2
gradlew.bat
vendored
2
gradlew.bat
vendored
@@ -5,7 +5,7 @@
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem http://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
||||
@@ -185,3 +185,14 @@ nativeUtils.exportsConfigs {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
model {
|
||||
binaries {
|
||||
all {
|
||||
if (!(it instanceof NativeBinarySpec)) return
|
||||
if (it.component.name != 'hal' && it.component.name != 'halBase') return
|
||||
if (it.targetPlatform.name != nativeUtils.wpi.platforms.roborio) return
|
||||
nativeUtils.useRequiredLibrary(it, 'netcomm_shared', 'chipobject_shared')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,54 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// ifdef's definition is to allow for default parameters in C++.
|
||||
#ifdef __cplusplus
|
||||
/**
|
||||
* Reports a hardware usage to the HAL.
|
||||
*
|
||||
* @param resource the used resource
|
||||
* @param instanceNumber the instance of the resource
|
||||
* @param context a user specified context index
|
||||
* @param feature a user specified feature string
|
||||
* @return the index of the added value in NetComm
|
||||
*/
|
||||
int64_t HAL_Report(int32_t resource, int32_t instanceNumber,
|
||||
int32_t context = 0, const char* feature = nullptr);
|
||||
#else
|
||||
|
||||
/**
|
||||
* Reports a hardware usage to the HAL.
|
||||
*
|
||||
* @param resource the used resource
|
||||
* @param instanceNumber the instance of the resource
|
||||
* @param context a user specified context index
|
||||
* @param feature a user specified feature string
|
||||
* @return the index of the added value in NetComm
|
||||
*/
|
||||
int64_t HAL_Report(int32_t resource, int32_t instanceNumber, int32_t context,
|
||||
const char* feature);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Autogenerated file! Do not manually edit this file.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
namespace HALUsageReporting {
|
||||
typedef enum {
|
||||
enum tResourceType : int32_t {
|
||||
${usage_reporting_types_cpp}
|
||||
} tResourceType;
|
||||
typedef enum {
|
||||
};
|
||||
enum tInstances : int32_t {
|
||||
${usage_reporting_instances_cpp}
|
||||
} tInstances;
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -62,7 +62,7 @@ kResourceType_PCM = 60
|
||||
kResourceType_PigeonIMU = 61
|
||||
kResourceType_NidecBrushless = 62
|
||||
kResourceType_CANifier = 63
|
||||
kResourceType_CTRE_future0 = 64
|
||||
kResourceType_TalonFX = 64
|
||||
kResourceType_CTRE_future1 = 65
|
||||
kResourceType_CTRE_future2 = 66
|
||||
kResourceType_CTRE_future3 = 67
|
||||
@@ -83,3 +83,12 @@ kResourceType_PWMVictorSPX = 81
|
||||
kResourceType_RevSparkMaxPWM = 82
|
||||
kResourceType_RevSparkMaxCAN = 83
|
||||
kResourceType_ADIS16470 = 84
|
||||
kResourceType_PIDController2 = 85
|
||||
kResourceType_ProfiledPIDController = 86
|
||||
kResourceType_Kinematics = 87
|
||||
kResourceType_Odometry = 88
|
||||
kResourceType_Units = 89
|
||||
kResourceType_TrapezoidProfile = 90
|
||||
kResourceType_DutyCycle = 91
|
||||
kResourceType_AddressableLEDs = 92
|
||||
kResourceType_FusionVenom = 93
|
||||
|
||||
23
hal/src/main/java/edu/wpi/first/hal/AddressableLEDJNI.java
Normal file
23
hal/src/main/java/edu/wpi/first/hal/AddressableLEDJNI.java
Normal file
@@ -0,0 +1,23 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
package edu.wpi.first.hal;
|
||||
|
||||
@SuppressWarnings("AbbreviationAsWordInName")
|
||||
public class AddressableLEDJNI extends JNIWrapper {
|
||||
public static native int initialize(int pwmHandle);
|
||||
public static native void free(int handle);
|
||||
|
||||
public static native void setLength(int handle, int length);
|
||||
public static native void setData(int handle, byte[] data);
|
||||
|
||||
public static native void setBitTiming(int handle, int lowTime0, int highTime0, int lowTime1, int highTime1);
|
||||
public static native void setSyncTime(int handle, int syncTime);
|
||||
|
||||
public static native void start(int handle);
|
||||
public static native void stop(int handle);
|
||||
}
|
||||
@@ -7,8 +7,6 @@
|
||||
|
||||
package edu.wpi.first.hal;
|
||||
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
public class AnalogJNI extends JNIWrapper {
|
||||
/**
|
||||
* <i>native declaration : AthenaJava\target\native\include\HAL\Analog.h:58</i><br> enum values
|
||||
@@ -94,13 +92,18 @@ public class AnalogJNI extends JNIWrapper {
|
||||
|
||||
public static native void getAccumulatorOutput(int analogPortHandle, AccumulatorResult result);
|
||||
|
||||
public static native int initializeAnalogTrigger(int analogInputHandle, IntBuffer index);
|
||||
public static native int initializeAnalogTrigger(int analogInputHandle);
|
||||
|
||||
public static native int initializeAnalogTriggerDutyCycle(int dutyCycleHandle);
|
||||
|
||||
public static native void cleanAnalogTrigger(int analogTriggerHandle);
|
||||
|
||||
public static native void setAnalogTriggerLimitsRaw(int analogTriggerHandle, int lower,
|
||||
int upper);
|
||||
|
||||
public static native void setAnalogTriggerLimitsDutyCycle(int analogTriggerHandle, double lower,
|
||||
double higher);
|
||||
|
||||
public static native void setAnalogTriggerLimitsVoltage(int analogTriggerHandle,
|
||||
double lower, double upper);
|
||||
|
||||
@@ -115,4 +118,7 @@ public class AnalogJNI extends JNIWrapper {
|
||||
public static native boolean getAnalogTriggerTriggerState(int analogTriggerHandle);
|
||||
|
||||
public static native boolean getAnalogTriggerOutput(int analogTriggerHandle, int type);
|
||||
|
||||
@SuppressWarnings("AbbreviationAsWordInName")
|
||||
public static native int getAnalogTriggerFPGAIndex(int analogTriggerHandle);
|
||||
}
|
||||
|
||||
21
hal/src/main/java/edu/wpi/first/hal/DutyCycleJNI.java
Normal file
21
hal/src/main/java/edu/wpi/first/hal/DutyCycleJNI.java
Normal file
@@ -0,0 +1,21 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
package edu.wpi.first.hal;
|
||||
|
||||
public class DutyCycleJNI extends JNIWrapper {
|
||||
public static native int initialize(int digitalSourceHandle, int analogTriggerType);
|
||||
public static native void free(int handle);
|
||||
|
||||
public static native int getFrequency(int handle);
|
||||
public static native double getOutput(int handle);
|
||||
public static native int getOutputRaw(int handle);
|
||||
public static native int getOutputScaleFactor(int handle);
|
||||
|
||||
@SuppressWarnings("AbbreviationAsWordInName")
|
||||
public static native int getFPGAIndex(int handle);
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
|
||||
/* 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. */
|
||||
@@ -19,6 +19,11 @@ public class NotifierJNI extends JNIWrapper {
|
||||
*/
|
||||
public static native int initializeNotifier();
|
||||
|
||||
/**
|
||||
* Sets the name of the notifier.
|
||||
*/
|
||||
public static native void setNotifierName(int notifierHandle, String name);
|
||||
|
||||
/**
|
||||
* Wakes up the waiter with time=0. Note: after this function is called, all
|
||||
* calls to waitForNotifierAlarm() will immediately start returning 0.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
|
||||
/* 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. */
|
||||
@@ -21,6 +21,8 @@ public class PDPJNI extends JNIWrapper {
|
||||
|
||||
public static native double getPDPChannelCurrent(byte channel, int handle);
|
||||
|
||||
public static native void getPDPAllCurrents(int handle, double[] currents);
|
||||
|
||||
public static native double getPDPTotalCurrent(int handle);
|
||||
|
||||
public static native double getPDPTotalPower(int handle);
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
package edu.wpi.first.hal.sim;
|
||||
|
||||
import edu.wpi.first.hal.sim.mockdata.AddressableLEDDataJNI;
|
||||
|
||||
public class AddressableLEDSim {
|
||||
private final int m_index;
|
||||
|
||||
public AddressableLEDSim(int index) {
|
||||
m_index = index;
|
||||
}
|
||||
|
||||
public CallbackStore registerInitializedCallback(NotifyCallback callback, boolean initialNotify) {
|
||||
int uid = AddressableLEDDataJNI.registerInitializedCallback(m_index, callback, initialNotify);
|
||||
return new CallbackStore(m_index, uid, AddressableLEDDataJNI::cancelInitializedCallback);
|
||||
}
|
||||
public boolean getInitialized() {
|
||||
return AddressableLEDDataJNI.getInitialized(m_index);
|
||||
}
|
||||
public void setInitialized(boolean initialized) {
|
||||
AddressableLEDDataJNI.setInitialized(m_index, initialized);
|
||||
}
|
||||
|
||||
public CallbackStore registerOutputPortCallback(NotifyCallback callback, boolean initialNotify) {
|
||||
int uid = AddressableLEDDataJNI.registerOutputPortCallback(m_index, callback, initialNotify);
|
||||
return new CallbackStore(m_index, uid, AddressableLEDDataJNI::cancelOutputPortCallback);
|
||||
}
|
||||
public int getOutputPort() {
|
||||
return AddressableLEDDataJNI.getOutputPort(m_index);
|
||||
}
|
||||
public void setOutputPort(int outputPort) {
|
||||
AddressableLEDDataJNI.setOutputPort(m_index, outputPort);
|
||||
}
|
||||
|
||||
public CallbackStore registerLengthCallback(NotifyCallback callback, boolean initialNotify) {
|
||||
int uid = AddressableLEDDataJNI.registerLengthCallback(m_index, callback, initialNotify);
|
||||
return new CallbackStore(m_index, uid, AddressableLEDDataJNI::cancelLengthCallback);
|
||||
}
|
||||
public int getLength() {
|
||||
return AddressableLEDDataJNI.getLength(m_index);
|
||||
}
|
||||
public void setLength(int length) {
|
||||
AddressableLEDDataJNI.setLength(m_index, length);
|
||||
}
|
||||
|
||||
public CallbackStore registerRunningCallback(NotifyCallback callback, boolean initialNotify) {
|
||||
int uid = AddressableLEDDataJNI.registerRunningCallback(m_index, callback, initialNotify);
|
||||
return new CallbackStore(m_index, uid, AddressableLEDDataJNI::cancelRunningCallback);
|
||||
}
|
||||
public boolean getRunning() {
|
||||
return AddressableLEDDataJNI.getRunning(m_index);
|
||||
}
|
||||
public void setRunning(boolean running) {
|
||||
AddressableLEDDataJNI.setRunning(m_index, running);
|
||||
}
|
||||
|
||||
public CallbackStore registerDataCallback(ConstBufferCallback callback) {
|
||||
int uid = AddressableLEDDataJNI.registerDataCallback(m_index, callback);
|
||||
return new CallbackStore(m_index, uid, AddressableLEDDataJNI::cancelDataCallback);
|
||||
}
|
||||
public byte[] getData() {
|
||||
return AddressableLEDDataJNI.getData(m_index);
|
||||
}
|
||||
public void setData(byte[] data) {
|
||||
AddressableLEDDataJNI.setData(m_index, data);
|
||||
}
|
||||
|
||||
public void resetData() {
|
||||
AddressableLEDDataJNI.resetData(m_index);
|
||||
}
|
||||
}
|
||||
51
hal/src/main/java/edu/wpi/first/hal/sim/DutyCycleSim.java
Normal file
51
hal/src/main/java/edu/wpi/first/hal/sim/DutyCycleSim.java
Normal file
@@ -0,0 +1,51 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
package edu.wpi.first.hal.sim;
|
||||
|
||||
import edu.wpi.first.hal.sim.mockdata.DutyCycleDataJNI;
|
||||
|
||||
public class DutyCycleSim {
|
||||
private final int m_index;
|
||||
|
||||
public DutyCycleSim(int index) {
|
||||
m_index = index;
|
||||
}
|
||||
|
||||
public CallbackStore registerInitializedCallback(NotifyCallback callback, boolean initialNotify) {
|
||||
int uid = DutyCycleDataJNI.registerInitializedCallback(m_index, callback, initialNotify);
|
||||
return new CallbackStore(m_index, uid, DutyCycleDataJNI::cancelInitializedCallback);
|
||||
}
|
||||
public boolean getInitialized() {
|
||||
return DutyCycleDataJNI.getInitialized(m_index);
|
||||
}
|
||||
public void setInitialized(boolean initialized) {
|
||||
DutyCycleDataJNI.setInitialized(m_index, initialized);
|
||||
}
|
||||
|
||||
public CallbackStore registerFrequencyCallback(NotifyCallback callback, boolean initialNotify) {
|
||||
int uid = DutyCycleDataJNI.registerFrequencyCallback(m_index, callback, initialNotify);
|
||||
return new CallbackStore(m_index, uid, DutyCycleDataJNI::cancelFrequencyCallback);
|
||||
}
|
||||
public int getFrequency() {
|
||||
return DutyCycleDataJNI.getFrequency(m_index);
|
||||
}
|
||||
public void setFrequency(int frequency) {
|
||||
DutyCycleDataJNI.setFrequency(m_index, frequency);
|
||||
}
|
||||
|
||||
public CallbackStore registerOutputCallback(NotifyCallback callback, boolean initialNotify) {
|
||||
int uid = DutyCycleDataJNI.registerOutputCallback(m_index, callback, initialNotify);
|
||||
return new CallbackStore(m_index, uid, DutyCycleDataJNI::cancelOutputCallback);
|
||||
}
|
||||
public double getOutput() {
|
||||
return DutyCycleDataJNI.getOutput(m_index);
|
||||
}
|
||||
public void setOutput(double output) {
|
||||
DutyCycleDataJNI.setOutput(m_index, output);
|
||||
}
|
||||
}
|
||||
23
hal/src/main/java/edu/wpi/first/hal/sim/NotifierSim.java
Normal file
23
hal/src/main/java/edu/wpi/first/hal/sim/NotifierSim.java
Normal file
@@ -0,0 +1,23 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
package edu.wpi.first.hal.sim;
|
||||
|
||||
import edu.wpi.first.hal.sim.mockdata.NotifierDataJNI;
|
||||
|
||||
public final class NotifierSim {
|
||||
private NotifierSim() {
|
||||
}
|
||||
|
||||
public static long getNextTimeout() {
|
||||
return NotifierDataJNI.getNextTimeout();
|
||||
}
|
||||
|
||||
public static int getNumNotifiers() {
|
||||
return NotifierDataJNI.getNumNotifiers();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
|
||||
/* 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. */
|
||||
@@ -24,4 +24,20 @@ public final class SimHooks {
|
||||
public static void restartTiming() {
|
||||
SimulatorJNI.restartTiming();
|
||||
}
|
||||
|
||||
public static void pauseTiming() {
|
||||
SimulatorJNI.pauseTiming();
|
||||
}
|
||||
|
||||
public static void resumeTiming() {
|
||||
SimulatorJNI.resumeTiming();
|
||||
}
|
||||
|
||||
public static boolean isTimingPaused() {
|
||||
return SimulatorJNI.isTimingPaused();
|
||||
}
|
||||
|
||||
public static void stepTiming(long delta) {
|
||||
SimulatorJNI.stepTiming(delta);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
package edu.wpi.first.hal.sim.mockdata;
|
||||
|
||||
import edu.wpi.first.hal.sim.ConstBufferCallback;
|
||||
import edu.wpi.first.hal.sim.NotifyCallback;
|
||||
import edu.wpi.first.hal.JNIWrapper;
|
||||
|
||||
public class AddressableLEDDataJNI extends JNIWrapper {
|
||||
public static native int registerInitializedCallback(int index, NotifyCallback callback, boolean initialNotify);
|
||||
public static native void cancelInitializedCallback(int index, int uid);
|
||||
public static native boolean getInitialized(int index);
|
||||
public static native void setInitialized(int index, boolean initialized);
|
||||
|
||||
public static native int registerOutputPortCallback(int index, NotifyCallback callback, boolean initialNotify);
|
||||
public static native void cancelOutputPortCallback(int index, int uid);
|
||||
public static native int getOutputPort(int index);
|
||||
public static native void setOutputPort(int index, int outputPort);
|
||||
|
||||
public static native int registerLengthCallback(int index, NotifyCallback callback, boolean initialNotify);
|
||||
public static native void cancelLengthCallback(int index, int uid);
|
||||
public static native int getLength(int index);
|
||||
public static native void setLength(int index, int length);
|
||||
|
||||
public static native int registerRunningCallback(int index, NotifyCallback callback, boolean initialNotify);
|
||||
public static native void cancelRunningCallback(int index, int uid);
|
||||
public static native boolean getRunning(int index);
|
||||
public static native void setRunning(int index, boolean running);
|
||||
|
||||
public static native int registerDataCallback(int index, ConstBufferCallback callback);
|
||||
public static native void cancelDataCallback(int index, int uid);
|
||||
public static native byte[] getData(int index);
|
||||
public static native void setData(int index, byte[] data);
|
||||
|
||||
public static native void resetData(int index);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
package edu.wpi.first.hal.sim.mockdata;
|
||||
|
||||
import edu.wpi.first.hal.sim.NotifyCallback;
|
||||
import edu.wpi.first.hal.JNIWrapper;
|
||||
|
||||
public class DutyCycleDataJNI extends JNIWrapper {
|
||||
public static native int registerInitializedCallback(int index, NotifyCallback callback, boolean initialNotify);
|
||||
public static native void cancelInitializedCallback(int index, int uid);
|
||||
public static native boolean getInitialized(int index);
|
||||
public static native void setInitialized(int index, boolean initialized);
|
||||
|
||||
public static native int registerFrequencyCallback(int index, NotifyCallback callback, boolean initialNotify);
|
||||
public static native void cancelFrequencyCallback(int index, int uid);
|
||||
public static native int getFrequency(int index);
|
||||
public static native void setFrequency(int index, int frequency);
|
||||
|
||||
public static native int registerOutputCallback(int index, NotifyCallback callback, boolean initialNotify);
|
||||
public static native void cancelOutputCallback(int index, int uid);
|
||||
public static native double getOutput(int index);
|
||||
public static native void setOutput(int index, double output);
|
||||
|
||||
public static native void resetData(int index);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
package edu.wpi.first.hal.sim.mockdata;
|
||||
|
||||
import edu.wpi.first.hal.JNIWrapper;
|
||||
|
||||
public class NotifierDataJNI extends JNIWrapper {
|
||||
public static native long getNextTimeout();
|
||||
public static native int getNumNotifiers();
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
|
||||
/* 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. */
|
||||
@@ -13,5 +13,9 @@ public class SimulatorJNI extends JNIWrapper {
|
||||
public static native void waitForProgramStart();
|
||||
public static native void setProgramStarted();
|
||||
public static native void restartTiming();
|
||||
public static native void pauseTiming();
|
||||
public static native void resumeTiming();
|
||||
public static native boolean isTimingPaused();
|
||||
public static native void stepTiming(long delta);
|
||||
public static native void resetHandles();
|
||||
}
|
||||
|
||||
288
hal/src/main/native/athena/AddressableLED.cpp
Normal file
288
hal/src/main/native/athena/AddressableLED.cpp
Normal file
@@ -0,0 +1,288 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "hal/AddressableLED.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include <FRC_FPGA_ChipObject/fpgainterfacecapi/NiFpga_HMB.h>
|
||||
|
||||
#include "ConstantsInternal.h"
|
||||
#include "DigitalInternal.h"
|
||||
#include "HALInitializer.h"
|
||||
#include "PortsInternal.h"
|
||||
#include "hal/ChipObject.h"
|
||||
#include "hal/handles/HandlesInternal.h"
|
||||
#include "hal/handles/LimitedHandleResource.h"
|
||||
|
||||
using namespace hal;
|
||||
|
||||
extern "C" {
|
||||
NiFpga_Status NiFpga_ClientFunctionCall(NiFpga_Session session, uint32_t group,
|
||||
uint32_t functionId,
|
||||
const void* inBuffer,
|
||||
size_t inBufferSize, void* outBuffer,
|
||||
size_t outBufferSize);
|
||||
} // extern "C"
|
||||
|
||||
namespace {
|
||||
struct AddressableLED {
|
||||
std::unique_ptr<tLED> led;
|
||||
void* ledBuffer;
|
||||
size_t ledBufferSize;
|
||||
int32_t stringLength = 1;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
static LimitedHandleResource<
|
||||
HAL_AddressableLEDHandle, AddressableLED, kNumAddressableLEDs,
|
||||
HAL_HandleEnum::AddressableLED>* addressableLEDHandles;
|
||||
|
||||
namespace hal {
|
||||
namespace init {
|
||||
void InitializeAddressableLED() {
|
||||
static LimitedHandleResource<HAL_AddressableLEDHandle, AddressableLED,
|
||||
kNumAddressableLEDs,
|
||||
HAL_HandleEnum::AddressableLED>
|
||||
alH;
|
||||
addressableLEDHandles = &alH;
|
||||
}
|
||||
} // namespace init
|
||||
} // namespace hal
|
||||
|
||||
// Shim for broken ChipObject function
|
||||
static const uint32_t clientFeature_hostMemoryBuffer = 0;
|
||||
static const uint32_t hostMemoryBufferFunction_open = 2;
|
||||
|
||||
// Input arguments for HMB open
|
||||
struct AtomicHMBOpenInputs {
|
||||
const char* memoryName;
|
||||
};
|
||||
|
||||
// Output arguments for HMB open
|
||||
struct AtomicHMBOpenOutputs {
|
||||
size_t size;
|
||||
void* virtualAddress;
|
||||
};
|
||||
|
||||
static NiFpga_Status OpenHostMemoryBuffer(NiFpga_Session session,
|
||||
const char* memoryName,
|
||||
void** virtualAddress, size_t* size) {
|
||||
struct AtomicHMBOpenOutputs outputs;
|
||||
|
||||
struct AtomicHMBOpenInputs inputs;
|
||||
inputs.memoryName = memoryName;
|
||||
|
||||
NiFpga_Status retval = NiFpga_ClientFunctionCall(
|
||||
session, clientFeature_hostMemoryBuffer, hostMemoryBufferFunction_open,
|
||||
&inputs, sizeof(struct AtomicHMBOpenInputs), &outputs,
|
||||
sizeof(struct AtomicHMBOpenOutputs));
|
||||
if (NiFpga_IsError(retval)) {
|
||||
return retval;
|
||||
}
|
||||
*virtualAddress = outputs.virtualAddress;
|
||||
if (size != NULL) {
|
||||
*size = outputs.size;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
||||
HAL_AddressableLEDHandle HAL_InitializeAddressableLED(
|
||||
HAL_DigitalHandle outputPort, int32_t* status) {
|
||||
hal::init::CheckInit();
|
||||
|
||||
auto digitalPort =
|
||||
hal::digitalChannelHandles->Get(outputPort, hal::HAL_HandleEnum::PWM);
|
||||
|
||||
if (!digitalPort) {
|
||||
// If DIO was passed, channel error, else generic error
|
||||
if (getHandleType(outputPort) == hal::HAL_HandleEnum::DIO) {
|
||||
*status = HAL_LED_CHANNEL_ERROR;
|
||||
} else {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
}
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
|
||||
if (digitalPort->channel >= kNumPWMHeaders) {
|
||||
*status = HAL_LED_CHANNEL_ERROR;
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
|
||||
auto handle = addressableLEDHandles->Allocate();
|
||||
|
||||
if (handle == HAL_kInvalidHandle) {
|
||||
*status = NO_AVAILABLE_RESOURCES;
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
|
||||
auto led = addressableLEDHandles->Get(handle);
|
||||
|
||||
if (!led) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
|
||||
led->led.reset(tLED::create(status));
|
||||
|
||||
if (*status != 0) {
|
||||
addressableLEDHandles->Free(handle);
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
|
||||
led->led->writeOutputSelect(digitalPort->channel, status);
|
||||
|
||||
if (*status != 0) {
|
||||
addressableLEDHandles->Free(handle);
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
|
||||
led->ledBuffer = nullptr;
|
||||
led->ledBufferSize = 0;
|
||||
|
||||
uint32_t session = led->led->getSystemInterface()->getHandle();
|
||||
|
||||
*status = OpenHostMemoryBuffer(session, "HMB_0_LED", &led->ledBuffer,
|
||||
&led->ledBufferSize);
|
||||
|
||||
if (*status != 0) {
|
||||
addressableLEDHandles->Free(handle);
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
void HAL_FreeAddressableLED(HAL_AddressableLEDHandle handle) {
|
||||
addressableLEDHandles->Free(handle);
|
||||
}
|
||||
|
||||
void HAL_SetAddressableLEDOutputPort(HAL_AddressableLEDHandle handle,
|
||||
HAL_DigitalHandle outputPort,
|
||||
int32_t* status) {
|
||||
auto digitalPort =
|
||||
hal::digitalChannelHandles->Get(outputPort, hal::HAL_HandleEnum::PWM);
|
||||
|
||||
if (!digitalPort) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
auto led = addressableLEDHandles->Get(handle);
|
||||
if (!led) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
led->led->writeOutputSelect(digitalPort->channel, status);
|
||||
}
|
||||
|
||||
void HAL_SetAddressableLEDLength(HAL_AddressableLEDHandle handle,
|
||||
int32_t length, int32_t* status) {
|
||||
auto led = addressableLEDHandles->Get(handle);
|
||||
if (!led) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
if (length > HAL_kAddressableLEDMaxLength) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
return;
|
||||
}
|
||||
|
||||
led->led->strobeReset(status);
|
||||
|
||||
while (led->led->readPixelWriteIndex(status) != 0) {
|
||||
}
|
||||
|
||||
if (*status != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
led->led->writeStringLength(length, status);
|
||||
|
||||
led->stringLength = length;
|
||||
}
|
||||
|
||||
static_assert(sizeof(HAL_AddressableLEDData) == sizeof(uint32_t),
|
||||
"LED Data must be 32 bit");
|
||||
|
||||
void HAL_WriteAddressableLEDData(HAL_AddressableLEDHandle handle,
|
||||
const struct HAL_AddressableLEDData* data,
|
||||
int32_t length, int32_t* status) {
|
||||
auto led = addressableLEDHandles->Get(handle);
|
||||
if (!led) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
if (length > led->stringLength) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
return;
|
||||
}
|
||||
|
||||
std::memcpy(led->ledBuffer, data, length * sizeof(HAL_AddressableLEDData));
|
||||
|
||||
asm("dmb");
|
||||
|
||||
led->led->strobeLoad(status);
|
||||
}
|
||||
|
||||
void HAL_SetAddressableLEDBitTiming(HAL_AddressableLEDHandle handle,
|
||||
int32_t lowTime0NanoSeconds,
|
||||
int32_t highTime0NanoSeconds,
|
||||
int32_t lowTime1NanoSeconds,
|
||||
int32_t highTime1NanoSeconds,
|
||||
int32_t* status) {
|
||||
auto led = addressableLEDHandles->Get(handle);
|
||||
if (!led) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
led->led->writeLowBitTickTiming(1, highTime0NanoSeconds / 25, status);
|
||||
led->led->writeLowBitTickTiming(0, lowTime0NanoSeconds / 25, status);
|
||||
led->led->writeHighBitTickTiming(1, highTime1NanoSeconds / 25, status);
|
||||
led->led->writeHighBitTickTiming(0, lowTime1NanoSeconds / 25, status);
|
||||
}
|
||||
|
||||
void HAL_SetAddressableLEDSyncTime(HAL_AddressableLEDHandle handle,
|
||||
int32_t syncTimeMicroSeconds,
|
||||
int32_t* status) {
|
||||
auto led = addressableLEDHandles->Get(handle);
|
||||
if (!led) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
led->led->writeSyncTiming(syncTimeMicroSeconds, status);
|
||||
}
|
||||
|
||||
void HAL_StartAddressableLEDOutput(HAL_AddressableLEDHandle handle,
|
||||
int32_t* status) {
|
||||
auto led = addressableLEDHandles->Get(handle);
|
||||
if (!led) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
led->led->strobeStart(status);
|
||||
}
|
||||
|
||||
void HAL_StopAddressableLEDOutput(HAL_AddressableLEDHandle handle,
|
||||
int32_t* status) {
|
||||
auto led = addressableLEDHandles->Get(handle);
|
||||
if (!led) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
led->led->strobeAbort(status);
|
||||
}
|
||||
} // extern "C"
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
|
||||
/* 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. */
|
||||
@@ -181,7 +181,7 @@ void HAL_CalibrateAnalogGyro(HAL_GyroHandle handle, int32_t* status) {
|
||||
if (*status != 0) return;
|
||||
|
||||
gyro->center = static_cast<int32_t>(
|
||||
static_cast<double>(value) / static_cast<double>(count) + .5);
|
||||
static_cast<double>(value) / static_cast<double>(count) + 0.5);
|
||||
|
||||
gyro->offset = static_cast<double>(value) / static_cast<double>(count) -
|
||||
static_cast<double>(gyro->center);
|
||||
|
||||
@@ -201,6 +201,14 @@ double HAL_GetAnalogVoltage(HAL_AnalogInputHandle analogPortHandle,
|
||||
return voltage;
|
||||
}
|
||||
|
||||
double HAL_GetAnalogValueToVolts(HAL_AnalogInputHandle analogPortHandle,
|
||||
int32_t rawValue, int32_t* status) {
|
||||
int32_t LSBWeight = HAL_GetAnalogLSBWeight(analogPortHandle, status);
|
||||
int32_t offset = HAL_GetAnalogOffset(analogPortHandle, status);
|
||||
double voltage = LSBWeight * 1.0e-9 * rawValue - offset * 1.0e-9;
|
||||
return voltage;
|
||||
}
|
||||
|
||||
double HAL_GetAnalogAverageVoltage(HAL_AnalogInputHandle analogPortHandle,
|
||||
int32_t* status) {
|
||||
int32_t value = HAL_GetAnalogAverageValue(analogPortHandle, status);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
|
||||
/* 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. */
|
||||
@@ -8,9 +8,11 @@
|
||||
#include "hal/AnalogTrigger.h"
|
||||
|
||||
#include "AnalogInternal.h"
|
||||
#include "DutyCycleInternal.h"
|
||||
#include "HALInitializer.h"
|
||||
#include "PortsInternal.h"
|
||||
#include "hal/AnalogInput.h"
|
||||
#include "hal/DutyCycle.h"
|
||||
#include "hal/Errors.h"
|
||||
#include "hal/handles/HandlesInternal.h"
|
||||
#include "hal/handles/LimitedHandleResource.h"
|
||||
@@ -21,7 +23,7 @@ namespace {
|
||||
|
||||
struct AnalogTrigger {
|
||||
std::unique_ptr<tAnalogTrigger> trigger;
|
||||
HAL_AnalogInputHandle analogHandle;
|
||||
HAL_Handle handle;
|
||||
uint8_t index;
|
||||
};
|
||||
|
||||
@@ -46,7 +48,7 @@ void InitializeAnalogTrigger() {
|
||||
extern "C" {
|
||||
|
||||
HAL_AnalogTriggerHandle HAL_InitializeAnalogTrigger(
|
||||
HAL_AnalogInputHandle portHandle, int32_t* index, int32_t* status) {
|
||||
HAL_AnalogInputHandle portHandle, int32_t* status) {
|
||||
hal::init::CheckInit();
|
||||
// ensure we are given a valid and active AnalogInput handle
|
||||
auto analog_port = analogInputHandles->Get(portHandle);
|
||||
@@ -64,19 +66,46 @@ HAL_AnalogTriggerHandle HAL_InitializeAnalogTrigger(
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
trigger->analogHandle = portHandle;
|
||||
trigger->handle = portHandle;
|
||||
trigger->index = static_cast<uint8_t>(getHandleIndex(handle));
|
||||
*index = trigger->index;
|
||||
|
||||
trigger->trigger.reset(tAnalogTrigger::create(trigger->index, status));
|
||||
trigger->trigger->writeSourceSelect_Channel(analog_port->channel, status);
|
||||
return handle;
|
||||
}
|
||||
|
||||
HAL_AnalogTriggerHandle HAL_InitializeAnalogTriggerDutyCycle(
|
||||
HAL_DutyCycleHandle dutyCycleHandle, int32_t* status) {
|
||||
hal::init::CheckInit();
|
||||
// ensure we are given a valid and active DutyCycle handle
|
||||
auto dutyCycle = dutyCycleHandles->Get(dutyCycleHandle);
|
||||
if (dutyCycle == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
HAL_AnalogTriggerHandle handle = analogTriggerHandles->Allocate();
|
||||
if (handle == HAL_kInvalidHandle) {
|
||||
*status = NO_AVAILABLE_RESOURCES;
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
auto trigger = analogTriggerHandles->Get(handle);
|
||||
if (trigger == nullptr) { // would only occur on thread issue
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
trigger->handle = dutyCycleHandle;
|
||||
trigger->index = static_cast<uint8_t>(getHandleIndex(handle));
|
||||
|
||||
trigger->trigger.reset(tAnalogTrigger::create(trigger->index, status));
|
||||
trigger->trigger->writeSourceSelect_Channel(dutyCycle->index, status);
|
||||
trigger->trigger->writeSourceSelect_DutyCycle(true, status);
|
||||
return handle;
|
||||
}
|
||||
|
||||
void HAL_CleanAnalogTrigger(HAL_AnalogTriggerHandle analogTriggerHandle,
|
||||
int32_t* status) {
|
||||
analogTriggerHandles->Free(analogTriggerHandle);
|
||||
// caller owns the analog input handle.
|
||||
// caller owns the input handle.
|
||||
}
|
||||
|
||||
void HAL_SetAnalogTriggerLimitsRaw(HAL_AnalogTriggerHandle analogTriggerHandle,
|
||||
@@ -89,11 +118,46 @@ void HAL_SetAnalogTriggerLimitsRaw(HAL_AnalogTriggerHandle analogTriggerHandle,
|
||||
}
|
||||
if (lower > upper) {
|
||||
*status = ANALOG_TRIGGER_LIMIT_ORDER_ERROR;
|
||||
return;
|
||||
}
|
||||
trigger->trigger->writeLowerLimit(lower, status);
|
||||
trigger->trigger->writeUpperLimit(upper, status);
|
||||
}
|
||||
|
||||
void HAL_SetAnalogTriggerLimitsDutyCycle(
|
||||
HAL_AnalogTriggerHandle analogTriggerHandle, double lower, double upper,
|
||||
int32_t* status) {
|
||||
auto trigger = analogTriggerHandles->Get(analogTriggerHandle);
|
||||
if (trigger == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
if (getHandleType(trigger->handle) != HAL_HandleEnum::DutyCycle) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
if (lower > upper) {
|
||||
*status = ANALOG_TRIGGER_LIMIT_ORDER_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
if (lower < 0.0 || upper > 1.0) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t scaleFactor =
|
||||
HAL_GetDutyCycleOutputScaleFactor(trigger->handle, status);
|
||||
if (*status != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
trigger->trigger->writeLowerLimit(static_cast<int32_t>(scaleFactor * lower),
|
||||
status);
|
||||
trigger->trigger->writeUpperLimit(static_cast<int32_t>(scaleFactor * upper),
|
||||
status);
|
||||
}
|
||||
|
||||
void HAL_SetAnalogTriggerLimitsVoltage(
|
||||
HAL_AnalogTriggerHandle analogTriggerHandle, double lower, double upper,
|
||||
int32_t* status) {
|
||||
@@ -102,16 +166,22 @@ void HAL_SetAnalogTriggerLimitsVoltage(
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
if (getHandleType(trigger->handle) != HAL_HandleEnum::AnalogInput) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
if (lower > upper) {
|
||||
*status = ANALOG_TRIGGER_LIMIT_ORDER_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: This depends on the averaged setting. Only raw values will work as
|
||||
// is.
|
||||
trigger->trigger->writeLowerLimit(
|
||||
HAL_GetAnalogVoltsToValue(trigger->analogHandle, lower, status), status);
|
||||
HAL_GetAnalogVoltsToValue(trigger->handle, lower, status), status);
|
||||
trigger->trigger->writeUpperLimit(
|
||||
HAL_GetAnalogVoltsToValue(trigger->analogHandle, upper, status), status);
|
||||
HAL_GetAnalogVoltsToValue(trigger->handle, upper, status), status);
|
||||
}
|
||||
|
||||
void HAL_SetAnalogTriggerAveraged(HAL_AnalogTriggerHandle analogTriggerHandle,
|
||||
@@ -121,7 +191,8 @@ void HAL_SetAnalogTriggerAveraged(HAL_AnalogTriggerHandle analogTriggerHandle,
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
if (trigger->trigger->readSourceSelect_Filter(status) != 0) {
|
||||
if (trigger->trigger->readSourceSelect_Filter(status) != 0 ||
|
||||
trigger->trigger->readSourceSelect_DutyCycle(status) != 0) {
|
||||
*status = INCOMPATIBLE_STATE;
|
||||
// TODO: wpi_setWPIErrorWithContext(IncompatibleMode, "Hardware does not
|
||||
// support average and filtering at the same time.");
|
||||
@@ -136,7 +207,8 @@ void HAL_SetAnalogTriggerFiltered(HAL_AnalogTriggerHandle analogTriggerHandle,
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
if (trigger->trigger->readSourceSelect_Averaged(status) != 0) {
|
||||
if (trigger->trigger->readSourceSelect_Averaged(status) != 0 ||
|
||||
trigger->trigger->readSourceSelect_DutyCycle(status) != 0) {
|
||||
*status = INCOMPATIBLE_STATE;
|
||||
// TODO: wpi_setWPIErrorWithContext(IncompatibleMode, "Hardware does not "
|
||||
// "support average and filtering at the same time.");
|
||||
@@ -177,16 +249,27 @@ HAL_Bool HAL_GetAnalogTriggerOutput(HAL_AnalogTriggerHandle analogTriggerHandle,
|
||||
case HAL_Trigger_kInWindow:
|
||||
result =
|
||||
trigger->trigger->readOutput_InHysteresis(trigger->index, status);
|
||||
break; // XXX: Backport
|
||||
break;
|
||||
case HAL_Trigger_kState:
|
||||
result = trigger->trigger->readOutput_OverLimit(trigger->index, status);
|
||||
break; // XXX: Backport
|
||||
break;
|
||||
case HAL_Trigger_kRisingPulse:
|
||||
case HAL_Trigger_kFallingPulse:
|
||||
*status = ANALOG_TRIGGER_PULSE_OUTPUT_ERROR;
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t HAL_GetAnalogTriggerFPGAIndex(
|
||||
HAL_AnalogTriggerHandle analogTriggerHandle, int32_t* status) {
|
||||
auto trigger = analogTriggerHandles->Get(analogTriggerHandle);
|
||||
if (trigger == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return -1;
|
||||
}
|
||||
return trigger->index;
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
1004
hal/src/main/native/athena/DMA.cpp
Normal file
1004
hal/src/main/native/athena/DMA.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@@ -103,9 +103,9 @@ void initializeDigital(int32_t* status) {
|
||||
(kSystemClockTicksPerMicrosecond * 1e3);
|
||||
|
||||
pwmSystem->writeConfig_Period(
|
||||
static_cast<uint16_t>(kDefaultPwmPeriod / loopTime + .5), status);
|
||||
static_cast<uint16_t>(kDefaultPwmPeriod / loopTime + 0.5), status);
|
||||
uint16_t minHigh = static_cast<uint16_t>(
|
||||
(kDefaultPwmCenter - kDefaultPwmStepsDown * loopTime) / loopTime + .5);
|
||||
(kDefaultPwmCenter - kDefaultPwmStepsDown * loopTime) / loopTime + 0.5);
|
||||
pwmSystem->writeConfig_MinHigh(minHigh, status);
|
||||
// Ensure that PWM output values are set to OFF
|
||||
for (uint8_t pwmIndex = 0; pwmIndex < kNumPWMChannels; pwmIndex++) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
|
||||
/* 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. */
|
||||
@@ -96,6 +96,20 @@ bool remapDigitalSource(HAL_Handle digitalSourceHandle,
|
||||
HAL_AnalogTriggerType analogTriggerType,
|
||||
uint8_t& channel, uint8_t& module, bool& analogTrigger);
|
||||
|
||||
/**
|
||||
* Remap the Digital Channel to map to the bitfield channel of the FPGA
|
||||
*/
|
||||
constexpr int32_t remapDigitalChannelToBitfieldChannel(int32_t channel) {
|
||||
// First 10 are headers
|
||||
if (channel < kNumDigitalHeaders) return channel;
|
||||
// 2nd group of 16 are mxp. So if mxp port, add 6, since they start at 10
|
||||
else if (channel < kNumDigitalMXPChannels)
|
||||
return channel + 6;
|
||||
// Assume SPI, so remove MXP channels
|
||||
else
|
||||
return channel - kNumDigitalMXPChannels;
|
||||
}
|
||||
|
||||
/**
|
||||
* Map DIO channel numbers from their physical number (10 to 26) to their
|
||||
* position in the bit field.
|
||||
|
||||
124
hal/src/main/native/athena/DutyCycle.cpp
Normal file
124
hal/src/main/native/athena/DutyCycle.cpp
Normal file
@@ -0,0 +1,124 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "hal/DutyCycle.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "DigitalInternal.h"
|
||||
#include "DutyCycleInternal.h"
|
||||
#include "HALInitializer.h"
|
||||
#include "PortsInternal.h"
|
||||
#include "hal/ChipObject.h"
|
||||
#include "hal/Errors.h"
|
||||
#include "hal/handles/HandlesInternal.h"
|
||||
#include "hal/handles/LimitedHandleResource.h"
|
||||
|
||||
using namespace hal;
|
||||
|
||||
namespace hal {
|
||||
LimitedHandleResource<HAL_DutyCycleHandle, DutyCycle, kNumDutyCycles,
|
||||
HAL_HandleEnum::DutyCycle>* dutyCycleHandles;
|
||||
namespace init {
|
||||
void InitializeDutyCycle() {
|
||||
static LimitedHandleResource<HAL_DutyCycleHandle, DutyCycle, kNumDutyCycles,
|
||||
HAL_HandleEnum::DutyCycle>
|
||||
dcH;
|
||||
dutyCycleHandles = &dcH;
|
||||
}
|
||||
} // namespace init
|
||||
} // namespace hal
|
||||
|
||||
static constexpr int32_t kScaleFactor = 4e7 - 1;
|
||||
|
||||
extern "C" {
|
||||
HAL_DutyCycleHandle HAL_InitializeDutyCycle(HAL_Handle digitalSourceHandle,
|
||||
HAL_AnalogTriggerType triggerType,
|
||||
int32_t* status) {
|
||||
hal::init::CheckInit();
|
||||
|
||||
bool routingAnalogTrigger = false;
|
||||
uint8_t routingChannel = 0;
|
||||
uint8_t routingModule = 0;
|
||||
bool success =
|
||||
remapDigitalSource(digitalSourceHandle, triggerType, routingChannel,
|
||||
routingModule, routingAnalogTrigger);
|
||||
|
||||
if (!success) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
|
||||
HAL_DutyCycleHandle handle = dutyCycleHandles->Allocate();
|
||||
if (handle == HAL_kInvalidHandle) {
|
||||
*status = NO_AVAILABLE_RESOURCES;
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
|
||||
auto dutyCycle = dutyCycleHandles->Get(handle);
|
||||
uint32_t index = static_cast<uint32_t>(getHandleIndex(handle));
|
||||
dutyCycle->dutyCycle.reset(tDutyCycle::create(index, status));
|
||||
|
||||
dutyCycle->dutyCycle->writeSource_AnalogTrigger(routingAnalogTrigger, status);
|
||||
dutyCycle->dutyCycle->writeSource_Channel(routingChannel, status);
|
||||
dutyCycle->dutyCycle->writeSource_Module(routingModule, status);
|
||||
dutyCycle->index = index;
|
||||
|
||||
return handle;
|
||||
}
|
||||
void HAL_FreeDutyCycle(HAL_DutyCycleHandle dutyCycleHandle) {
|
||||
// Just free it, the unique ptr will take care of everything else
|
||||
dutyCycleHandles->Free(dutyCycleHandle);
|
||||
}
|
||||
|
||||
int32_t HAL_GetDutyCycleFrequency(HAL_DutyCycleHandle dutyCycleHandle,
|
||||
int32_t* status) {
|
||||
auto dutyCycle = dutyCycleHandles->Get(dutyCycleHandle);
|
||||
if (!dutyCycle) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// TODO Handle Overflow
|
||||
unsigned char overflow = 0;
|
||||
return dutyCycle->dutyCycle->readFrequency(&overflow, status);
|
||||
}
|
||||
|
||||
double HAL_GetDutyCycleOutput(HAL_DutyCycleHandle dutyCycleHandle,
|
||||
int32_t* status) {
|
||||
return HAL_GetDutyCycleOutputRaw(dutyCycleHandle, status) /
|
||||
static_cast<double>(kScaleFactor);
|
||||
}
|
||||
|
||||
int32_t HAL_GetDutyCycleOutputRaw(HAL_DutyCycleHandle dutyCycleHandle,
|
||||
int32_t* status) {
|
||||
auto dutyCycle = dutyCycleHandles->Get(dutyCycleHandle);
|
||||
if (!dutyCycle) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// TODO Handle Overflow
|
||||
unsigned char overflow = 0;
|
||||
return dutyCycle->dutyCycle->readOutput(&overflow, status);
|
||||
}
|
||||
|
||||
int32_t HAL_GetDutyCycleOutputScaleFactor(HAL_DutyCycleHandle dutyCycleHandle,
|
||||
int32_t* status) {
|
||||
return kScaleFactor;
|
||||
}
|
||||
|
||||
int32_t HAL_GetDutyCycleFPGAIndex(HAL_DutyCycleHandle dutyCycleHandle,
|
||||
int32_t* status) {
|
||||
auto dutyCycle = dutyCycleHandles->Get(dutyCycleHandle);
|
||||
if (!dutyCycle) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return -1;
|
||||
}
|
||||
return dutyCycle->index;
|
||||
}
|
||||
} // extern "C"
|
||||
24
hal/src/main/native/athena/DutyCycleInternal.h
Normal file
24
hal/src/main/native/athena/DutyCycleInternal.h
Normal file
@@ -0,0 +1,24 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* 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 "hal/ChipObject.h"
|
||||
#include "hal/handles/HandlesInternal.h"
|
||||
#include "hal/handles/LimitedHandleResource.h"
|
||||
|
||||
namespace hal {
|
||||
struct DutyCycle {
|
||||
std::unique_ptr<tDutyCycle> dutyCycle;
|
||||
int index;
|
||||
};
|
||||
|
||||
extern LimitedHandleResource<HAL_DutyCycleHandle, DutyCycle, kNumDutyCycles,
|
||||
HAL_HandleEnum::DutyCycle>* dutyCycleHandles;
|
||||
} // namespace hal
|
||||
@@ -35,7 +35,7 @@ Encoder::Encoder(HAL_Handle digitalSourceHandleA,
|
||||
return;
|
||||
}
|
||||
m_counter = HAL_kInvalidHandle;
|
||||
SetMaxPeriod(.5, status);
|
||||
SetMaxPeriod(0.5, status);
|
||||
break;
|
||||
}
|
||||
case HAL_Encoder_k1X:
|
||||
@@ -238,6 +238,19 @@ void InitializeEncoder() {
|
||||
} // namespace init
|
||||
} // namespace hal
|
||||
|
||||
namespace hal {
|
||||
bool GetEncoderBaseHandle(HAL_EncoderHandle handle,
|
||||
HAL_FPGAEncoderHandle* fpgaHandle,
|
||||
HAL_CounterHandle* counterHandle) {
|
||||
auto encoder = encoderHandles->Get(handle);
|
||||
if (!handle) return false;
|
||||
|
||||
*fpgaHandle = encoder->m_encoder;
|
||||
*counterHandle = encoder->m_counter;
|
||||
return true;
|
||||
}
|
||||
} // namespace hal
|
||||
|
||||
extern "C" {
|
||||
HAL_EncoderHandle HAL_InitializeEncoder(
|
||||
HAL_Handle digitalSourceHandleA, HAL_AnalogTriggerType analogTriggerTypeA,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
|
||||
/* 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. */
|
||||
@@ -13,8 +13,16 @@
|
||||
|
||||
namespace hal {
|
||||
|
||||
bool GetEncoderBaseHandle(HAL_EncoderHandle handle,
|
||||
HAL_FPGAEncoderHandle* fpgaEncoderHandle,
|
||||
HAL_CounterHandle* counterHandle);
|
||||
|
||||
class Encoder {
|
||||
public:
|
||||
friend bool GetEncoderBaseHandle(HAL_EncoderHandle handle,
|
||||
HAL_FPGAEncoderHandle* fpgaEncoderHandle,
|
||||
HAL_CounterHandle* counterHandle);
|
||||
|
||||
Encoder(HAL_Handle digitalSourceHandleA,
|
||||
HAL_AnalogTriggerType analogTriggerTypeA,
|
||||
HAL_Handle digitalSourceHandleB,
|
||||
|
||||
@@ -124,7 +124,7 @@ static int32_t HAL_GetMatchInfoInternal(HAL_MatchInfo* info) {
|
||||
|
||||
static wpi::mutex* newDSDataAvailableMutex;
|
||||
static wpi::condition_variable* newDSDataAvailableCond;
|
||||
static int newDSDataAvailableCounter{0};
|
||||
static std::atomic_int newDSDataAvailableCounter{0};
|
||||
|
||||
namespace hal {
|
||||
namespace init {
|
||||
@@ -338,14 +338,46 @@ void HAL_ObserveUserProgramTest(void) {
|
||||
FRC_NetworkCommunication_observeUserProgramTest();
|
||||
}
|
||||
|
||||
HAL_Bool HAL_IsNewControlData(void) {
|
||||
static int& GetThreadLocalLastCount() {
|
||||
// There is a rollover error condition here. At Packet# = n * (uintmax), this
|
||||
// will return false when instead it should return true. However, this at a
|
||||
// 20ms rate occurs once every 2.7 years of DS connected runtime, so not
|
||||
// worth the cycles to check.
|
||||
thread_local int lastCount{-1};
|
||||
std::lock_guard lock{*newDSDataAvailableMutex};
|
||||
int currentCount = newDSDataAvailableCounter;
|
||||
return lastCount;
|
||||
}
|
||||
|
||||
void HAL_WaitForCachedControlData(void) {
|
||||
HAL_WaitForCachedControlDataTimeout(0);
|
||||
}
|
||||
|
||||
HAL_Bool HAL_WaitForCachedControlDataTimeout(double timeout) {
|
||||
int& lastCount = GetThreadLocalLastCount();
|
||||
int currentCount = newDSDataAvailableCounter.load();
|
||||
if (lastCount != currentCount) {
|
||||
lastCount = currentCount;
|
||||
return true;
|
||||
}
|
||||
auto timeoutTime =
|
||||
std::chrono::steady_clock::now() + std::chrono::duration<double>(timeout);
|
||||
|
||||
std::unique_lock lock{*newDSDataAvailableMutex};
|
||||
while (newDSDataAvailableCounter.load() == currentCount) {
|
||||
if (timeout > 0) {
|
||||
auto timedOut = newDSDataAvailableCond->wait_until(lock, timeoutTime);
|
||||
if (timedOut == std::cv_status::timeout) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
newDSDataAvailableCond->wait(lock);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
HAL_Bool HAL_IsNewControlData(void) {
|
||||
int& lastCount = GetThreadLocalLastCount();
|
||||
int currentCount = newDSDataAvailableCounter.load();
|
||||
if (lastCount == currentCount) return false;
|
||||
lastCount = currentCount;
|
||||
return true;
|
||||
@@ -365,9 +397,9 @@ HAL_Bool HAL_WaitForDSDataTimeout(double timeout) {
|
||||
auto timeoutTime =
|
||||
std::chrono::steady_clock::now() + std::chrono::duration<double>(timeout);
|
||||
|
||||
int currentCount = newDSDataAvailableCounter.load();
|
||||
std::unique_lock lock{*newDSDataAvailableMutex};
|
||||
int currentCount = newDSDataAvailableCounter;
|
||||
while (newDSDataAvailableCounter == currentCount) {
|
||||
while (newDSDataAvailableCounter.load() == currentCount) {
|
||||
if (timeout > 0) {
|
||||
auto timedOut = newDSDataAvailableCond->wait_until(lock, timeoutTime);
|
||||
if (timedOut == std::cv_status::timeout) {
|
||||
@@ -388,7 +420,7 @@ static void newDataOccur(uint32_t refNum) {
|
||||
// to signal our threads
|
||||
if (refNum != refNumber) return;
|
||||
// Notify all threads
|
||||
newDSDataAvailableCounter++;
|
||||
newDSDataAvailableCounter.fetch_add(1);
|
||||
newDSDataAvailableCond->notify_all();
|
||||
}
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ using namespace hal;
|
||||
namespace hal {
|
||||
namespace init {
|
||||
void InitializeHAL() {
|
||||
InitializeAddressableLED();
|
||||
InitializeAccelerometer();
|
||||
InitializeAnalogAccumulator();
|
||||
InitializeAnalogGyro();
|
||||
@@ -56,6 +57,8 @@ void InitializeHAL() {
|
||||
InitializeCounter();
|
||||
InitializeDigitalInternal();
|
||||
InitializeDIO();
|
||||
InitializeDMA();
|
||||
InitializeDutyCycle();
|
||||
InitializeEncoder();
|
||||
InitializeFPGAEncoder();
|
||||
InitializeFRCDriverStation();
|
||||
@@ -212,6 +215,10 @@ const char* HAL_GetErrorMessage(int32_t code) {
|
||||
return ERR_FRCSystem_NetCommNotResponding_MESSAGE;
|
||||
case ERR_FRCSystem_NoDSConnection:
|
||||
return ERR_FRCSystem_NoDSConnection_MESSAGE;
|
||||
case HAL_CAN_BUFFER_OVERRUN:
|
||||
return HAL_CAN_BUFFER_OVERRUN_MESSAGE;
|
||||
case HAL_LED_CHANNEL_ERROR:
|
||||
return HAL_LED_CHANNEL_ERROR_MESSAGE;
|
||||
default:
|
||||
return "Unknown error status";
|
||||
}
|
||||
@@ -253,6 +260,28 @@ uint64_t HAL_GetFPGATime(int32_t* status) {
|
||||
return (upper2 << 32) + lower;
|
||||
}
|
||||
|
||||
uint64_t HAL_ExpandFPGATime(uint32_t unexpanded_lower, int32_t* status) {
|
||||
// Capture the current FPGA time. This will give us the upper half of the
|
||||
// clock.
|
||||
uint64_t fpga_time = HAL_GetFPGATime(status);
|
||||
if (*status != 0) return 0;
|
||||
|
||||
// Now, we need to detect the case where the lower bits rolled over after we
|
||||
// sampled. In that case, the upper bits will be 1 bigger than they should
|
||||
// be.
|
||||
|
||||
// Break it into lower and upper portions.
|
||||
uint32_t lower = fpga_time & 0xffffffffull;
|
||||
uint64_t upper = (fpga_time >> 32) & 0xffffffff;
|
||||
|
||||
// The time was sampled *before* the current time, so roll it back.
|
||||
if (lower < unexpanded_lower) {
|
||||
--upper;
|
||||
}
|
||||
|
||||
return (upper << 32) + static_cast<uint64_t>(unexpanded_lower);
|
||||
}
|
||||
|
||||
HAL_Bool HAL_GetFPGAButton(int32_t* status) {
|
||||
if (!global) {
|
||||
*status = NiFpga_Status_ResourceNotInitialized;
|
||||
|
||||
@@ -19,6 +19,7 @@ static inline void CheckInit() {
|
||||
}
|
||||
|
||||
extern void InitializeAccelerometer();
|
||||
extern void InitializeAddressableLED();
|
||||
extern void InitializeAnalogAccumulator();
|
||||
extern void InitializeAnalogGyro();
|
||||
extern void InitializeAnalogInput();
|
||||
@@ -32,6 +33,8 @@ extern void InitializeConstants();
|
||||
extern void InitializeCounter();
|
||||
extern void InitializeDigitalInternal();
|
||||
extern void InitializeDIO();
|
||||
extern void InitializeDMA();
|
||||
extern void InitializeDutyCycle();
|
||||
extern void InitializeEncoder();
|
||||
extern void InitializeFPGAEncoder();
|
||||
extern void InitializeFRCDriverStation();
|
||||
|
||||
@@ -64,12 +64,6 @@ class InterruptThreadOwner : public wpi::SafeThreadOwner<InterruptThread> {
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
static void threadedInterruptHandler(uint32_t mask, void* param) {
|
||||
static_cast<InterruptThreadOwner*>(param)->Notify(mask);
|
||||
}
|
||||
|
||||
struct Interrupt {
|
||||
std::unique_ptr<tInterrupt> anInterrupt;
|
||||
std::unique_ptr<tInterruptManager> manager;
|
||||
@@ -77,6 +71,12 @@ struct Interrupt {
|
||||
void* param = nullptr;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
static void threadedInterruptHandler(uint32_t mask, void* param) {
|
||||
static_cast<InterruptThreadOwner*>(param)->Notify(mask);
|
||||
}
|
||||
|
||||
static LimitedHandleResource<HAL_InterruptHandle, Interrupt, kNumInterrupts,
|
||||
HAL_HandleEnum::Interrupt>* interruptHandles;
|
||||
|
||||
|
||||
@@ -139,6 +139,9 @@ HAL_NotifierHandle HAL_InitializeNotifier(int32_t* status) {
|
||||
return handle;
|
||||
}
|
||||
|
||||
void HAL_SetNotifierName(HAL_NotifierHandle notifierHandle, const char* name,
|
||||
int32_t* status) {}
|
||||
|
||||
void HAL_StopNotifier(HAL_NotifierHandle notifierHandle, int32_t* status) {
|
||||
auto notifier = notifierHandles->Get(notifierHandle);
|
||||
if (!notifier) return;
|
||||
|
||||
@@ -289,6 +289,75 @@ double HAL_GetPDPChannelCurrent(HAL_PDPHandle handle, int32_t channel,
|
||||
return raw * 0.125; /* 7.3 fixed pt value in Amps */
|
||||
}
|
||||
|
||||
void HAL_GetPDPAllChannelCurrents(HAL_PDPHandle handle, double* currents,
|
||||
int32_t* status) {
|
||||
int32_t length = 0;
|
||||
uint64_t receivedTimestamp = 0;
|
||||
PdpStatus1 pdpStatus;
|
||||
HAL_ReadCANPacketTimeout(handle, Status1, pdpStatus.data, &length,
|
||||
&receivedTimestamp, TimeoutMs, status);
|
||||
if (*status != 0) return;
|
||||
PdpStatus2 pdpStatus2;
|
||||
HAL_ReadCANPacketTimeout(handle, Status2, pdpStatus2.data, &length,
|
||||
&receivedTimestamp, TimeoutMs, status);
|
||||
if (*status != 0) return;
|
||||
PdpStatus3 pdpStatus3;
|
||||
HAL_ReadCANPacketTimeout(handle, Status3, pdpStatus3.data, &length,
|
||||
&receivedTimestamp, TimeoutMs, status);
|
||||
if (*status != 0) return;
|
||||
|
||||
currents[0] = ((static_cast<uint32_t>(pdpStatus.bits.chan1_h8) << 2) |
|
||||
pdpStatus.bits.chan1_l2) *
|
||||
0.125;
|
||||
currents[1] = ((static_cast<uint32_t>(pdpStatus.bits.chan2_h6) << 4) |
|
||||
pdpStatus.bits.chan2_l4) *
|
||||
0.125;
|
||||
currents[2] = ((static_cast<uint32_t>(pdpStatus.bits.chan3_h4) << 6) |
|
||||
pdpStatus.bits.chan3_l6) *
|
||||
0.125;
|
||||
currents[3] = ((static_cast<uint32_t>(pdpStatus.bits.chan4_h2) << 8) |
|
||||
pdpStatus.bits.chan4_l8) *
|
||||
0.125;
|
||||
currents[4] = ((static_cast<uint32_t>(pdpStatus.bits.chan5_h8) << 2) |
|
||||
pdpStatus.bits.chan5_l2) *
|
||||
0.125;
|
||||
currents[5] = ((static_cast<uint32_t>(pdpStatus.bits.chan6_h6) << 4) |
|
||||
pdpStatus.bits.chan6_l4) *
|
||||
0.125;
|
||||
|
||||
currents[6] = ((static_cast<uint32_t>(pdpStatus2.bits.chan7_h8) << 2) |
|
||||
pdpStatus2.bits.chan7_l2) *
|
||||
0.125;
|
||||
currents[7] = ((static_cast<uint32_t>(pdpStatus2.bits.chan8_h6) << 4) |
|
||||
pdpStatus2.bits.chan8_l4) *
|
||||
0.125;
|
||||
currents[8] = ((static_cast<uint32_t>(pdpStatus2.bits.chan9_h4) << 6) |
|
||||
pdpStatus2.bits.chan9_l6) *
|
||||
0.125;
|
||||
currents[9] = ((static_cast<uint32_t>(pdpStatus2.bits.chan10_h2) << 8) |
|
||||
pdpStatus2.bits.chan10_l8) *
|
||||
0.125;
|
||||
currents[10] = ((static_cast<uint32_t>(pdpStatus2.bits.chan11_h8) << 2) |
|
||||
pdpStatus2.bits.chan11_l2) *
|
||||
0.125;
|
||||
currents[11] = ((static_cast<uint32_t>(pdpStatus2.bits.chan12_h6) << 4) |
|
||||
pdpStatus2.bits.chan12_l4) *
|
||||
0.125;
|
||||
|
||||
currents[12] = ((static_cast<uint32_t>(pdpStatus3.bits.chan13_h8) << 2) |
|
||||
pdpStatus3.bits.chan13_l2) *
|
||||
0.125;
|
||||
currents[13] = ((static_cast<uint32_t>(pdpStatus3.bits.chan14_h6) << 4) |
|
||||
pdpStatus3.bits.chan14_l4) *
|
||||
0.125;
|
||||
currents[14] = ((static_cast<uint32_t>(pdpStatus3.bits.chan15_h4) << 6) |
|
||||
pdpStatus3.bits.chan15_l6) *
|
||||
0.125;
|
||||
currents[15] = ((static_cast<uint32_t>(pdpStatus3.bits.chan16_h2) << 8) |
|
||||
pdpStatus3.bits.chan16_l8) *
|
||||
0.125;
|
||||
}
|
||||
|
||||
double HAL_GetPDPTotalCurrent(HAL_PDPHandle handle, int32_t* status) {
|
||||
PdpStatusEnergy pdpStatus;
|
||||
int32_t length = 0;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
|
||||
/* 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. */
|
||||
@@ -37,5 +37,7 @@ int32_t HAL_GetNumPCMModules(void) { return kNumPCMModules; }
|
||||
int32_t HAL_GetNumSolenoidChannels(void) { return kNumSolenoidChannels; }
|
||||
int32_t HAL_GetNumPDPModules(void) { return kNumPDPModules; }
|
||||
int32_t HAL_GetNumPDPChannels(void) { return kNumPDPChannels; }
|
||||
int32_t HAL_GetNumDutyCycles(void) { return kNumDutyCycles; }
|
||||
int32_t HAL_GetNumAddressableLEDs(void) { return kNumAddressableLEDs; }
|
||||
|
||||
} // extern "C"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
|
||||
/* 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. */
|
||||
@@ -35,5 +35,7 @@ constexpr int32_t kNumPCMModules = 63;
|
||||
constexpr int32_t kNumSolenoidChannels = 8;
|
||||
constexpr int32_t kNumPDPModules = 63;
|
||||
constexpr int32_t kNumPDPChannels = 16;
|
||||
constexpr int32_t kNumDutyCycles = tDutyCycle::kNumSystems;
|
||||
constexpr int32_t kNumAddressableLEDs = tLED::kNumSystems;
|
||||
|
||||
} // namespace hal
|
||||
|
||||
145
hal/src/main/native/cpp/jni/AddressableLEDJNI.cpp
Normal file
145
hal/src/main/native/cpp/jni/AddressableLEDJNI.cpp
Normal file
@@ -0,0 +1,145 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#include <wpi/jni_util.h>
|
||||
|
||||
#include "HALUtil.h"
|
||||
#include "edu_wpi_first_hal_AddressableLEDJNI.h"
|
||||
#include "hal/AddressableLED.h"
|
||||
|
||||
using namespace frc;
|
||||
using namespace wpi::java;
|
||||
|
||||
static_assert(sizeof(jbyte) * 4 == sizeof(HAL_AddressableLEDData));
|
||||
|
||||
extern "C" {
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_AddressableLEDJNI
|
||||
* Method: initialize
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_AddressableLEDJNI_initialize
|
||||
(JNIEnv* env, jclass, jint handle)
|
||||
{
|
||||
int32_t status = 0;
|
||||
auto ret = HAL_InitializeAddressableLED(
|
||||
static_cast<HAL_DigitalHandle>(handle), &status);
|
||||
CheckStatus(env, status);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_AddressableLEDJNI
|
||||
* Method: free
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_AddressableLEDJNI_free
|
||||
(JNIEnv* env, jclass, jint handle)
|
||||
{
|
||||
HAL_FreeAddressableLED(static_cast<HAL_AddressableLEDHandle>(handle));
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_AddressableLEDJNI
|
||||
* Method: setLength
|
||||
* Signature: (II)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_AddressableLEDJNI_setLength
|
||||
(JNIEnv* env, jclass, jint handle, jint length)
|
||||
{
|
||||
int32_t status = 0;
|
||||
HAL_SetAddressableLEDLength(static_cast<HAL_AddressableLEDHandle>(handle),
|
||||
length, &status);
|
||||
CheckStatus(env, status);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_AddressableLEDJNI
|
||||
* Method: setData
|
||||
* Signature: (I[B)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_AddressableLEDJNI_setData
|
||||
(JNIEnv* env, jclass, jint handle, jbyteArray arr)
|
||||
{
|
||||
int32_t status = 0;
|
||||
JByteArrayRef jArrRef{env, arr};
|
||||
auto arrRef = jArrRef.array();
|
||||
HAL_WriteAddressableLEDData(
|
||||
static_cast<HAL_AddressableLEDHandle>(handle),
|
||||
reinterpret_cast<const HAL_AddressableLEDData*>(arrRef.data()),
|
||||
arrRef.size() / 4, &status);
|
||||
CheckStatus(env, status);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_AddressableLEDJNI
|
||||
* Method: setBitTiming
|
||||
* Signature: (IIIII)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_AddressableLEDJNI_setBitTiming
|
||||
(JNIEnv* env, jclass, jint handle, jint lowTime0, jint highTime0,
|
||||
jint lowTime1, jint highTime1)
|
||||
{
|
||||
int32_t status = 0;
|
||||
HAL_SetAddressableLEDBitTiming(static_cast<HAL_AddressableLEDHandle>(handle),
|
||||
lowTime0, highTime0, lowTime1, highTime1,
|
||||
&status);
|
||||
CheckStatus(env, status);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_AddressableLEDJNI
|
||||
* Method: setSyncTime
|
||||
* Signature: (II)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_AddressableLEDJNI_setSyncTime
|
||||
(JNIEnv* env, jclass, jint handle, jint syncTime)
|
||||
{
|
||||
int32_t status = 0;
|
||||
HAL_SetAddressableLEDSyncTime(static_cast<HAL_AddressableLEDHandle>(handle),
|
||||
syncTime, &status);
|
||||
CheckStatus(env, status);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_AddressableLEDJNI
|
||||
* Method: start
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_AddressableLEDJNI_start
|
||||
(JNIEnv* env, jclass, jint handle)
|
||||
{
|
||||
int32_t status = 0;
|
||||
HAL_StartAddressableLEDOutput(static_cast<HAL_AddressableLEDHandle>(handle),
|
||||
&status);
|
||||
CheckStatus(env, status);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_AddressableLEDJNI
|
||||
* Method: stop
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_AddressableLEDJNI_stop
|
||||
(JNIEnv* env, jclass, jint handle)
|
||||
{
|
||||
int32_t status = 0;
|
||||
HAL_StopAddressableLEDOutput(static_cast<HAL_AddressableLEDHandle>(handle),
|
||||
&status);
|
||||
CheckStatus(env, status);
|
||||
}
|
||||
} // extern "C"
|
||||
@@ -486,18 +486,31 @@ Java_edu_wpi_first_hal_AnalogJNI_getAccumulatorOutput
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_AnalogJNI
|
||||
* Method: initializeAnalogTrigger
|
||||
* Signature: (ILjava/lang/Object;)I
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_AnalogJNI_initializeAnalogTrigger
|
||||
(JNIEnv* env, jclass, jint id, jobject index)
|
||||
(JNIEnv* env, jclass, jint id)
|
||||
{
|
||||
jint* indexHandle =
|
||||
reinterpret_cast<jint*>(env->GetDirectBufferAddress(index));
|
||||
int32_t status = 0;
|
||||
HAL_AnalogTriggerHandle analogTrigger = HAL_InitializeAnalogTrigger(
|
||||
(HAL_AnalogInputHandle)id, reinterpret_cast<int32_t*>(indexHandle),
|
||||
&status);
|
||||
HAL_AnalogTriggerHandle analogTrigger =
|
||||
HAL_InitializeAnalogTrigger((HAL_AnalogInputHandle)id, &status);
|
||||
CheckStatus(env, status);
|
||||
return (jint)analogTrigger;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_AnalogJNI
|
||||
* Method: initializeAnalogTriggerDutyCycle
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_AnalogJNI_initializeAnalogTriggerDutyCycle
|
||||
(JNIEnv* env, jclass, jint id)
|
||||
{
|
||||
int32_t status = 0;
|
||||
HAL_AnalogTriggerHandle analogTrigger =
|
||||
HAL_InitializeAnalogTriggerDutyCycle((HAL_DutyCycleHandle)id, &status);
|
||||
CheckStatus(env, status);
|
||||
return (jint)analogTrigger;
|
||||
}
|
||||
@@ -531,6 +544,21 @@ Java_edu_wpi_first_hal_AnalogJNI_setAnalogTriggerLimitsRaw
|
||||
CheckStatus(env, status);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_AnalogJNI
|
||||
* Method: setAnalogTriggerLimitsDutyCycle
|
||||
* Signature: (IDD)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_AnalogJNI_setAnalogTriggerLimitsDutyCycle
|
||||
(JNIEnv* env, jclass, jint id, jdouble lower, jdouble upper)
|
||||
{
|
||||
int32_t status = 0;
|
||||
HAL_SetAnalogTriggerLimitsDutyCycle((HAL_AnalogTriggerHandle)id, lower, upper,
|
||||
&status);
|
||||
CheckStatus(env, status);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_AnalogJNI
|
||||
* Method: setAnalogTriggerLimitsVoltage
|
||||
@@ -622,4 +650,20 @@ Java_edu_wpi_first_hal_AnalogJNI_getAnalogTriggerOutput
|
||||
return val;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_AnalogJNI
|
||||
* Method: getAnalogTriggerFPGAIndex
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_AnalogJNI_getAnalogTriggerFPGAIndex
|
||||
(JNIEnv* env, jclass, jint id)
|
||||
{
|
||||
int32_t status = 0;
|
||||
auto val =
|
||||
HAL_GetAnalogTriggerFPGAIndex((HAL_AnalogTriggerHandle)id, &status);
|
||||
CheckStatus(env, status);
|
||||
return val;
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
|
||||
/* 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. */
|
||||
@@ -13,6 +13,8 @@
|
||||
|
||||
using namespace frc;
|
||||
|
||||
extern "C" {
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_DigitalGlitchFilterJNI
|
||||
* Method: setFilterSelect
|
||||
@@ -76,3 +78,5 @@ Java_edu_wpi_first_hal_DigitalGlitchFilterJNI_getFilterPeriod
|
||||
CheckStatus(env, status);
|
||||
return result;
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
126
hal/src/main/native/cpp/jni/DutyCycleJNI.cpp
Normal file
126
hal/src/main/native/cpp/jni/DutyCycleJNI.cpp
Normal file
@@ -0,0 +1,126 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#include "HALUtil.h"
|
||||
#include "edu_wpi_first_hal_DutyCycleJNI.h"
|
||||
#include "hal/DutyCycle.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
extern "C" {
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_DutyCycleJNI
|
||||
* Method: initialize
|
||||
* Signature: (II)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_DutyCycleJNI_initialize
|
||||
(JNIEnv* env, jclass, jint digitalSourceHandle, jint analogTriggerType)
|
||||
{
|
||||
int32_t status = 0;
|
||||
auto handle = HAL_InitializeDutyCycle(
|
||||
static_cast<HAL_Handle>(digitalSourceHandle),
|
||||
static_cast<HAL_AnalogTriggerType>(analogTriggerType), &status);
|
||||
CheckStatus(env, status);
|
||||
return handle;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_DutyCycleJNI
|
||||
* Method: free
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_DutyCycleJNI_free
|
||||
(JNIEnv*, jclass, jint handle)
|
||||
{
|
||||
HAL_FreeDutyCycle(static_cast<HAL_DutyCycleHandle>(handle));
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_DutyCycleJNI
|
||||
* Method: getFrequency
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_DutyCycleJNI_getFrequency
|
||||
(JNIEnv* env, jclass, jint handle)
|
||||
{
|
||||
int32_t status = 0;
|
||||
auto retVal = HAL_GetDutyCycleFrequency(
|
||||
static_cast<HAL_DutyCycleHandle>(handle), &status);
|
||||
CheckStatus(env, status);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_DutyCycleJNI
|
||||
* Method: getOutput
|
||||
* Signature: (I)D
|
||||
*/
|
||||
JNIEXPORT jdouble JNICALL
|
||||
Java_edu_wpi_first_hal_DutyCycleJNI_getOutput
|
||||
(JNIEnv* env, jclass, jint handle)
|
||||
{
|
||||
int32_t status = 0;
|
||||
auto retVal =
|
||||
HAL_GetDutyCycleOutput(static_cast<HAL_DutyCycleHandle>(handle), &status);
|
||||
CheckStatus(env, status);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_DutyCycleJNI
|
||||
* Method: getOutputRaw
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_DutyCycleJNI_getOutputRaw
|
||||
(JNIEnv* env, jclass, jint handle)
|
||||
{
|
||||
int32_t status = 0;
|
||||
auto retVal = HAL_GetDutyCycleOutputRaw(
|
||||
static_cast<HAL_DutyCycleHandle>(handle), &status);
|
||||
CheckStatus(env, status);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_DutyCycleJNI
|
||||
* Method: getOutputScaleFactor
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_DutyCycleJNI_getOutputScaleFactor
|
||||
(JNIEnv* env, jclass, jint handle)
|
||||
{
|
||||
int32_t status = 0;
|
||||
auto retVal = HAL_GetDutyCycleOutputScaleFactor(
|
||||
static_cast<HAL_DutyCycleHandle>(handle), &status);
|
||||
CheckStatus(env, status);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_DutyCycleJNI
|
||||
* Method: getFPGAIndex
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_DutyCycleJNI_getFPGAIndex
|
||||
(JNIEnv* env, jclass, jint handle)
|
||||
{
|
||||
int32_t status = 0;
|
||||
auto retVal = HAL_GetDutyCycleFPGAIndex(
|
||||
static_cast<HAL_DutyCycleHandle>(handle), &status);
|
||||
CheckStatus(env, status);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
@@ -10,6 +10,8 @@
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
|
||||
#include <wpi/jni_util.h>
|
||||
|
||||
#include "HALUtil.h"
|
||||
#include "edu_wpi_first_hal_NotifierJNI.h"
|
||||
#include "hal/Notifier.h"
|
||||
@@ -37,6 +39,21 @@ Java_edu_wpi_first_hal_NotifierJNI_initializeNotifier
|
||||
return (jint)notifierHandle;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_NotifierJNI
|
||||
* Method: setNotifierName
|
||||
* Signature: (ILjava/lang/String;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_NotifierJNI_setNotifierName
|
||||
(JNIEnv* env, jclass cls, jint notifierHandle, jstring name)
|
||||
{
|
||||
int32_t status = 0;
|
||||
HAL_SetNotifierName((HAL_NotifierHandle)notifierHandle,
|
||||
wpi::java::JStringRef{env, name}.c_str(), &status);
|
||||
CheckStatus(env, status);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_NotifierJNI
|
||||
* Method: stopNotifier
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
|
||||
/* 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. */
|
||||
@@ -98,6 +98,25 @@ Java_edu_wpi_first_hal_PDPJNI_getPDPChannelCurrent
|
||||
return current;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_PDPJNI
|
||||
* Method: getPDPAllCurrents
|
||||
* Signature: (I[D)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_PDPJNI_getPDPAllCurrents
|
||||
(JNIEnv* env, jclass, jint handle, jdoubleArray jarr)
|
||||
{
|
||||
double storage[16];
|
||||
int32_t status = 0;
|
||||
HAL_GetPDPAllChannelCurrents(handle, storage, &status);
|
||||
if (!CheckStatus(env, status, false)) {
|
||||
return;
|
||||
}
|
||||
|
||||
env->SetDoubleArrayRegion(jarr, 0, 16, storage);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_PDPJNI
|
||||
* Method: getPDPTotalCurrent
|
||||
|
||||
61
hal/src/main/native/include/hal/AddressableLED.h
Normal file
61
hal/src/main/native/include/hal/AddressableLED.h
Normal file
@@ -0,0 +1,61 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* 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 <stdint.h>
|
||||
|
||||
#include "hal/AddressableLEDTypes.h"
|
||||
#include "hal/Types.h"
|
||||
|
||||
/**
|
||||
* @defgroup hal_addressable Addressable LED Functions
|
||||
* @ingroup hal_capi
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
HAL_AddressableLEDHandle HAL_InitializeAddressableLED(
|
||||
HAL_DigitalHandle outputPort, int32_t* status);
|
||||
|
||||
void HAL_FreeAddressableLED(HAL_AddressableLEDHandle handle);
|
||||
|
||||
void HAL_SetAddressableLEDOutputPort(HAL_AddressableLEDHandle handle,
|
||||
HAL_DigitalHandle outputPort,
|
||||
int32_t* status);
|
||||
|
||||
void HAL_SetAddressableLEDLength(HAL_AddressableLEDHandle handle,
|
||||
int32_t length, int32_t* status);
|
||||
|
||||
void HAL_WriteAddressableLEDData(HAL_AddressableLEDHandle handle,
|
||||
const struct HAL_AddressableLEDData* data,
|
||||
int32_t length, int32_t* status);
|
||||
|
||||
void HAL_SetAddressableLEDBitTiming(HAL_AddressableLEDHandle handle,
|
||||
int32_t lowTime0NanoSeconds,
|
||||
int32_t highTime0NanoSeconds,
|
||||
int32_t lowTime1NanoSeconds,
|
||||
int32_t highTime1NanoSeconds,
|
||||
int32_t* status);
|
||||
|
||||
void HAL_SetAddressableLEDSyncTime(HAL_AddressableLEDHandle handle,
|
||||
int32_t syncTimeMicroSeconds,
|
||||
int32_t* status);
|
||||
|
||||
void HAL_StartAddressableLEDOutput(HAL_AddressableLEDHandle handle,
|
||||
int32_t* status);
|
||||
|
||||
void HAL_StopAddressableLEDOutput(HAL_AddressableLEDHandle handle,
|
||||
int32_t* status);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
/** @} */
|
||||
19
hal/src/main/native/include/hal/AddressableLEDTypes.h
Normal file
19
hal/src/main/native/include/hal/AddressableLEDTypes.h
Normal file
@@ -0,0 +1,19 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* 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 <stdint.h>
|
||||
|
||||
#define HAL_kAddressableLEDMaxLength 5460
|
||||
|
||||
struct HAL_AddressableLEDData {
|
||||
uint8_t b;
|
||||
uint8_t g;
|
||||
uint8_t r;
|
||||
uint8_t padding;
|
||||
};
|
||||
@@ -233,6 +233,16 @@ int32_t HAL_GetAnalogLSBWeight(HAL_AnalogInputHandle analogPortHandle,
|
||||
*/
|
||||
int32_t HAL_GetAnalogOffset(HAL_AnalogInputHandle analogPortHandle,
|
||||
int32_t* status);
|
||||
|
||||
/**
|
||||
* Get the analog voltage from a raw value.
|
||||
*
|
||||
* @param analogPortHandle Handle to the analog port the values were read from.
|
||||
* @param rawValue The raw analog value
|
||||
* @return The voltage relating to the value
|
||||
*/
|
||||
double HAL_GetAnalogValueToVolts(HAL_AnalogInputHandle analogPortHandle,
|
||||
int32_t rawValue, int32_t* status);
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
|
||||
/* 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. */
|
||||
@@ -37,11 +37,17 @@ extern "C" {
|
||||
* Initializes an analog trigger.
|
||||
*
|
||||
* @param portHandle the analog input to use for triggering
|
||||
* @param index the trigger index value (output)
|
||||
* @return the created analog trigger handle
|
||||
*/
|
||||
HAL_AnalogTriggerHandle HAL_InitializeAnalogTrigger(
|
||||
HAL_AnalogInputHandle portHandle, int32_t* index, int32_t* status);
|
||||
HAL_AnalogInputHandle portHandle, int32_t* status);
|
||||
|
||||
/**
|
||||
* Initializes an analog trigger with a Duty Cycle input
|
||||
*
|
||||
*/
|
||||
HAL_AnalogTriggerHandle HAL_InitializeAnalogTriggerDutyCycle(
|
||||
HAL_DutyCycleHandle dutyCycleHandle, int32_t* status);
|
||||
|
||||
/**
|
||||
* Frees an analog trigger.
|
||||
@@ -54,7 +60,8 @@ void HAL_CleanAnalogTrigger(HAL_AnalogTriggerHandle analogTriggerHandle,
|
||||
/**
|
||||
* Sets the raw ADC upper and lower limits of the analog trigger.
|
||||
*
|
||||
* HAL_SetAnalogTriggerLimitsVoltage is likely better in most cases.
|
||||
* HAL_SetAnalogTriggerLimitsVoltage or HAL_SetAnalogTriggerLimitsDutyCycle
|
||||
* is likely better in most cases.
|
||||
*
|
||||
* @param analogTriggerHandle the trigger handle
|
||||
* @param lower the lower ADC value
|
||||
@@ -77,12 +84,19 @@ void HAL_SetAnalogTriggerLimitsVoltage(
|
||||
HAL_AnalogTriggerHandle analogTriggerHandle, double lower, double upper,
|
||||
int32_t* status);
|
||||
|
||||
void HAL_SetAnalogTriggerLimitsDutyCycle(
|
||||
HAL_AnalogTriggerHandle analogTriggerHandle, double lower, double upper,
|
||||
int32_t* status);
|
||||
|
||||
/**
|
||||
* Configures the analog trigger to use the averaged vs. raw values.
|
||||
*
|
||||
* If the value is true, then the averaged value is selected for the analog
|
||||
* trigger, otherwise the immediate value is used.
|
||||
*
|
||||
* This is not allowed to be used if filtered mode is set.
|
||||
* This is not allowed to be used with Duty Cycle based inputs.
|
||||
*
|
||||
* @param analogTriggerHandle the trigger handle
|
||||
* @param useAveragedValue true to use averaged values, false for raw
|
||||
*/
|
||||
@@ -96,6 +110,8 @@ void HAL_SetAnalogTriggerAveraged(HAL_AnalogTriggerHandle analogTriggerHandle,
|
||||
* is designed to help with 360 degree pot applications for the period where the
|
||||
* pot crosses through zero.
|
||||
*
|
||||
* This is not allowed to be used if averaged mode is set.
|
||||
*
|
||||
* @param analogTriggerHandle the trigger handle
|
||||
* @param useFilteredValue true to use filtered values, false for average or
|
||||
* raw
|
||||
@@ -137,6 +153,15 @@ HAL_Bool HAL_GetAnalogTriggerTriggerState(
|
||||
HAL_Bool HAL_GetAnalogTriggerOutput(HAL_AnalogTriggerHandle analogTriggerHandle,
|
||||
HAL_AnalogTriggerType type,
|
||||
int32_t* status);
|
||||
|
||||
/**
|
||||
* Get the FPGA index for the AnlogTrigger.
|
||||
*
|
||||
* @param analogTriggerHandle the trigger handle
|
||||
* @return the FPGA index
|
||||
*/
|
||||
int32_t HAL_GetAnalogTriggerFPGAIndex(
|
||||
HAL_AnalogTriggerHandle analogTriggerHandle, int32_t* status);
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
@@ -55,7 +55,8 @@ HAL_ENUM(HAL_CANManufacturer) {
|
||||
HAL_CAN_Man_kTeamUse = 8,
|
||||
HAL_CAN_Man_kKauaiLabs = 9,
|
||||
HAL_CAN_Man_kCopperforge = 10,
|
||||
HAL_CAN_Man_kPWF = 11
|
||||
HAL_CAN_Man_kPWF = 11,
|
||||
HAL_CAN_Man_kStudica = 12
|
||||
};
|
||||
// clang-format on
|
||||
/** @} */
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */
|
||||
/* 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. */
|
||||
@@ -24,9 +24,11 @@
|
||||
#include <FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tCounter.h>
|
||||
#include <FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tDIO.h>
|
||||
#include <FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tDMA.h>
|
||||
#include <FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tDutyCycle.h>
|
||||
#include <FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tEncoder.h>
|
||||
#include <FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tGlobal.h>
|
||||
#include <FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tInterrupt.h>
|
||||
#include <FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tLED.h>
|
||||
#include <FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tPWM.h>
|
||||
#include <FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tPower.h>
|
||||
#include <FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tRelay.h>
|
||||
|
||||
129
hal/src/main/native/include/hal/DMA.h
Normal file
129
hal/src/main/native/include/hal/DMA.h
Normal file
@@ -0,0 +1,129 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* 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 <stdint.h>
|
||||
|
||||
#include "hal/AnalogTrigger.h"
|
||||
#include "hal/Types.h"
|
||||
|
||||
// clang-format off
|
||||
/**
|
||||
* The DMA Read Status.
|
||||
*/
|
||||
HAL_ENUM(HAL_DMAReadStatus ) {
|
||||
HAL_DMA_OK = 1,
|
||||
HAL_DMA_TIMEOUT = 2,
|
||||
HAL_DMA_ERROR = 3,
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
struct HAL_DMASample {
|
||||
uint32_t readBuffer[74];
|
||||
int32_t channelOffsets[22];
|
||||
uint64_t timeStamp;
|
||||
uint32_t captureSize;
|
||||
uint8_t triggerChannels;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
HAL_DMAHandle HAL_InitializeDMA(int32_t* status);
|
||||
void HAL_FreeDMA(HAL_DMAHandle handle);
|
||||
|
||||
void HAL_SetDMAPause(HAL_DMAHandle handle, HAL_Bool pause, int32_t* status);
|
||||
void HAL_SetDMARate(HAL_DMAHandle handle, int32_t cycles, int32_t* status);
|
||||
|
||||
void HAL_AddDMAEncoder(HAL_DMAHandle handle, HAL_EncoderHandle encoderHandle,
|
||||
int32_t* status);
|
||||
void HAL_AddDMAEncoderPeriod(HAL_DMAHandle handle,
|
||||
HAL_EncoderHandle encoderHandle, int32_t* status);
|
||||
void HAL_AddDMACounter(HAL_DMAHandle handle, HAL_CounterHandle counterHandle,
|
||||
int32_t* status);
|
||||
void HAL_AddDMACounterPeriod(HAL_DMAHandle handle,
|
||||
HAL_CounterHandle counterHandle, int32_t* status);
|
||||
void HAL_AddDMADigitalSource(HAL_DMAHandle handle,
|
||||
HAL_Handle digitalSourceHandle, int32_t* status);
|
||||
void HAL_AddDMAAnalogInput(HAL_DMAHandle handle,
|
||||
HAL_AnalogInputHandle aInHandle, int32_t* status);
|
||||
|
||||
void HAL_AddDMAAveragedAnalogInput(HAL_DMAHandle handle,
|
||||
HAL_AnalogInputHandle aInHandle,
|
||||
int32_t* status);
|
||||
|
||||
void HAL_AddDMAAnalogAccumulator(HAL_DMAHandle handle,
|
||||
HAL_AnalogInputHandle aInHandle,
|
||||
int32_t* status);
|
||||
|
||||
void HAL_AddDMADutyCycle(HAL_DMAHandle handle,
|
||||
HAL_DutyCycleHandle dutyCycleHandle, int32_t* status);
|
||||
|
||||
void HAL_SetDMAExternalTrigger(HAL_DMAHandle handle,
|
||||
HAL_Handle digitalSourceHandle,
|
||||
HAL_AnalogTriggerType analogTriggerType,
|
||||
HAL_Bool rising, HAL_Bool falling,
|
||||
int32_t* status);
|
||||
|
||||
void HAL_StartDMA(HAL_DMAHandle handle, int32_t queueDepth, int32_t* status);
|
||||
void HAL_StopDMA(HAL_DMAHandle handle, int32_t* status);
|
||||
|
||||
void* HAL_GetDMADirectPointer(HAL_DMAHandle handle);
|
||||
|
||||
enum HAL_DMAReadStatus HAL_ReadDMADirect(void* dmaPointer,
|
||||
HAL_DMASample* dmaSample,
|
||||
int32_t timeoutMs,
|
||||
int32_t* remainingOut,
|
||||
int32_t* status);
|
||||
|
||||
enum HAL_DMAReadStatus HAL_ReadDMA(HAL_DMAHandle handle,
|
||||
HAL_DMASample* dmaSample, int32_t timeoutMs,
|
||||
int32_t* remainingOut, int32_t* status);
|
||||
|
||||
// Sampling Code
|
||||
uint64_t HAL_GetDMASampleTime(const HAL_DMASample* dmaSample, int32_t* status);
|
||||
|
||||
int32_t HAL_GetDMASampleEncoderRaw(const HAL_DMASample* dmaSample,
|
||||
HAL_EncoderHandle encoderHandle,
|
||||
int32_t* status);
|
||||
|
||||
int32_t HAL_GetDMASampleCounter(const HAL_DMASample* dmaSample,
|
||||
HAL_CounterHandle counterHandle,
|
||||
int32_t* status);
|
||||
|
||||
int32_t HAL_GetDMASampleEncoderPeriodRaw(const HAL_DMASample* dmaSample,
|
||||
HAL_EncoderHandle encoderHandle,
|
||||
int32_t* status);
|
||||
|
||||
int32_t HAL_GetDMASampleCounterPeriod(const HAL_DMASample* dmaSample,
|
||||
HAL_CounterHandle counterHandle,
|
||||
int32_t* status);
|
||||
HAL_Bool HAL_GetDMASampleDigitalSource(const HAL_DMASample* dmaSample,
|
||||
HAL_Handle dSourceHandle,
|
||||
int32_t* status);
|
||||
int32_t HAL_GetDMASampleAnalogInputRaw(const HAL_DMASample* dmaSample,
|
||||
HAL_AnalogInputHandle aInHandle,
|
||||
int32_t* status);
|
||||
|
||||
int32_t HAL_GetDMASampleAveragedAnalogInputRaw(const HAL_DMASample* dmaSample,
|
||||
HAL_AnalogInputHandle aInHandle,
|
||||
int32_t* status);
|
||||
|
||||
void HAL_GetDMASampleAnalogAccumulator(const HAL_DMASample* dmaSample,
|
||||
HAL_AnalogInputHandle aInHandle,
|
||||
int64_t* count, int64_t* value,
|
||||
int32_t* status);
|
||||
|
||||
int32_t HAL_GetDMASampleDutyCycleOutputRaw(const HAL_DMASample* dmaSample,
|
||||
HAL_DutyCycleHandle dutyCycleHandle,
|
||||
int32_t* status);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
@@ -193,6 +193,24 @@ int32_t HAL_GetMatchInfo(HAL_MatchInfo* info);
|
||||
*/
|
||||
void HAL_ReleaseDSMutex(void);
|
||||
|
||||
/**
|
||||
* Checks if new control data has arrived since the last
|
||||
* HAL_WaitForCachedControlData or HAL_IsNewControlData call. If new data has
|
||||
* not arrived, waits for new data to arrive. Otherwise, returns immediately.
|
||||
*/
|
||||
void HAL_WaitForCachedControlData(void);
|
||||
|
||||
/**
|
||||
* Checks if new control data has arrived since the last
|
||||
* HAL_WaitForCachedControlData or HAL_IsNewControlData call. If new data has
|
||||
* not arrived, waits for new data to arrive, or a timeout. Otherwise, returns
|
||||
* immediately.
|
||||
*
|
||||
* @param timeout timeout in seconds
|
||||
* @return true for new data, false for timeout
|
||||
*/
|
||||
HAL_Bool HAL_WaitForCachedControlDataTimeout(double timeout);
|
||||
|
||||
/**
|
||||
* Has a new control packet from the driver station arrived since the last
|
||||
* time this function was called?
|
||||
|
||||
109
hal/src/main/native/include/hal/DutyCycle.h
Normal file
109
hal/src/main/native/include/hal/DutyCycle.h
Normal file
@@ -0,0 +1,109 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* 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 "hal/AnalogTrigger.h"
|
||||
#include "hal/Types.h"
|
||||
|
||||
/**
|
||||
* @defgroup hal_dutycycle DutyCycle Functions
|
||||
* @ingroup hal_capi
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Initialize a DutyCycle input.
|
||||
*
|
||||
* @param digitalSourceHandle the digital source to use (either a
|
||||
* HAL_DigitalHandle or a HAL_AnalogTriggerHandle)
|
||||
* @param triggerType the analog trigger type of the source if it is
|
||||
* an analog trigger
|
||||
* @return thre created duty cycle handle
|
||||
*/
|
||||
HAL_DutyCycleHandle HAL_InitializeDutyCycle(HAL_Handle digitalSourceHandle,
|
||||
HAL_AnalogTriggerType triggerType,
|
||||
int32_t* status);
|
||||
|
||||
/**
|
||||
* Free a DutyCycle.
|
||||
*
|
||||
* @param dutyCycleHandle the duty cycle handle
|
||||
*/
|
||||
void HAL_FreeDutyCycle(HAL_DutyCycleHandle dutyCycleHandle);
|
||||
|
||||
/**
|
||||
* Indicates the duty cycle is used by a simulated device.
|
||||
*
|
||||
* @param handle the duty cycle handle
|
||||
* @param device simulated device handle
|
||||
*/
|
||||
void HAL_SetDutyCycleSimDevice(HAL_DutyCycleHandle handle,
|
||||
HAL_SimDeviceHandle device);
|
||||
|
||||
/**
|
||||
* Get the frequency of the duty cycle signal.
|
||||
*
|
||||
* @param dutyCycleHandle the duty cycle handle
|
||||
* @return frequency in Hertz
|
||||
*/
|
||||
int32_t HAL_GetDutyCycleFrequency(HAL_DutyCycleHandle dutyCycleHandle,
|
||||
int32_t* status);
|
||||
|
||||
/**
|
||||
* Get the output ratio of the duty cycle signal.
|
||||
*
|
||||
* <p> 0 means always low, 1 means always high.
|
||||
*
|
||||
* @param dutyCycleHandle the duty cycle handle
|
||||
* @return output ratio between 0 and 1
|
||||
*/
|
||||
double HAL_GetDutyCycleOutput(HAL_DutyCycleHandle dutyCycleHandle,
|
||||
int32_t* status);
|
||||
|
||||
/**
|
||||
* Get the raw output ratio of the duty cycle signal.
|
||||
*
|
||||
* <p> 0 means always low, an output equal to
|
||||
* GetOutputScaleFactor() means always high.
|
||||
*
|
||||
* @param dutyCycleHandle the duty cycle handle
|
||||
* @return output ratio in raw units
|
||||
*/
|
||||
int32_t HAL_GetDutyCycleOutputRaw(HAL_DutyCycleHandle dutyCycleHandle,
|
||||
int32_t* status);
|
||||
|
||||
/**
|
||||
* Get the scale factor of the output.
|
||||
*
|
||||
* <p> An output equal to this value is always high, and then linearly scales
|
||||
* down to 0. Divide the result of getOutputRaw by this in order to get the
|
||||
* percentage between 0 and 1.
|
||||
*
|
||||
* @param dutyCycleHandle the duty cycle handle
|
||||
* @return the output scale factor
|
||||
*/
|
||||
int32_t HAL_GetDutyCycleOutputScaleFactor(HAL_DutyCycleHandle dutyCycleHandle,
|
||||
int32_t* status);
|
||||
|
||||
/**
|
||||
* Get the FPGA index for the DutyCycle.
|
||||
*
|
||||
* @param dutyCycleHandle the duty cycle handle
|
||||
* @return the FPGA index
|
||||
*/
|
||||
int32_t HAL_GetDutyCycleFPGAIndex(HAL_DutyCycleHandle dutyCycleHandle,
|
||||
int32_t* status);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
/** @} */
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
|
||||
/* 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. */
|
||||
@@ -94,6 +94,14 @@
|
||||
#define HAL_HANDLE_ERROR_MESSAGE \
|
||||
"HAL: A handle parameter was passed incorrectly"
|
||||
|
||||
#define HAL_LED_CHANNEL_ERROR -1099
|
||||
#define HAL_LED_CHANNEL_ERROR_MESSAGE \
|
||||
"HAL: Addressable LEDs only supported on PWM Headers, not MXP or DIO"
|
||||
|
||||
#define HAL_INVALID_DMA_ADDITION -1102
|
||||
#define HAL_INVALID_DMA_ADDITION_MESSAGE \
|
||||
"HAL_AddDMA() only works before HAL_StartDMA()"
|
||||
|
||||
#define HAL_SERIAL_PORT_NOT_FOUND -1123
|
||||
#define HAL_SERIAL_PORT_NOT_FOUND_MESSAGE \
|
||||
"HAL: The specified serial port device was not found"
|
||||
@@ -117,6 +125,13 @@
|
||||
#define HAL_CAN_TIMEOUT -1154
|
||||
#define HAL_CAN_TIMEOUT_MESSAGE "HAL: CAN Receive has Timed Out"
|
||||
|
||||
#define HAL_SIM_NOT_SUPPORTED -1155
|
||||
#define HAL_SIM_NOT_SUPPORTED_MESSAGE "HAL: Method not supported in sim"
|
||||
|
||||
#define HAL_CAN_BUFFER_OVERRUN -35007
|
||||
#define HAL_CAN_BUFFER_OVERRUN_MESSAGE \
|
||||
"HAL: CAN Output Buffer Full. Ensure a device is attached"
|
||||
|
||||
#define VI_ERROR_SYSTEM_ERROR_MESSAGE "HAL - VISA: System Error";
|
||||
#define VI_ERROR_INV_OBJECT_MESSAGE "HAL - VISA: Invalid Object"
|
||||
#define VI_ERROR_RSRC_LOCKED_MESSAGE "HAL - VISA: Resource Locked"
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "hal/DriverStation.h"
|
||||
#include "hal/Encoder.h"
|
||||
#include "hal/Errors.h"
|
||||
#include "hal/FRCUsageReporting.h"
|
||||
#include "hal/HALBase.h"
|
||||
#include "hal/I2C.h"
|
||||
#include "hal/Interrupts.h"
|
||||
@@ -41,7 +42,3 @@
|
||||
#include "hal/Threads.h"
|
||||
#include "hal/Types.h"
|
||||
#include "hal/Value.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include "hal/FRCUsageReporting.h"
|
||||
#endif
|
||||
|
||||
@@ -109,6 +109,20 @@ HAL_PortHandle HAL_GetPortWithModule(int32_t module, int32_t channel);
|
||||
*/
|
||||
uint64_t HAL_GetFPGATime(int32_t* status);
|
||||
|
||||
/**
|
||||
* Given an 32 bit FPGA time, expand it to the nearest likely 64 bit FPGA time.
|
||||
*
|
||||
* Note: This is making the assumption that the timestamp being converted is
|
||||
* always in the past. If you call this with a future timestamp, it probably
|
||||
* will make it in the past. If you wait over 70 minutes between capturing the
|
||||
* bottom 32 bits of the timestamp and expanding it, you will be off by
|
||||
* multiples of 1<<32 microseconds.
|
||||
*
|
||||
* @return The current time in microseconds according to the FPGA (since FPGA
|
||||
* reset) as a 64 bit number.
|
||||
*/
|
||||
uint64_t HAL_ExpandFPGATime(uint32_t unexpanded_lower, int32_t* status);
|
||||
|
||||
/**
|
||||
* Call this to start up HAL. This is required for robot programs.
|
||||
*
|
||||
@@ -135,34 +149,6 @@ uint64_t HAL_GetFPGATime(int32_t* status);
|
||||
*/
|
||||
HAL_Bool HAL_Initialize(int32_t timeout, int32_t mode);
|
||||
|
||||
// ifdef's definition is to allow for default parameters in C++.
|
||||
#ifdef __cplusplus
|
||||
/**
|
||||
* Reports a hardware usage to the HAL.
|
||||
*
|
||||
* @param resource the used resource
|
||||
* @param instanceNumber the instance of the resource
|
||||
* @param context a user specified context index
|
||||
* @param feature a user specified feature string
|
||||
* @return the index of the added value in NetComm
|
||||
*/
|
||||
int64_t HAL_Report(int32_t resource, int32_t instanceNumber,
|
||||
int32_t context = 0, const char* feature = nullptr);
|
||||
#else
|
||||
|
||||
/**
|
||||
* Reports a hardware usage to the HAL.
|
||||
*
|
||||
* @param resource the used resource
|
||||
* @param instanceNumber the instance of the resource
|
||||
* @param context a user specified context index
|
||||
* @param feature a user specified feature string
|
||||
* @return the index of the added value in NetComm
|
||||
*/
|
||||
int64_t HAL_Report(int32_t resource, int32_t instanceNumber, int32_t context,
|
||||
const char* feature);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
|
||||
/* 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. */
|
||||
@@ -31,6 +31,15 @@ extern "C" {
|
||||
*/
|
||||
HAL_NotifierHandle HAL_InitializeNotifier(int32_t* status);
|
||||
|
||||
/**
|
||||
* Sets the name of a notifier.
|
||||
*
|
||||
* @param notifierHandle the notifier handle
|
||||
* @param name name
|
||||
*/
|
||||
void HAL_SetNotifierName(HAL_NotifierHandle notifierHandle, const char* name,
|
||||
int32_t* status);
|
||||
|
||||
/**
|
||||
* Stops a notifier from running.
|
||||
*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
|
||||
/* 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. */
|
||||
@@ -79,6 +79,17 @@ double HAL_GetPDPVoltage(HAL_PDPHandle handle, int32_t* status);
|
||||
double HAL_GetPDPChannelCurrent(HAL_PDPHandle handle, int32_t channel,
|
||||
int32_t* status);
|
||||
|
||||
/**
|
||||
* Gets the current of all 16 channels on the PDP.
|
||||
*
|
||||
* The array must be large enough to hold all channels.
|
||||
*
|
||||
* @param handle the module handle
|
||||
* @param current the currents (output)
|
||||
*/
|
||||
void HAL_GetPDPAllChannelCurrents(HAL_PDPHandle handle, double* currents,
|
||||
int32_t* status);
|
||||
|
||||
/**
|
||||
* Gets the total current of the PDP.
|
||||
*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
|
||||
/* 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. */
|
||||
@@ -144,6 +144,20 @@ int32_t HAL_GetNumPDPModules(void);
|
||||
* @return the number of PDP channels
|
||||
*/
|
||||
int32_t HAL_GetNumPDPChannels(void);
|
||||
|
||||
/**
|
||||
* Gets the number of duty cycle inputs in the current system.
|
||||
*
|
||||
* @return the number of Duty Cycle inputs
|
||||
*/
|
||||
int32_t HAL_GetNumDutyCycles(void);
|
||||
|
||||
/**
|
||||
* Gets the number of addressable LED generators in the current system.
|
||||
*
|
||||
* @return the number of Addressable LED generators
|
||||
*/
|
||||
int32_t HAL_GetNumAddressableLEDs(void);
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
@@ -57,6 +57,12 @@ typedef HAL_Handle HAL_SimDeviceHandle;
|
||||
|
||||
typedef HAL_Handle HAL_SimValueHandle;
|
||||
|
||||
typedef HAL_Handle HAL_DMAHandle;
|
||||
|
||||
typedef HAL_Handle HAL_DutyCycleHandle;
|
||||
|
||||
typedef HAL_Handle HAL_AddressableLEDHandle;
|
||||
|
||||
typedef HAL_CANHandle HAL_PDPHandle;
|
||||
|
||||
typedef int32_t HAL_Bool;
|
||||
|
||||
@@ -66,6 +66,9 @@ enum class HAL_HandleEnum {
|
||||
SimulationJni = 18,
|
||||
CAN = 19,
|
||||
SerialPort = 20,
|
||||
DutyCycle = 21,
|
||||
DMA = 22,
|
||||
AddressableLED = 23,
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
65
hal/src/main/native/include/mockdata/AddressableLEDData.h
Normal file
65
hal/src/main/native/include/mockdata/AddressableLEDData.h
Normal file
@@ -0,0 +1,65 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* 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 "NotifyListener.h"
|
||||
#include "hal/AddressableLEDTypes.h"
|
||||
#include "hal/Types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void HALSIM_ResetAddressableLEDData(int32_t index);
|
||||
|
||||
int32_t HALSIM_RegisterAddressableLEDInitializedCallback(
|
||||
int32_t index, HAL_NotifyCallback callback, void* param,
|
||||
HAL_Bool initialNotify);
|
||||
void HALSIM_CancelAddressableLEDInitializedCallback(int32_t index, int32_t uid);
|
||||
HAL_Bool HALSIM_GetAddressableLEDInitialized(int32_t index);
|
||||
void HALSIM_SetAddressableLEDInitialized(int32_t index, HAL_Bool initialized);
|
||||
|
||||
int32_t HALSIM_RegisterAddressableLEDOutputPortCallback(
|
||||
int32_t index, HAL_NotifyCallback callback, void* param,
|
||||
HAL_Bool initialNotify);
|
||||
void HALSIM_CancelAddressableLEDOutputPortCallback(int32_t index, int32_t uid);
|
||||
int32_t HALSIM_GetAddressableLEDOutputPort(int32_t index);
|
||||
void HALSIM_SetAddressableLEDOutputPort(int32_t index, int32_t outputPort);
|
||||
|
||||
int32_t HALSIM_RegisterAddressableLEDLengthCallback(int32_t index,
|
||||
HAL_NotifyCallback callback,
|
||||
void* param,
|
||||
HAL_Bool initialNotify);
|
||||
void HALSIM_CancelAddressableLEDLengthCallback(int32_t index, int32_t uid);
|
||||
int32_t HALSIM_GetAddressableLEDLength(int32_t index);
|
||||
void HALSIM_SetAddressableLEDLength(int32_t index, int32_t length);
|
||||
|
||||
int32_t HALSIM_RegisterAddressableLEDRunningCallback(
|
||||
int32_t index, HAL_NotifyCallback callback, void* param,
|
||||
HAL_Bool initialNotify);
|
||||
void HALSIM_CancelAddressableLEDRunningCallback(int32_t index, int32_t uid);
|
||||
HAL_Bool HALSIM_GetAddressableLEDRunning(int32_t index);
|
||||
void HALSIM_SetAddressableLEDRunning(int32_t index, HAL_Bool running);
|
||||
|
||||
int32_t HALSIM_RegisterAddressableLEDDataCallback(
|
||||
int32_t index, HAL_ConstBufferCallback callback, void* param);
|
||||
void HALSIM_CancelAddressableLEDDataCallback(int32_t index, int32_t uid);
|
||||
int32_t HALSIM_GetAddressableLEDData(int32_t index,
|
||||
struct HAL_AddressableLEDData* data);
|
||||
void HALSIM_SetAddressableLEDData(int32_t index,
|
||||
const struct HAL_AddressableLEDData* data,
|
||||
int32_t length);
|
||||
|
||||
void HALSIM_RegisterAddressableLEDAllCallbacks(int32_t index,
|
||||
HAL_NotifyCallback callback,
|
||||
void* param,
|
||||
HAL_Bool initialNotify);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
@@ -13,6 +13,7 @@
|
||||
enum HALSIM_AnalogTriggerMode : int32_t {
|
||||
HALSIM_AnalogTriggerUnassigned,
|
||||
HALSIM_AnalogTriggerFiltered,
|
||||
HALSIM_AnalogTriggerDutyCycle,
|
||||
HALSIM_AnalogTriggerAveraged
|
||||
};
|
||||
|
||||
|
||||
52
hal/src/main/native/include/mockdata/DutyCycleData.h
Normal file
52
hal/src/main/native/include/mockdata/DutyCycleData.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* 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 "NotifyListener.h"
|
||||
#include "hal/Types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void HALSIM_ResetDutyCycleData(int32_t index);
|
||||
int32_t HALSIM_GetDutyCycleDigitalChannel(int32_t index);
|
||||
|
||||
int32_t HALSIM_RegisterDutyCycleInitializedCallback(int32_t index,
|
||||
HAL_NotifyCallback callback,
|
||||
void* param,
|
||||
HAL_Bool initialNotify);
|
||||
void HALSIM_CancelDutyCycleInitializedCallback(int32_t index, int32_t uid);
|
||||
HAL_Bool HALSIM_GetDutyCycleInitialized(int32_t index);
|
||||
void HALSIM_SetDutyCycleInitialized(int32_t index, HAL_Bool initialized);
|
||||
|
||||
HAL_SimDeviceHandle HALSIM_GetDutyCycleSimDevice(int32_t index);
|
||||
|
||||
int32_t HALSIM_RegisterDutyCycleOutputCallback(int32_t index,
|
||||
HAL_NotifyCallback callback,
|
||||
void* param,
|
||||
HAL_Bool initialNotify);
|
||||
void HALSIM_CancelDutyCycleOutputCallback(int32_t index, int32_t uid);
|
||||
double HALSIM_GetDutyCycleOutput(int32_t index);
|
||||
void HALSIM_SetDutyCycleOutput(int32_t index, double output);
|
||||
|
||||
int32_t HALSIM_RegisterDutyCycleFrequencyCallback(int32_t index,
|
||||
HAL_NotifyCallback callback,
|
||||
void* param,
|
||||
HAL_Bool initialNotify);
|
||||
void HALSIM_CancelDutyCycleFrequencyCallback(int32_t index, int32_t uid);
|
||||
int32_t HALSIM_GetDutyCycleFrequency(int32_t index);
|
||||
void HALSIM_SetDutyCycleFrequency(int32_t index, int32_t frequency);
|
||||
|
||||
void HALSIM_RegisterDutyCycleAllCallbacks(int32_t index,
|
||||
HAL_NotifyCallback callback,
|
||||
void* param, HAL_Bool initialNotify);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
@@ -14,6 +14,10 @@ void HALSIM_WaitForProgramStart(void);
|
||||
void HALSIM_SetProgramStarted(void);
|
||||
HAL_Bool HALSIM_GetProgramStarted(void);
|
||||
void HALSIM_RestartTiming(void);
|
||||
void HALSIM_PauseTiming(void);
|
||||
void HALSIM_ResumeTiming(void);
|
||||
HAL_Bool HALSIM_IsTimingPaused(void);
|
||||
void HALSIM_StepTiming(uint64_t delta);
|
||||
|
||||
typedef int32_t (*HALSIM_SendErrorHandler)(
|
||||
HAL_Bool isError, int32_t errorCode, HAL_Bool isLVCode, const char* details,
|
||||
|
||||
38
hal/src/main/native/include/mockdata/NotifierData.h
Normal file
38
hal/src/main/native/include/mockdata/NotifierData.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* 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 "hal/Types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct HALSIM_NotifierInfo {
|
||||
HAL_NotifierHandle handle;
|
||||
char name[64];
|
||||
uint64_t timeout;
|
||||
HAL_Bool running;
|
||||
};
|
||||
|
||||
uint64_t HALSIM_GetNextNotifierTimeout(void);
|
||||
|
||||
int32_t HALSIM_GetNumNotifiers(void);
|
||||
|
||||
/**
|
||||
* Gets detailed information about each notifier.
|
||||
*
|
||||
* @param arr array of information to be filled
|
||||
* @param size size of arr
|
||||
* @return Number of notifiers; note: may be larger than passed-in size
|
||||
*/
|
||||
int32_t HALSIM_GetNotifierInfo(struct HALSIM_NotifierInfo* arr, int32_t size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
@@ -74,6 +74,9 @@ void HALSIM_CancelPCMCompressorCurrentCallback(int32_t index, int32_t uid);
|
||||
double HALSIM_GetPCMCompressorCurrent(int32_t index);
|
||||
void HALSIM_SetPCMCompressorCurrent(int32_t index, double compressorCurrent);
|
||||
|
||||
void HALSIM_GetPCMAllSolenoids(int32_t index, uint8_t* values);
|
||||
void HALSIM_SetPCMAllSolenoids(int32_t index, uint8_t values);
|
||||
|
||||
void HALSIM_RegisterPCMAllNonSolenoidCallbacks(int32_t index,
|
||||
HAL_NotifyCallback callback,
|
||||
void* param,
|
||||
|
||||
@@ -46,6 +46,9 @@ void HALSIM_CancelPDPCurrentCallback(int32_t index, int32_t channel,
|
||||
double HALSIM_GetPDPCurrent(int32_t index, int32_t channel);
|
||||
void HALSIM_SetPDPCurrent(int32_t index, int32_t channel, double current);
|
||||
|
||||
void HALSIM_GetPDPAllCurrents(int32_t index, double* currents);
|
||||
void HALSIM_SetPDPAllCurrents(int32_t index, const double* currents);
|
||||
|
||||
void HALSIM_RegisterPDPAllNonCurrentCallbacks(int32_t index, int32_t channel,
|
||||
HAL_NotifyCallback callback,
|
||||
void* param,
|
||||
|
||||
71
hal/src/main/native/include/simulation/DutyCycleSim.h
Normal file
71
hal/src/main/native/include/simulation/DutyCycleSim.h
Normal file
@@ -0,0 +1,71 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* 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>
|
||||
|
||||
#include "CallbackStore.h"
|
||||
#include "mockdata/DutyCycleData.h"
|
||||
|
||||
namespace frc {
|
||||
namespace sim {
|
||||
class DutyCycleSim {
|
||||
public:
|
||||
explicit DutyCycleSim(int index) { m_index = index; }
|
||||
|
||||
std::unique_ptr<CallbackStore> RegisterInitializedCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
m_index, -1, callback, &HALSIM_CancelDutyCycleInitializedCallback);
|
||||
store->SetUid(HALSIM_RegisterDutyCycleInitializedCallback(
|
||||
m_index, &CallbackStoreThunk, store.get(), initialNotify));
|
||||
return store;
|
||||
}
|
||||
|
||||
bool GetInitialized() const {
|
||||
return HALSIM_GetDutyCycleInitialized(m_index);
|
||||
}
|
||||
|
||||
void SetInitialized(bool initialized) {
|
||||
HALSIM_SetDutyCycleInitialized(m_index, initialized);
|
||||
}
|
||||
|
||||
std::unique_ptr<CallbackStore> RegisterFrequencyCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
m_index, -1, callback, &HALSIM_CancelDutyCycleFrequencyCallback);
|
||||
store->SetUid(HALSIM_RegisterDutyCycleFrequencyCallback(
|
||||
m_index, &CallbackStoreThunk, store.get(), initialNotify));
|
||||
return store;
|
||||
}
|
||||
|
||||
int GetFrequency() const { return HALSIM_GetDutyCycleFrequency(m_index); }
|
||||
|
||||
void SetFrequency(int count) { HALSIM_SetDutyCycleFrequency(m_index, count); }
|
||||
|
||||
std::unique_ptr<CallbackStore> RegisterOutputCallback(NotifyCallback callback,
|
||||
bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
m_index, -1, callback, &HALSIM_CancelDutyCycleOutputCallback);
|
||||
store->SetUid(HALSIM_RegisterDutyCycleOutputCallback(
|
||||
m_index, &CallbackStoreThunk, store.get(), initialNotify));
|
||||
return store;
|
||||
}
|
||||
|
||||
double GetOutput() const { return HALSIM_GetDutyCycleOutput(m_index); }
|
||||
|
||||
void SetOutput(double period) { HALSIM_SetDutyCycleOutput(m_index, period); }
|
||||
|
||||
void ResetData() { HALSIM_ResetDutyCycleData(m_index); }
|
||||
|
||||
private:
|
||||
int m_index;
|
||||
};
|
||||
} // namespace sim
|
||||
} // namespace frc
|
||||
@@ -138,6 +138,16 @@ class PCMSim {
|
||||
HALSIM_SetPCMCompressorCurrent(m_index, compressorCurrent);
|
||||
}
|
||||
|
||||
uint8_t GetAllSolenoidOutputs() {
|
||||
uint8_t ret = 0;
|
||||
HALSIM_GetPCMAllSolenoids(m_index, &ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void SetAllSolenoidOutputs(uint8_t outputs) {
|
||||
HALSIM_SetPCMAllSolenoids(m_index, outputs);
|
||||
}
|
||||
|
||||
void ResetData() { HALSIM_ResetPCMData(m_index); }
|
||||
|
||||
private:
|
||||
|
||||
@@ -79,6 +79,14 @@ class PDPSim {
|
||||
HALSIM_SetPDPCurrent(m_index, channel, current);
|
||||
}
|
||||
|
||||
void GetAllCurrents(double* currents) {
|
||||
HALSIM_GetPDPAllCurrents(m_index, currents);
|
||||
}
|
||||
|
||||
void SetAllCurrents(const double* currents) {
|
||||
HALSIM_SetPDPAllCurrents(m_index, currents);
|
||||
}
|
||||
|
||||
void ResetData() { HALSIM_ResetPDPData(m_index); }
|
||||
|
||||
private:
|
||||
|
||||
168
hal/src/main/native/sim/AddressableLED.cpp
Normal file
168
hal/src/main/native/sim/AddressableLED.cpp
Normal file
@@ -0,0 +1,168 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "hal/AddressableLED.h"
|
||||
|
||||
#include "DigitalInternal.h"
|
||||
#include "HALInitializer.h"
|
||||
#include "PortsInternal.h"
|
||||
#include "hal/Errors.h"
|
||||
#include "hal/handles/HandlesInternal.h"
|
||||
#include "hal/handles/LimitedHandleResource.h"
|
||||
#include "mockdata/AddressableLEDDataInternal.h"
|
||||
|
||||
using namespace hal;
|
||||
|
||||
namespace {
|
||||
struct AddressableLED {
|
||||
uint8_t index;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
static LimitedHandleResource<HAL_AddressableLEDHandle, AddressableLED,
|
||||
kNumAddressableLEDs,
|
||||
HAL_HandleEnum::AddressableLED>* ledHandles;
|
||||
|
||||
namespace hal {
|
||||
namespace init {
|
||||
void InitializeAddressableLED() {
|
||||
static LimitedHandleResource<HAL_AddressableLEDHandle, AddressableLED,
|
||||
kNumAddressableLEDs,
|
||||
HAL_HandleEnum::AddressableLED>
|
||||
dcH;
|
||||
ledHandles = &dcH;
|
||||
}
|
||||
} // namespace init
|
||||
} // namespace hal
|
||||
|
||||
extern "C" {
|
||||
HAL_AddressableLEDHandle HAL_InitializeAddressableLED(
|
||||
HAL_DigitalHandle outputPort, int32_t* status) {
|
||||
hal::init::CheckInit();
|
||||
|
||||
auto digitalPort =
|
||||
hal::digitalChannelHandles->Get(outputPort, hal::HAL_HandleEnum::PWM);
|
||||
|
||||
if (!digitalPort) {
|
||||
// If DIO was passed, channel error, else generic error
|
||||
if (getHandleType(outputPort) == hal::HAL_HandleEnum::DIO) {
|
||||
*status = HAL_LED_CHANNEL_ERROR;
|
||||
} else {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
}
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
|
||||
if (digitalPort->channel >= kNumPWMHeaders) {
|
||||
*status = HAL_LED_CHANNEL_ERROR;
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
|
||||
HAL_AddressableLEDHandle handle = ledHandles->Allocate();
|
||||
if (handle == HAL_kInvalidHandle) {
|
||||
*status = NO_AVAILABLE_RESOURCES;
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
|
||||
auto led = ledHandles->Get(handle);
|
||||
if (!led) { // would only occur on thread issue
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
|
||||
int16_t index = getHandleIndex(handle);
|
||||
SimAddressableLEDData[index].outputPort = digitalPort->channel;
|
||||
SimAddressableLEDData[index].length = 1;
|
||||
SimAddressableLEDData[index].running = false;
|
||||
SimAddressableLEDData[index].initialized = true;
|
||||
led->index = index;
|
||||
return handle;
|
||||
}
|
||||
|
||||
void HAL_FreeAddressableLED(HAL_AddressableLEDHandle handle) {
|
||||
auto led = ledHandles->Get(handle);
|
||||
ledHandles->Free(handle);
|
||||
if (!led) return;
|
||||
SimAddressableLEDData[led->index].running = false;
|
||||
SimAddressableLEDData[led->index].initialized = false;
|
||||
}
|
||||
|
||||
void HAL_SetAddressableLEDOutputPort(HAL_AddressableLEDHandle handle,
|
||||
HAL_DigitalHandle outputPort,
|
||||
int32_t* status) {
|
||||
auto led = ledHandles->Get(handle);
|
||||
if (!led) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
if (auto port = digitalChannelHandles->Get(outputPort, HAL_HandleEnum::PWM)) {
|
||||
SimAddressableLEDData[led->index].outputPort = port->channel;
|
||||
} else {
|
||||
SimAddressableLEDData[led->index].outputPort = -1;
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_SetAddressableLEDLength(HAL_AddressableLEDHandle handle,
|
||||
int32_t length, int32_t* status) {
|
||||
auto led = ledHandles->Get(handle);
|
||||
if (!led) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
if (length > HAL_kAddressableLEDMaxLength) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
return;
|
||||
}
|
||||
SimAddressableLEDData[led->index].length = length;
|
||||
}
|
||||
|
||||
void HAL_WriteAddressableLEDData(HAL_AddressableLEDHandle handle,
|
||||
const struct HAL_AddressableLEDData* data,
|
||||
int32_t length, int32_t* status) {
|
||||
auto led = ledHandles->Get(handle);
|
||||
if (!led) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
if (length > SimAddressableLEDData[led->index].length) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
return;
|
||||
}
|
||||
SimAddressableLEDData[led->index].SetData(data, length);
|
||||
}
|
||||
|
||||
void HAL_SetAddressableLEDBitTiming(HAL_AddressableLEDHandle handle,
|
||||
int32_t lowTime0NanoSeconds,
|
||||
int32_t highTime0NanoSeconds,
|
||||
int32_t lowTime1NanoSeconds,
|
||||
int32_t highTime1NanoSeconds,
|
||||
int32_t* status) {}
|
||||
|
||||
void HAL_SetAddressableLEDSyncTime(HAL_AddressableLEDHandle handle,
|
||||
int32_t syncTimeMicroSeconds,
|
||||
int32_t* status) {}
|
||||
|
||||
void HAL_StartAddressableLEDOutput(HAL_AddressableLEDHandle handle,
|
||||
int32_t* status) {
|
||||
auto led = ledHandles->Get(handle);
|
||||
if (!led) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
SimAddressableLEDData[led->index].running = true;
|
||||
}
|
||||
|
||||
void HAL_StopAddressableLEDOutput(HAL_AddressableLEDHandle handle,
|
||||
int32_t* status) {
|
||||
auto led = ledHandles->Get(handle);
|
||||
if (!led) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
SimAddressableLEDData[led->index].running = false;
|
||||
}
|
||||
} // extern "C"
|
||||
@@ -165,6 +165,15 @@ double HAL_GetAnalogVoltage(HAL_AnalogInputHandle analogPortHandle,
|
||||
|
||||
return SimAnalogInData[port->channel].voltage;
|
||||
}
|
||||
|
||||
double HAL_GetAnalogValueToVolts(HAL_AnalogInputHandle analogPortHandle,
|
||||
int32_t rawValue, int32_t* status) {
|
||||
int32_t LSBWeight = HAL_GetAnalogLSBWeight(analogPortHandle, status);
|
||||
int32_t offset = HAL_GetAnalogOffset(analogPortHandle, status);
|
||||
double voltage = LSBWeight * 1.0e-9 * rawValue - offset * 1.0e-9;
|
||||
return voltage;
|
||||
}
|
||||
|
||||
double HAL_GetAnalogAverageVoltage(HAL_AnalogInputHandle analogPortHandle,
|
||||
int32_t* status) {
|
||||
auto port = analogInputHandles->Get(analogPortHandle);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
|
||||
/* 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. */
|
||||
@@ -63,7 +63,7 @@ int32_t hal::GetAnalogTriggerInputIndex(HAL_AnalogTriggerHandle handle,
|
||||
extern "C" {
|
||||
|
||||
HAL_AnalogTriggerHandle HAL_InitializeAnalogTrigger(
|
||||
HAL_AnalogInputHandle portHandle, int32_t* index, int32_t* status) {
|
||||
HAL_AnalogInputHandle portHandle, int32_t* status) {
|
||||
hal::init::CheckInit();
|
||||
// ensure we are given a valid and active AnalogInput handle
|
||||
auto analog_port = analogInputHandles->Get(portHandle);
|
||||
@@ -83,7 +83,6 @@ HAL_AnalogTriggerHandle HAL_InitializeAnalogTrigger(
|
||||
}
|
||||
trigger->analogHandle = portHandle;
|
||||
trigger->index = static_cast<uint8_t>(getHandleIndex(handle));
|
||||
*index = trigger->index;
|
||||
|
||||
SimAnalogTriggerData[trigger->index].initialized = true;
|
||||
|
||||
@@ -92,6 +91,12 @@ HAL_AnalogTriggerHandle HAL_InitializeAnalogTrigger(
|
||||
return handle;
|
||||
}
|
||||
|
||||
HAL_AnalogTriggerHandle HAL_InitializeAnalogTriggerDutyCycle(
|
||||
HAL_DutyCycleHandle dutyCycleHandle, int32_t* status) {
|
||||
*status = HAL_SIM_NOT_SUPPORTED;
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
|
||||
void HAL_CleanAnalogTrigger(HAL_AnalogTriggerHandle analogTriggerHandle,
|
||||
int32_t* status) {
|
||||
auto trigger = analogTriggerHandles->Get(analogTriggerHandle);
|
||||
@@ -133,6 +138,13 @@ void HAL_SetAnalogTriggerLimitsRaw(HAL_AnalogTriggerHandle analogTriggerHandle,
|
||||
SimAnalogTriggerData[trigger->index].triggerUpperBound = trigUpper;
|
||||
SimAnalogTriggerData[trigger->index].triggerLowerBound = trigLower;
|
||||
}
|
||||
|
||||
void HAL_SetAnalogTriggerLimitsDutyCycle(
|
||||
HAL_AnalogTriggerHandle analogTriggerHandle, double lower, double upper,
|
||||
int32_t* status) {
|
||||
*status = HAL_SIM_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
void HAL_SetAnalogTriggerLimitsVoltage(
|
||||
HAL_AnalogTriggerHandle analogTriggerHandle, double lower, double upper,
|
||||
int32_t* status) {
|
||||
@@ -158,7 +170,7 @@ void HAL_SetAnalogTriggerAveraged(HAL_AnalogTriggerHandle analogTriggerHandle,
|
||||
|
||||
AnalogTriggerData* triggerData = &SimAnalogTriggerData[trigger->index];
|
||||
|
||||
if (triggerData->triggerMode.Get() == HALSIM_AnalogTriggerFiltered) {
|
||||
if (triggerData->triggerMode.Get() != HALSIM_AnalogTriggerUnassigned) {
|
||||
*status = INCOMPATIBLE_STATE;
|
||||
return;
|
||||
}
|
||||
@@ -167,6 +179,7 @@ void HAL_SetAnalogTriggerAveraged(HAL_AnalogTriggerHandle analogTriggerHandle,
|
||||
: HALSIM_AnalogTriggerUnassigned;
|
||||
triggerData->triggerMode = setVal;
|
||||
}
|
||||
|
||||
void HAL_SetAnalogTriggerFiltered(HAL_AnalogTriggerHandle analogTriggerHandle,
|
||||
HAL_Bool useFilteredValue, int32_t* status) {
|
||||
auto trigger = analogTriggerHandles->Get(analogTriggerHandle);
|
||||
@@ -177,12 +190,12 @@ void HAL_SetAnalogTriggerFiltered(HAL_AnalogTriggerHandle analogTriggerHandle,
|
||||
|
||||
AnalogTriggerData* triggerData = &SimAnalogTriggerData[trigger->index];
|
||||
|
||||
if (triggerData->triggerMode.Get() == HALSIM_AnalogTriggerAveraged) {
|
||||
if (triggerData->triggerMode.Get() != HALSIM_AnalogTriggerUnassigned) {
|
||||
*status = INCOMPATIBLE_STATE;
|
||||
return;
|
||||
}
|
||||
|
||||
auto setVal = useFilteredValue ? HALSIM_AnalogTriggerAveraged
|
||||
auto setVal = useFilteredValue ? HALSIM_AnalogTriggerFiltered
|
||||
: HALSIM_AnalogTriggerUnassigned;
|
||||
triggerData->triggerMode = setVal;
|
||||
}
|
||||
@@ -258,4 +271,15 @@ HAL_Bool HAL_GetAnalogTriggerOutput(HAL_AnalogTriggerHandle analogTriggerHandle,
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t HAL_GetAnalogTriggerFPGAIndex(
|
||||
HAL_AnalogTriggerHandle analogTriggerHandle, int32_t* status) {
|
||||
auto trigger = analogTriggerHandles->Get(analogTriggerHandle);
|
||||
if (trigger == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return -1;
|
||||
}
|
||||
return trigger->index;
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
124
hal/src/main/native/sim/DMA.cpp
Normal file
124
hal/src/main/native/sim/DMA.cpp
Normal file
@@ -0,0 +1,124 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "hal/DMA.h"
|
||||
|
||||
extern "C" {
|
||||
HAL_DMAHandle HAL_InitializeDMA(int32_t* status) { return HAL_kInvalidHandle; }
|
||||
void HAL_FreeDMA(HAL_DMAHandle handle) {}
|
||||
|
||||
void HAL_SetDMAPause(HAL_DMAHandle handle, HAL_Bool pause, int32_t* status) {}
|
||||
void HAL_SetDMARate(HAL_DMAHandle handle, int32_t cycles, int32_t* status) {}
|
||||
|
||||
void HAL_AddDMAEncoder(HAL_DMAHandle handle, HAL_EncoderHandle encoderHandle,
|
||||
int32_t* status) {}
|
||||
void HAL_AddDMAEncoderPeriod(HAL_DMAHandle handle,
|
||||
HAL_EncoderHandle encoderHandle, int32_t* status) {
|
||||
}
|
||||
void HAL_AddDMACounter(HAL_DMAHandle handle, HAL_CounterHandle counterHandle,
|
||||
int32_t* status) {}
|
||||
void HAL_AddDMACounterPeriod(HAL_DMAHandle handle,
|
||||
HAL_CounterHandle counterHandle, int32_t* status) {
|
||||
}
|
||||
void HAL_AddDMADigitalSource(HAL_DMAHandle handle,
|
||||
HAL_Handle digitalSourceHandle, int32_t* status) {}
|
||||
void HAL_AddDMAAnalogInput(HAL_DMAHandle handle,
|
||||
HAL_AnalogInputHandle aInHandle, int32_t* status) {}
|
||||
|
||||
void HAL_AddDMAAveragedAnalogInput(HAL_DMAHandle handle,
|
||||
HAL_AnalogInputHandle aInHandle,
|
||||
int32_t* status) {}
|
||||
|
||||
void HAL_AddDMAAnalogAccumulator(HAL_DMAHandle handle,
|
||||
HAL_AnalogInputHandle aInHandle,
|
||||
int32_t* status) {}
|
||||
|
||||
void HAL_AddDMADutyCycle(HAL_DMAHandle handle,
|
||||
HAL_DutyCycleHandle dutyCycleHandle, int32_t* status) {
|
||||
}
|
||||
|
||||
void HAL_SetDMAExternalTrigger(HAL_DMAHandle handle,
|
||||
HAL_Handle digitalSourceHandle,
|
||||
HAL_AnalogTriggerType analogTriggerType,
|
||||
HAL_Bool rising, HAL_Bool falling,
|
||||
int32_t* status) {}
|
||||
|
||||
void HAL_StartDMA(HAL_DMAHandle handle, int32_t queueDepth, int32_t* status) {}
|
||||
void HAL_StopDMA(HAL_DMAHandle handle, int32_t* status) {}
|
||||
|
||||
void* HAL_GetDMADirectPointer(HAL_DMAHandle handle) { return nullptr; }
|
||||
|
||||
enum HAL_DMAReadStatus HAL_ReadDMADirect(void* dmaPointer,
|
||||
HAL_DMASample* dmaSample,
|
||||
int32_t timeoutMs,
|
||||
int32_t* remainingOut,
|
||||
int32_t* status) {
|
||||
return HAL_DMA_ERROR;
|
||||
}
|
||||
|
||||
enum HAL_DMAReadStatus HAL_ReadDMA(HAL_DMAHandle handle,
|
||||
HAL_DMASample* dmaSample, int32_t timeoutMs,
|
||||
int32_t* remainingOut, int32_t* status) {
|
||||
return HAL_DMA_ERROR;
|
||||
}
|
||||
|
||||
// Sampling Code
|
||||
uint64_t HAL_GetDMASampleTime(const HAL_DMASample* dmaSample, int32_t* status) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t HAL_GetDMASampleEncoderRaw(const HAL_DMASample* dmaSample,
|
||||
HAL_EncoderHandle encoderHandle,
|
||||
int32_t* status) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t HAL_GetDMASampleCounter(const HAL_DMASample* dmaSample,
|
||||
HAL_CounterHandle counterHandle,
|
||||
int32_t* status) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t HAL_GetDMASampleEncoderPeriodRaw(const HAL_DMASample* dmaSample,
|
||||
HAL_EncoderHandle encoderHandle,
|
||||
int32_t* status) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t HAL_GetDMASampleCounterPeriod(const HAL_DMASample* dmaSample,
|
||||
HAL_CounterHandle counterHandle,
|
||||
int32_t* status) {
|
||||
return 0;
|
||||
}
|
||||
HAL_Bool HAL_GetDMASampleDigitalSource(const HAL_DMASample* dmaSample,
|
||||
HAL_Handle dSourceHandle,
|
||||
int32_t* status) {
|
||||
return 0;
|
||||
}
|
||||
int32_t HAL_GetDMASampleAnalogInputRaw(const HAL_DMASample* dmaSample,
|
||||
HAL_AnalogInputHandle aInHandle,
|
||||
int32_t* status) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t HAL_GetDMASampleAveragedAnalogInputRaw(const HAL_DMASample* dmaSample,
|
||||
HAL_AnalogInputHandle aInHandle,
|
||||
int32_t* status) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void HAL_GetDMASampleAnalogAccumulator(const HAL_DMASample* dmaSample,
|
||||
HAL_AnalogInputHandle aInHandle,
|
||||
int64_t* count, int64_t* value,
|
||||
int32_t* status) {}
|
||||
|
||||
int32_t HAL_GetDMASampleDutyCycleOutputRaw(const HAL_DMASample* dmaSample,
|
||||
HAL_DutyCycleHandle dutyCycleHandle,
|
||||
int32_t* status) {
|
||||
return 0;
|
||||
}
|
||||
} // extern "C"
|
||||
@@ -210,7 +210,11 @@ static void InitLastCountKey(void) {
|
||||
}
|
||||
#endif
|
||||
|
||||
HAL_Bool HAL_IsNewControlData(void) {
|
||||
static int& GetThreadLocalLastCount() {
|
||||
// There is a rollover error condition here. At Packet# = n * (uintmax), this
|
||||
// will return false when instead it should return true. However, this at a
|
||||
// 20ms rate occurs once every 2.7 years of DS connected runtime, so not
|
||||
// worth the cycles to check.
|
||||
#ifdef __APPLE__
|
||||
pthread_once(&lastCountKeyOnce, InitLastCountKey);
|
||||
int* lastCountPtr = static_cast<int*>(pthread_getspecific(lastCountKey));
|
||||
@@ -223,13 +227,43 @@ HAL_Bool HAL_IsNewControlData(void) {
|
||||
#else
|
||||
thread_local int lastCount{-1};
|
||||
#endif
|
||||
// There is a rollover error condition here. At Packet# = n * (uintmax), this
|
||||
// will return false when instead it should return true. However, this at a
|
||||
// 20ms rate occurs once every 2.7 years of DS connected runtime, so not
|
||||
// worth the cycles to check.
|
||||
return lastCount;
|
||||
}
|
||||
|
||||
HAL_Bool HAL_WaitForCachedControlDataTimeout(double timeout) {
|
||||
int& lastCount = GetThreadLocalLastCount();
|
||||
std::unique_lock lock(newDSDataAvailableMutex);
|
||||
int currentCount = newDSDataAvailableCounter;
|
||||
if (lastCount != currentCount) {
|
||||
lastCount = currentCount;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isFinalized.load()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto timeoutTime =
|
||||
std::chrono::steady_clock::now() + std::chrono::duration<double>(timeout);
|
||||
|
||||
while (newDSDataAvailableCounter == currentCount) {
|
||||
if (timeout > 0) {
|
||||
auto timedOut = newDSDataAvailableCond->wait_until(lock, timeoutTime);
|
||||
if (timedOut == std::cv_status::timeout) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
newDSDataAvailableCond->wait(lock);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
HAL_Bool HAL_IsNewControlData(void) {
|
||||
int& lastCount = GetThreadLocalLastCount();
|
||||
int currentCount = 0;
|
||||
{
|
||||
std::unique_lock lock(newDSDataAvailableMutex);
|
||||
std::scoped_lock lock(newDSDataAvailableMutex);
|
||||
currentCount = newDSDataAvailableCounter;
|
||||
}
|
||||
if (lastCount == currentCount) return false;
|
||||
|
||||
120
hal/src/main/native/sim/DutyCycle.cpp
Normal file
120
hal/src/main/native/sim/DutyCycle.cpp
Normal file
@@ -0,0 +1,120 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "hal/DutyCycle.h"
|
||||
|
||||
#include "HALInitializer.h"
|
||||
#include "PortsInternal.h"
|
||||
#include "hal/Errors.h"
|
||||
#include "hal/handles/HandlesInternal.h"
|
||||
#include "hal/handles/LimitedHandleResource.h"
|
||||
#include "mockdata/DutyCycleDataInternal.h"
|
||||
|
||||
using namespace hal;
|
||||
|
||||
namespace {
|
||||
struct DutyCycle {
|
||||
uint8_t index;
|
||||
};
|
||||
struct Empty {};
|
||||
} // namespace
|
||||
|
||||
static LimitedHandleResource<HAL_DutyCycleHandle, DutyCycle, kNumDutyCycles,
|
||||
HAL_HandleEnum::DutyCycle>* dutyCycleHandles;
|
||||
|
||||
namespace hal {
|
||||
namespace init {
|
||||
void InitializeDutyCycle() {
|
||||
static LimitedHandleResource<HAL_DutyCycleHandle, DutyCycle, kNumDutyCycles,
|
||||
HAL_HandleEnum::DutyCycle>
|
||||
dcH;
|
||||
dutyCycleHandles = &dcH;
|
||||
}
|
||||
} // namespace init
|
||||
} // namespace hal
|
||||
|
||||
extern "C" {
|
||||
HAL_DutyCycleHandle HAL_InitializeDutyCycle(HAL_Handle digitalSourceHandle,
|
||||
HAL_AnalogTriggerType triggerType,
|
||||
int32_t* status) {
|
||||
hal::init::CheckInit();
|
||||
|
||||
HAL_DutyCycleHandle handle = dutyCycleHandles->Allocate();
|
||||
if (handle == HAL_kInvalidHandle) {
|
||||
*status = NO_AVAILABLE_RESOURCES;
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
|
||||
auto dutyCycle = dutyCycleHandles->Get(handle);
|
||||
if (dutyCycle == nullptr) { // would only occur on thread issue
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
|
||||
int16_t index = getHandleIndex(handle);
|
||||
SimDutyCycleData[index].digitalChannel = getHandleIndex(digitalSourceHandle);
|
||||
SimDutyCycleData[index].initialized = true;
|
||||
SimDutyCycleData[index].simDevice = 0;
|
||||
dutyCycle->index = index;
|
||||
return handle;
|
||||
}
|
||||
void HAL_FreeDutyCycle(HAL_DutyCycleHandle dutyCycleHandle) {
|
||||
auto dutyCycle = dutyCycleHandles->Get(dutyCycleHandle);
|
||||
dutyCycleHandles->Free(dutyCycleHandle);
|
||||
if (dutyCycle == nullptr) return;
|
||||
SimDutyCycleData[dutyCycle->index].initialized = false;
|
||||
}
|
||||
|
||||
void HAL_SetDutyCycleSimDevice(HAL_EncoderHandle handle,
|
||||
HAL_SimDeviceHandle device) {
|
||||
auto dutyCycle = dutyCycleHandles->Get(handle);
|
||||
if (dutyCycle == nullptr) return;
|
||||
SimDutyCycleData[dutyCycle->index].simDevice = device;
|
||||
}
|
||||
|
||||
int32_t HAL_GetDutyCycleFrequency(HAL_DutyCycleHandle dutyCycleHandle,
|
||||
int32_t* status) {
|
||||
auto dutyCycle = dutyCycleHandles->Get(dutyCycleHandle);
|
||||
if (dutyCycle == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return 0;
|
||||
}
|
||||
return SimDutyCycleData[dutyCycle->index].frequency;
|
||||
}
|
||||
double HAL_GetDutyCycleOutput(HAL_DutyCycleHandle dutyCycleHandle,
|
||||
int32_t* status) {
|
||||
auto dutyCycle = dutyCycleHandles->Get(dutyCycleHandle);
|
||||
if (dutyCycle == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return 0;
|
||||
}
|
||||
return SimDutyCycleData[dutyCycle->index].output;
|
||||
}
|
||||
int32_t HAL_GetDutyCycleOutputRaw(HAL_DutyCycleHandle dutyCycleHandle,
|
||||
int32_t* status) {
|
||||
auto dutyCycle = dutyCycleHandles->Get(dutyCycleHandle);
|
||||
if (dutyCycle == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return 0;
|
||||
}
|
||||
return SimDutyCycleData[dutyCycle->index].output *
|
||||
HAL_GetDutyCycleOutputScaleFactor(dutyCycleHandle, status);
|
||||
}
|
||||
int32_t HAL_GetDutyCycleOutputScaleFactor(HAL_DutyCycleHandle dutyCycleHandle,
|
||||
int32_t* status) {
|
||||
return 4e7 - 1;
|
||||
}
|
||||
int32_t HAL_GetDutyCycleFPGAIndex(HAL_DutyCycleHandle dutyCycleHandle,
|
||||
int32_t* status) {
|
||||
auto dutyCycle = dutyCycleHandles->Get(dutyCycleHandle);
|
||||
if (dutyCycle == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return -1;
|
||||
}
|
||||
return dutyCycle->index;
|
||||
}
|
||||
} // extern "C"
|
||||
@@ -25,6 +25,7 @@ namespace hal {
|
||||
namespace init {
|
||||
void InitializeHAL() {
|
||||
InitializeAccelerometerData();
|
||||
InitializeAddressableLEDData();
|
||||
InitializeAnalogGyroData();
|
||||
InitializeAnalogInData();
|
||||
InitializeAnalogOutData();
|
||||
@@ -32,6 +33,7 @@ void InitializeHAL() {
|
||||
InitializeCanData();
|
||||
InitializeCANAPI();
|
||||
InitializeDigitalPWMData();
|
||||
InitializeDutyCycleData();
|
||||
InitializeDIOData();
|
||||
InitializeDriverStationData();
|
||||
InitializeEncoderData();
|
||||
@@ -45,6 +47,7 @@ void InitializeHAL() {
|
||||
InitializeSPIAccelerometerData();
|
||||
InitializeSPIData();
|
||||
InitializeAccelerometer();
|
||||
InitializeAddressableLED();
|
||||
InitializeAnalogAccumulator();
|
||||
InitializeAnalogGyro();
|
||||
InitializeAnalogInput();
|
||||
@@ -56,6 +59,7 @@ void InitializeHAL() {
|
||||
InitializeCounter();
|
||||
InitializeDigitalInternal();
|
||||
InitializeDIO();
|
||||
InitializeDutyCycle();
|
||||
InitializeDriverStation();
|
||||
InitializeEncoder();
|
||||
InitializeExtensions();
|
||||
@@ -199,6 +203,12 @@ const char* HAL_GetErrorMessage(int32_t code) {
|
||||
return HAL_PWM_SCALE_ERROR_MESSAGE;
|
||||
case HAL_CAN_TIMEOUT:
|
||||
return HAL_CAN_TIMEOUT_MESSAGE;
|
||||
case HAL_SIM_NOT_SUPPORTED:
|
||||
return HAL_SIM_NOT_SUPPORTED_MESSAGE;
|
||||
case HAL_CAN_BUFFER_OVERRUN:
|
||||
return HAL_CAN_BUFFER_OVERRUN_MESSAGE;
|
||||
case HAL_LED_CHANNEL_ERROR:
|
||||
return HAL_LED_CHANNEL_ERROR_MESSAGE;
|
||||
default:
|
||||
return "Unknown error status";
|
||||
}
|
||||
@@ -216,6 +226,28 @@ int64_t HAL_GetFPGARevision(int32_t* status) {
|
||||
|
||||
uint64_t HAL_GetFPGATime(int32_t* status) { return hal::GetFPGATime(); }
|
||||
|
||||
uint64_t HAL_ExpandFPGATime(uint32_t unexpanded_lower, int32_t* status) {
|
||||
// Capture the current FPGA time. This will give us the upper half of the
|
||||
// clock.
|
||||
uint64_t fpga_time = HAL_GetFPGATime(status);
|
||||
if (*status != 0) return 0;
|
||||
|
||||
// Now, we need to detect the case where the lower bits rolled over after we
|
||||
// sampled. In that case, the upper bits will be 1 bigger than they should
|
||||
// be.
|
||||
|
||||
// Break it into lower and upper portions.
|
||||
uint32_t lower = fpga_time & 0xffffffffull;
|
||||
uint64_t upper = (fpga_time >> 32) & 0xffffffff;
|
||||
|
||||
// The time was sampled *before* the current time, so roll it back.
|
||||
if (lower < unexpanded_lower) {
|
||||
--upper;
|
||||
}
|
||||
|
||||
return (upper << 32) + static_cast<uint64_t>(unexpanded_lower);
|
||||
}
|
||||
|
||||
HAL_Bool HAL_GetFPGAButton(int32_t* status) {
|
||||
return SimRoboRioData[0].fpgaButton;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ static inline void CheckInit() {
|
||||
}
|
||||
|
||||
extern void InitializeAccelerometerData();
|
||||
extern void InitializeAddressableLEDData();
|
||||
extern void InitializeAnalogGyroData();
|
||||
extern void InitializeAnalogInData();
|
||||
extern void InitializeAnalogOutData();
|
||||
@@ -26,7 +27,9 @@ extern void InitializeAnalogTriggerData();
|
||||
extern void InitializeCanData();
|
||||
extern void InitializeCANAPI();
|
||||
extern void InitializeDigitalPWMData();
|
||||
extern void InitializeDutyCycleData();
|
||||
extern void InitializeDIOData();
|
||||
extern void InitializeDutyCycle();
|
||||
extern void InitializeDriverStationData();
|
||||
extern void InitializeEncoderData();
|
||||
extern void InitializeI2CData();
|
||||
@@ -39,6 +42,7 @@ extern void InitializeSimDeviceData();
|
||||
extern void InitializeSPIAccelerometerData();
|
||||
extern void InitializeSPIData();
|
||||
extern void InitializeAccelerometer();
|
||||
extern void InitializeAddressableLED();
|
||||
extern void InitializeAnalogAccumulator();
|
||||
extern void InitializeAnalogGyro();
|
||||
extern void InitializeAnalogInput();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
|
||||
/* 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. */
|
||||
@@ -13,10 +13,12 @@
|
||||
#include <wpi/timestamp.h>
|
||||
|
||||
#include "MockHooksInternal.h"
|
||||
#include "NotifierInternal.h"
|
||||
|
||||
static std::atomic<bool> programStarted{false};
|
||||
|
||||
static std::atomic<uint64_t> programStartTime{0};
|
||||
static std::atomic<uint64_t> programPauseTime{0};
|
||||
|
||||
namespace hal {
|
||||
namespace init {
|
||||
@@ -25,12 +27,32 @@ void InitializeMockHooks() {}
|
||||
} // namespace hal
|
||||
|
||||
namespace hal {
|
||||
void RestartTiming() { programStartTime = wpi::Now(); }
|
||||
void RestartTiming() {
|
||||
programStartTime = wpi::Now();
|
||||
if (programPauseTime != 0) programPauseTime = programStartTime.load();
|
||||
}
|
||||
|
||||
void PauseTiming() {
|
||||
if (programPauseTime == 0) programPauseTime = wpi::Now();
|
||||
}
|
||||
|
||||
void ResumeTiming() {
|
||||
if (programPauseTime != 0) {
|
||||
programStartTime += wpi::Now() - programPauseTime;
|
||||
programPauseTime = 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool IsTimingPaused() { return programPauseTime != 0; }
|
||||
|
||||
void StepTiming(uint64_t delta) {
|
||||
if (programPauseTime != 0) programPauseTime += delta;
|
||||
}
|
||||
|
||||
int64_t GetFPGATime() {
|
||||
auto now = wpi::Now();
|
||||
auto currentTime = now - programStartTime;
|
||||
return currentTime;
|
||||
uint64_t curTime = programPauseTime;
|
||||
if (curTime == 0) curTime = wpi::Now();
|
||||
return curTime - programStartTime;
|
||||
}
|
||||
|
||||
double GetFPGATimestamp() { return GetFPGATime() * 1.0e-6; }
|
||||
@@ -56,4 +78,21 @@ void HALSIM_SetProgramStarted(void) { SetProgramStarted(); }
|
||||
HAL_Bool HALSIM_GetProgramStarted(void) { return GetProgramStarted(); }
|
||||
|
||||
void HALSIM_RestartTiming(void) { RestartTiming(); }
|
||||
|
||||
void HALSIM_PauseTiming(void) {
|
||||
PauseTiming();
|
||||
PauseNotifiers();
|
||||
}
|
||||
|
||||
void HALSIM_ResumeTiming(void) {
|
||||
ResumeTiming();
|
||||
ResumeNotifiers();
|
||||
}
|
||||
|
||||
HAL_Bool HALSIM_IsTimingPaused(void) { return IsTimingPaused(); }
|
||||
|
||||
void HALSIM_StepTiming(uint64_t delta) {
|
||||
StepTiming(delta);
|
||||
WakeupNotifiers();
|
||||
}
|
||||
} // extern "C"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
|
||||
/* 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. */
|
||||
@@ -14,6 +14,14 @@
|
||||
namespace hal {
|
||||
void RestartTiming();
|
||||
|
||||
void PauseTiming();
|
||||
|
||||
void ResumeTiming();
|
||||
|
||||
bool IsTimingPaused();
|
||||
|
||||
void StepTiming(uint64_t delta);
|
||||
|
||||
int64_t GetFPGATime();
|
||||
|
||||
double GetFPGATimestamp();
|
||||
|
||||
@@ -7,21 +7,27 @@
|
||||
|
||||
#include "hal/Notifier.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
#include <wpi/condition_variable.h>
|
||||
#include <wpi/mutex.h>
|
||||
#include <wpi/timestamp.h>
|
||||
|
||||
#include "HALInitializer.h"
|
||||
#include "NotifierInternal.h"
|
||||
#include "hal/HAL.h"
|
||||
#include "hal/cpp/fpga_clock.h"
|
||||
#include "hal/handles/UnlimitedHandleResource.h"
|
||||
#include "mockdata/NotifierData.h"
|
||||
|
||||
namespace {
|
||||
struct Notifier {
|
||||
std::string name;
|
||||
uint64_t waitTime;
|
||||
bool updatedAlarm = false;
|
||||
bool active = true;
|
||||
bool running = false;
|
||||
wpi::mutex mutex;
|
||||
@@ -48,6 +54,7 @@ class NotifierHandleContainer
|
||||
};
|
||||
|
||||
static NotifierHandleContainer* notifierHandles;
|
||||
static std::atomic<bool> notifiersPaused{false};
|
||||
|
||||
namespace hal {
|
||||
namespace init {
|
||||
@@ -56,6 +63,19 @@ void InitializeNotifier() {
|
||||
notifierHandles = &nH;
|
||||
}
|
||||
} // namespace init
|
||||
|
||||
void PauseNotifiers() { notifiersPaused = true; }
|
||||
|
||||
void ResumeNotifiers() {
|
||||
notifiersPaused = false;
|
||||
WakeupNotifiers();
|
||||
}
|
||||
|
||||
void WakeupNotifiers() {
|
||||
notifierHandles->ForEach([](HAL_NotifierHandle handle, Notifier* notifier) {
|
||||
notifier->cond.notify_all();
|
||||
});
|
||||
}
|
||||
} // namespace hal
|
||||
|
||||
extern "C" {
|
||||
@@ -71,6 +91,14 @@ HAL_NotifierHandle HAL_InitializeNotifier(int32_t* status) {
|
||||
return handle;
|
||||
}
|
||||
|
||||
void HAL_SetNotifierName(HAL_NotifierHandle notifierHandle, const char* name,
|
||||
int32_t* status) {
|
||||
auto notifier = notifierHandles->Get(notifierHandle);
|
||||
if (!notifier) return;
|
||||
std::scoped_lock lock(notifier->mutex);
|
||||
notifier->name = name;
|
||||
}
|
||||
|
||||
void HAL_StopNotifier(HAL_NotifierHandle notifierHandle, int32_t* status) {
|
||||
auto notifier = notifierHandles->Get(notifierHandle);
|
||||
if (!notifier) return;
|
||||
@@ -105,7 +133,6 @@ void HAL_UpdateNotifierAlarm(HAL_NotifierHandle notifierHandle,
|
||||
std::scoped_lock lock(notifier->mutex);
|
||||
notifier->waitTime = triggerTime;
|
||||
notifier->running = true;
|
||||
notifier->updatedAlarm = true;
|
||||
}
|
||||
|
||||
// We wake up any waiters to change how long they're sleeping for
|
||||
@@ -131,29 +158,66 @@ uint64_t HAL_WaitForNotifierAlarm(HAL_NotifierHandle notifierHandle,
|
||||
std::unique_lock lock(notifier->mutex);
|
||||
while (notifier->active) {
|
||||
double waitTime;
|
||||
if (!notifier->running) {
|
||||
if (!notifier->running || notifiersPaused) {
|
||||
waitTime = (HAL_GetFPGATime(status) * 1e-6) + 1000.0;
|
||||
// If not running, wait 1000 seconds
|
||||
} else {
|
||||
waitTime = notifier->waitTime * 1e-6;
|
||||
}
|
||||
|
||||
// Don't wait twice
|
||||
notifier->updatedAlarm = false;
|
||||
|
||||
auto timeoutTime =
|
||||
hal::fpga_clock::epoch() + std::chrono::duration<double>(waitTime);
|
||||
notifier->cond.wait_until(lock, timeoutTime);
|
||||
if (notifier->updatedAlarm) {
|
||||
notifier->updatedAlarm = false;
|
||||
continue;
|
||||
}
|
||||
if (!notifier->running) continue;
|
||||
if (!notifier->active) break;
|
||||
uint64_t curTime = HAL_GetFPGATime(status);
|
||||
if (curTime < notifier->waitTime) continue;
|
||||
notifier->running = false;
|
||||
return HAL_GetFPGATime(status);
|
||||
return curTime;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint64_t HALSIM_GetNextNotifierTimeout(void) {
|
||||
uint64_t timeout = UINT64_MAX;
|
||||
notifierHandles->ForEach([&](HAL_NotifierHandle, Notifier* notifier) {
|
||||
std::scoped_lock lock(notifier->mutex);
|
||||
if (notifier->active && notifier->running && timeout > notifier->waitTime)
|
||||
timeout = notifier->waitTime;
|
||||
});
|
||||
return timeout;
|
||||
}
|
||||
|
||||
int32_t HALSIM_GetNumNotifiers(void) {
|
||||
int32_t count = 0;
|
||||
notifierHandles->ForEach([&](HAL_NotifierHandle, Notifier* notifier) {
|
||||
std::scoped_lock lock(notifier->mutex);
|
||||
if (notifier->active) ++count;
|
||||
});
|
||||
return count;
|
||||
}
|
||||
|
||||
int32_t HALSIM_GetNotifierInfo(struct HALSIM_NotifierInfo* arr, int32_t size) {
|
||||
int32_t num = 0;
|
||||
notifierHandles->ForEach([&](HAL_NotifierHandle handle, Notifier* notifier) {
|
||||
std::scoped_lock lock(notifier->mutex);
|
||||
if (!notifier->active) return;
|
||||
if (num < size) {
|
||||
arr[num].handle = handle;
|
||||
if (notifier->name.empty()) {
|
||||
std::snprintf(arr[num].name, sizeof(arr[num].name), "Notifier%d",
|
||||
static_cast<int>(getHandleIndex(handle)));
|
||||
} else {
|
||||
std::strncpy(arr[num].name, notifier->name.c_str(),
|
||||
sizeof(arr[num].name));
|
||||
arr[num].name[sizeof(arr[num].name) - 1] = '\0';
|
||||
}
|
||||
arr[num].timeout = notifier->waitTime;
|
||||
arr[num].running = notifier->running;
|
||||
}
|
||||
++num;
|
||||
});
|
||||
return num;
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
14
hal/src/main/native/sim/NotifierInternal.h
Normal file
14
hal/src/main/native/sim/NotifierInternal.h
Normal file
@@ -0,0 +1,14 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* 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
|
||||
|
||||
namespace hal {
|
||||
void PauseNotifiers();
|
||||
void ResumeNotifiers();
|
||||
void WakeupNotifiers();
|
||||
} // namespace hal
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
|
||||
/* 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. */
|
||||
@@ -78,6 +78,18 @@ double HAL_GetPDPChannelCurrent(HAL_PDPHandle handle, int32_t channel,
|
||||
}
|
||||
return SimPDPData[module].current[channel];
|
||||
}
|
||||
void HAL_GetPDPAllChannelCurrents(HAL_PDPHandle handle, double* currents,
|
||||
int32_t* status) {
|
||||
auto module = hal::can::GetCANModuleFromHandle(handle, status);
|
||||
if (*status != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto& data = SimPDPData[module];
|
||||
for (int i = 0; i < kNumPDPChannels; i++) {
|
||||
currents[i] = data.current[i];
|
||||
}
|
||||
}
|
||||
double HAL_GetPDPTotalCurrent(HAL_PDPHandle handle, int32_t* status) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
|
||||
/* 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. */
|
||||
@@ -36,5 +36,6 @@ int32_t HAL_GetNumPCMModules(void) { return kNumPCMModules; }
|
||||
int32_t HAL_GetNumSolenoidChannels(void) { return kNumSolenoidChannels; }
|
||||
int32_t HAL_GetNumPDPModules(void) { return kNumPDPModules; }
|
||||
int32_t HAL_GetNumPDPChannels(void) { return kNumPDPChannels; }
|
||||
int32_t HAL_GetNumCanTalons(void) { return kNumCanTalons; }
|
||||
int32_t HAL_GetNumDutyCycles(void) { return kNumDutyCycles; }
|
||||
int32_t HAL_GetNumAddressableLEDs(void) { return kNumAddressableLEDs; }
|
||||
} // extern "C"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
|
||||
/* 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. */
|
||||
@@ -28,5 +28,6 @@ constexpr int32_t kNumPCMModules = 63;
|
||||
constexpr int32_t kNumSolenoidChannels = 8;
|
||||
constexpr int32_t kNumPDPModules = 63;
|
||||
constexpr int32_t kNumPDPChannels = 16;
|
||||
constexpr int32_t kNumCanTalons = 63;
|
||||
constexpr int32_t kNumDutyCycles = 8;
|
||||
constexpr int32_t kNumAddressableLEDs = 1;
|
||||
} // namespace hal
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
|
||||
/* 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. */
|
||||
@@ -120,6 +120,15 @@ void HAL_SetSolenoid(HAL_SolenoidHandle solenoidPortHandle, HAL_Bool value,
|
||||
|
||||
HALSIM_SetPCMSolenoidOutput(port->module, port->channel, value);
|
||||
}
|
||||
|
||||
void HAL_SetAllSolenoids(int32_t module, int32_t state, int32_t* status) {
|
||||
for (int i = 0; i < kNumSolenoidChannels; i++) {
|
||||
int set = state & 1;
|
||||
HALSIM_SetPCMSolenoidOutput(module, i, set);
|
||||
state >>= 1;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t HAL_GetPCMSolenoidBlackList(int32_t module, int32_t* status) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user