Skip to content

Commit

Permalink
Merge branch 'wcmp' of https://github.com/FRC2713/Robot2024 into wcmp
Browse files Browse the repository at this point in the history
  • Loading branch information
RHR2713 committed May 15, 2024
2 parents a59a2f8 + ac034ba commit 01670d6
Show file tree
Hide file tree
Showing 8 changed files with 269 additions and 8 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/gen_controls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle

name: Generate Controls PDF

on:
push:

permissions:
contents: read

jobs:
gen_controls:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r scripts/requirements.txt
- name: Generate Controls PDF
run: |
python scripts/gen_controls.py
- name: Upload Controls PDF 1
uses: actions/upload-artifact@v2
with:
name: 1_buttons-pdf
path: scripts/1_buttons.pdf
- name: Upload Controls PDF 2
uses: actions/upload-artifact@v2
with:
name: 2_buttons-pdf
path: scripts/2_buttons.pdf
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ simgui-ds.json
.glass/glass.json
.Glass/glass.json

/sim-logs/*
!/sim-logs/.gitkeep


# This gitignore has been specially created by the WPILib team.
# If you remove items from this file, intellisense might break.
Expand Down Expand Up @@ -184,3 +187,5 @@ logs/

# Folder that has CTRE Phoenix Sim device config storage
ctre_sim/
scripts/1_buttons.pdf
scripts/2_buttons.pdf
93 changes: 93 additions & 0 deletions scripts/gen_controls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import os
import re
import json
from reportlab.lib.utils import ImageReader
from reportlab.pdfgen import canvas
from PIL import Image

file_path = os.path.split(os.path.realpath(__file__))[0] + '/'


def extract_comments(text):
pattern = r'/\*RHRXBox\s*\n\s*\*Type:\s*(\d+)\s*\n\s*\*Btn:\s*(\d+)\s*\n\s*\*Desc:\s*(.*?)\*/'
comments = re.findall(pattern, text, re.DOTALL)
return [{'type': int(comment[0]), 'btn': int(comment[1].strip()), 'desc': comment[2].strip()} for comment in
comments]


def open_file():
java_file_path = file_path + '../src/main/java/frc/robot/Robot.java'
with open(java_file_path, 'r') as file:
java_code = file.read()

comments = extract_comments(java_code)
print(json.dumps(comments, indent=4))
return comments


def get_text_location(btn):
height = 753
if btn == 1:
return 783, height - 300
if btn == 2:
return 850, height - 230
if btn == 3:
return 700, height - 200
if btn == 4:
return 783, height - 150
if btn == 5:
return 201, 675
if btn == 6:
return 700, 675
if btn == 7:
return 400, height - 240
if btn == 8:
return 550, height - 240
if btn == 9:
return 24, height - 30
if btn == 10:
return 900, height - 30
if btn == 21:
return 320, height - 350
if btn == 23:
return 320, height - 450
if btn == 31:
return 181, height - 250
if btn == 32:
return 625, height - 400
return 100, 100


def draw_text(c, btn, text):
textobject = c.beginText(*get_text_location(btn))
textobject.setFont("Helvetica", 30, leading=None)
textobject.setFillColor((225, 0, 0))
textobject.textLine(text)
c.drawText(textobject)


def to_pdf(btns, type_id):
controller_image = Image.open(file_path + "xbox" + str(type_id) + ".png")

reportlab_pil_img = ImageReader(controller_image)

# Create a PDF canvas
c = canvas.Canvas(file_path + str(type_id) + "_buttons.pdf", pagesize=(1110, 753))
c.drawImage(reportlab_pil_img, 0, 0, width=1110, height=753)

for btn in btns:
draw_text(c, btn['btn'], btn['desc'])

c.save()


def main():
cmds = open_file()
cmds_driver = [cmd for cmd in cmds if cmd['type'] == 1]
cmds_operator = [cmd for cmd in cmds if cmd['type'] == 2]
to_pdf(cmds_driver, 1)
to_pdf(cmds_operator, 2)


if __name__ == "__main__":
main()
2 changes: 2 additions & 0 deletions scripts/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
reportlab~=3.6.8
Pillow~=10.1.0
Binary file added scripts/xbox1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added scripts/xbox2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file added sim-logs/.gitkeep
Empty file.
Loading

0 comments on commit 01670d6

Please sign in to comment.