-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
95 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/main/java/frc/robot/subsystems/internals/ColorSensorThread.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package frc.robot.subsystems.internals; | ||
|
||
import com.revrobotics.ColorSensorV3; | ||
|
||
import edu.wpi.first.wpilibj.util.Color; | ||
|
||
public class ColorSensorThread { | ||
private ColorSensorRunnable runnable; | ||
|
||
public ColorSensorThread(ColorSensorV3 storage, ColorSensorV3 staging) { | ||
this.runnable = new ColorSensorRunnable(storage, staging); | ||
|
||
Thread thread = new Thread(runnable); | ||
thread.setDaemon(true); | ||
thread.start(); | ||
} | ||
|
||
public Color getLastStorage() { | ||
return runnable.lastStorage; | ||
} | ||
|
||
public Color getLastStaging() { | ||
return runnable.lastStaging; | ||
} | ||
|
||
class ColorSensorRunnable implements Runnable { | ||
ColorSensorV3 storage; | ||
ColorSensorV3 staging; | ||
|
||
Color lastStorage; | ||
Color lastStaging; | ||
|
||
public ColorSensorRunnable(ColorSensorV3 storage, ColorSensorV3 staging) { | ||
this.storage = storage; | ||
this.staging = staging; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
// TODO Auto-generated method stub | ||
while (true) { | ||
this.lastStorage = storage.getColor(); | ||
this.lastStaging = staging.getColor(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters