Skip to content

Commit

Permalink
Updated packet sending code. Added match state
Browse files Browse the repository at this point in the history
  • Loading branch information
SebZanardo committed Mar 11, 2024
1 parent 1a854d2 commit 60e6350
Showing 1 changed file with 30 additions and 17 deletions.
47 changes: 30 additions & 17 deletions components/led_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class LEDPanel:
}

def __init__(self) -> None:
# custom packet: 0, 000, 0000
# match state, led status, match id
# Custom packet: 00 000000
# match state, state specific information
self.packet = 0b00000000
self.panel_port = wpilib.SerialPort(
baudRate=9600, port=wpilib.SerialPort.Port.kUSB2, dataBits=8
Expand All @@ -22,6 +22,19 @@ def __init__(self) -> None:
def send_packet(self) -> None:
self.panel_port.write(self.packet.to_bytes())

def set_match_state(self) -> None:
self.packet &= 0b00111111

if wpilib.DriverStation.isAutonomous() or wpilib.DriverStation.isTeleop():
# During
self.packet |= 0b01 << 6
elif wpilib.DriverStation.getMatchTime() <= 0:
# Post match
self.packet |= 0b10 << 6
else:
# Pre match
self.packet |= 0b00 << 6

def set_match_id(self) -> None:
match_type = wpilib.DriverStation.getMatchType()
match_id = 0
Expand All @@ -30,45 +43,45 @@ def set_match_id(self) -> None:
or match_type == wpilib.DriverStation.MatchType.kElimination
):
match_id = self.matches[wpilib.DriverStation.getMatchNumber()]
# Can't be greater than 15 as it is sent as 4bits
# Can't be greater than 15
match_id = max(match_id, 15)

self.packet |= match_id
self.send_packet()

def no_note(self) -> None:
self.packet &= 0b10001111
self.packet &= 0b11000000
self.send_packet()

def intake_deployed(self) -> None:
self.packet &= 0b10001111
self.packet |= 0b001 << 4
self.packet &= 0b11000000
self.packet |= 0b001
self.send_packet()

def in_range(self) -> None:
self.packet &= 0b10001111
self.packet |= 0b010 << 4
self.packet &= 0b11000000
self.packet |= 0b010
self.send_packet()

def not_in_range(self) -> None:
self.packet &= 0b10001111
self.packet |= 0b011 << 4
self.packet &= 0b11000000
self.packet |= 0b011
self.send_packet()

def climbing_arm_extending(self) -> None:
self.packet &= 0b10001111
self.packet |= 0b100 << 4
self.packet &= 0b11000000
self.packet |= 0b100
self.send_packet()

def climbing_arm_fully_extended(self) -> None:
self.packet &= 0b10001111
self.packet |= 0b101 << 4
self.packet &= 0b11000000
self.packet |= 0b101
self.send_packet()

def climbing_arm_retracted(self) -> None:
self.packet &= 0b10001111
self.packet |= 0b110 << 4
self.packet &= 0b11000000
self.packet |= 0b110
self.send_packet()

def execute(self) -> None:
pass
self.set_match_state()

0 comments on commit 60e6350

Please sign in to comment.