From 6f72d8aa07877f53299d43081203cd1f60fffcf8 Mon Sep 17 00:00:00 2001 From: klein panic Date: Sun, 29 Sep 2024 01:16:27 -0400 Subject: [PATCH] initial commit --- arduino_board_list.sh | 10 ++++++++++ board_selection.lua | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100755 arduino_board_list.sh create mode 100644 board_selection.lua diff --git a/arduino_board_list.sh b/arduino_board_list.sh new file mode 100755 index 0000000..b8f6292 --- /dev/null +++ b/arduino_board_list.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +# Search for all possible boards, remove the header, and clean up whitespace lines +arduino-cli board search | tail -n +2 | sed '/^\s*$/d' > /tmp/arduino_boards.txt + +# Ensure the file has the correct permissions for Lua to read +chmod 644 /tmp/arduino_boards.txt + +# Print a message indicating that the process is complete +echo "All possible boards have been listed in /tmp/arduino_boards.txt" diff --git a/board_selection.lua b/board_selection.lua new file mode 100644 index 0000000..aeec224 --- /dev/null +++ b/board_selection.lua @@ -0,0 +1,38 @@ +-- Open the file for reading +local file = io.open("/tmp/arduino_boards.txt", "r") +if not file then + print("Error: Could not open /tmp/arduino_boards.txt") + return +end + +-- Read the file into a table +local boards = {} +for line in file:lines() do + local board_name, fqbn = line:match("^(.-)%s+(%w+:%w+)$") + if board_name and fqbn then + table.insert(boards, { name = board_name, fqbn = fqbn }) + end +end +file:close() + +-- Display the header +print("Available Arduino Boards:") +print("No. Board Name FQBN") +print("---------------------------------------------------------") + +-- Display the list of boards +for i, board in ipairs(boards) do + print(string.format("%-3d %-40s %s", i, board.name, board.fqbn)) +end + +-- Ask the user to choose a board +io.write("Enter the number of the board you want to select: ") +local choice = tonumber(io.read()) + +if choice and boards[choice] then + local selected_board = boards[choice] + print("You selected: " .. selected_board.name) + print("FQBN: " .. selected_board.fqbn) +else + print("Invalid selection.") +end