File tree Expand file tree Collapse file tree 2 files changed +50
-7
lines changed
src/main/java/org/strykeforce/thirdcoast/util Expand file tree Collapse file tree 2 files changed +50
-7
lines changed Original file line number Diff line number Diff line change @@ -2,13 +2,13 @@ plugins {
22 id " java"
33 id " idea"
44 id " maven-publish"
5- id " org.jetbrains.kotlin.jvm" version " 1.3.70 "
5+ id " org.jetbrains.kotlin.jvm" version " 1.3.61 "
66 id " org.jetbrains.kotlin.kapt" version " 1.3.61"
7- id " edu.wpi.first.GradleRIO" version " 2020.3 .2"
7+ id " edu.wpi.first.GradleRIO" version " 2020.1 .2"
88}
99
1010group = ' org.strykeforce'
11- version = ' 20.3.2 '
11+ version = ' 20.4.1 '
1212
1313sourceCompatibility = JavaVersion . VERSION_11
1414targetCompatibility = JavaVersion . VERSION_11
@@ -58,10 +58,6 @@ java {
5858 withSourcesJar()
5959}
6060
61- test {
62- useJUnitPlatform()
63- }
64-
6561idea {
6662 module {
6763 downloadJavadoc = true
Original file line number Diff line number Diff line change 1+ package org .strykeforce .thirdcoast .util ;
2+
3+ import edu .wpi .first .wpilibj .DigitalInput ;
4+
5+ import java .util .ArrayList ;
6+ import java .util .List ;
7+
8+ public class AutonSwitch {
9+
10+ private final List <DigitalInput > digitalInputs ;
11+
12+ /**
13+ * Construct with the specified digital inputs.
14+ *
15+ * @param digitalInputs - in order from least to most significant bits.
16+ */
17+ public AutonSwitch (List <DigitalInput > digitalInputs ) {
18+ this .digitalInputs = digitalInputs ;
19+ }
20+
21+ /**
22+ * Construct with digital inputs starting with DIO channel 0
23+ *
24+ * @param bits - number of digital inputs
25+ */
26+ public AutonSwitch (int bits ) {
27+ List <DigitalInput > digitalInputs = new ArrayList <>(bits );
28+ for (int i = 0 ; i < bits ; i ++) {
29+ digitalInputs .add (new DigitalInput (i ));
30+ }
31+ this .digitalInputs = digitalInputs ;
32+ }
33+
34+ /**
35+ * Read switch value.
36+ *
37+ * @return numeric value of switch
38+ */
39+ public int position () {
40+ int val = 0 ;
41+ for (int i = digitalInputs .size (); i -- > 0 ; ) {
42+ val = val << 1 ;
43+ val = (val & 0xFE ) | (digitalInputs .get (i ).get () ? 0 : 1 );
44+ }
45+ return val ;
46+ }
47+ }
You can’t perform that action at this time.
0 commit comments