7
mirror of https://github.com/tenderlove/initial-v.git synced 2025-04-07 18:05:08 +00:00

some scripts

This commit is contained in:
Aaron Patterson 2023-02-11 15:08:38 -08:00
parent 893335eacb
commit e8c6c03ade
No known key found for this signature in database
GPG Key ID: 953170BCB4FFAFC6
2 changed files with 79 additions and 0 deletions

60
firmware/ctrl.rb Executable file
View File

@ -0,0 +1,60 @@
#!/Users/aaron/.rubies/arm64/ruby-trunk/bin/ruby
require "myhidapi"
class Handle
NONE = 0
BACKLIGHT = 1
RESET = 2
DRIVE = 3
NEUTRAL = 4
REVERSE = 5
PARK = 6
def initialize
devices = MyHIDAPI.enumerate 0x0, 0x0
dev = devices.find { |dev|
if dev.product_string =~ /Initial/i
p dev
end
dev.product_string =~ /Initial/i && dev.usage == 0x61
}
@handle = dev.open
100.times do
break if @handle
@handle = dev.open
end
raise "Couldn't connect" unless @handle
end
def reset!; send_command RESET; end
def drive!; send_command DRIVE; end
def neutral!; send_command NEUTRAL; end
def reverse!; send_command REVERSE; end
def park!; send_command PARK; end
def backlight!; send_command BACKLIGHT; end
private
def send_command cmd, param = nil
buf = [0x0, cmd, param].compact
loop do
break if @handle.write buf.pack('C*')
end
end
end
if __FILE__ == $0
handle = Handle.new
cmd = ARGV[0] || "reset"
case cmd
when "reset"
handle.reset!
sleep 1
handle.backlight!
when "drive" then handle.drive!
when "neutral" then handle.neutral!
when "park" then handle.park!
when "reverse" then handle.reverse!
end
end

19
firmware/reset.rb Normal file
View File

@ -0,0 +1,19 @@
require "uchip/mcp2221"
# Find the first connected chip
chip = UChip::MCP2221.first || raise("Couldn't find the chip!")
p chip.gpio_value 0
p chip.gpio_value 1
chip.set_gpio_value 0, 0
chip.set_gpio_value 1, 0
chip.set_gpio_value 0, 1
chip.set_gpio_value 1, 0
chip.set_gpio_value 0, 0
chip.set_gpio_value 1, 1
chip.set_gpio_value 0, 0
chip.set_gpio_value 1, 0