Skip to content

Commit

Permalink
Set match_id section of packet scaffold
Browse files Browse the repository at this point in the history
  • Loading branch information
SebZanardo committed Mar 10, 2024
1 parent 143dc6f commit 1a854d2
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions components/led_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,40 @@


class LEDPanel:
# Key: Match number, Value: Drop Bears match number (<=15)
# TODO: Fill with proper values when the draw comes out
matches: dict[int, int] = {
1: 1,
2: 2,
3: 3,
}

def __init__(self) -> None:
# custom packet: 0, 000, 0000
# match state, led status, match id
self.packet = 0b00000000
self.panel_port = wpilib.SerialPort(
baudRate=9600, port=wpilib.SerialPort.Port.kUSB2, dataBits=8
)
self.set_match_id()

def send_packet(self) -> None:
self.panel_port.write(self.packet.to_bytes())

def set_match_id(self) -> None:
match_type = wpilib.DriverStation.getMatchType()
match_id = 0
if (
match_type == wpilib.DriverStation.MatchType.kQualification
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
match_id = max(match_id, 15)

self.packet |= match_id
self.send_packet()

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

0 comments on commit 1a854d2

Please sign in to comment.