Add more comments, add error checks

master
Marvin Johanning 2018-07-11 11:26:00 +02:00
parent 2b9d787db4
commit e774a3f7f9
4 changed files with 46 additions and 32 deletions

8
serial
View File

@ -1,8 +0,0 @@
/dev/video0 - Chicony_Electronics_Co._Ltd._TOSHIBA_Web_Camera_-_HD_0x0001
/dev/input/event12 - Chicony_Electronics_Co._Ltd._TOSHIBA_Web_Camera_-_HD_0x0001
/dev/input/mouse2 - 1ea7_2.4G_Mouse
/dev/input/event15 - 1ea7_2.4G_Mouse
/dev/ttyACM4 - Arduino__www.arduino.cc__0043_75735323230351F09102
/dev/ttyACM2 - TOSHIBA_F5321gw_847A5C4419678500
/dev/ttyACM1 - TOSHIBA_F5321gw_847A5C4419678500
/dev/ttyACM0 - TOSHIBA_F5321gw_847A5C4419678500

View File

@ -1,11 +0,0 @@
#!/bin/bash
for sysdevpath in $(find /sys/bus/usb/devices/usb*/ -name dev); do
(
syspath="${sysdevpath%/dev}"
devname="$(udevadm info -q name -p $syspath)"
[[ "$devname" == "bus/"* ]] && continue
eval "$(udevadm info -q property --export -p $syspath)"
[[ -z "$ID_SERIAL" ]] && continue
echo "/dev/$devname - $ID_SERIAL"
)
done

View File

@ -1,24 +1,58 @@
require 'serialport'
require 'gmail'
require 'fileutils'
puts File.dirname(__FILE__)
#!/bin/env ruby
#Check if operating being used it Linux-based
unless /linux/ =~ RUBY_PLATFORM then
puts "ERROR: Only Linux-based operating systems are currently supported"
exit
end
#Requiring all the different gems
gems = ['serialport', 'gmail', 'fileutils', 'colorize', 'socket']
gems.each do |gem|
require gem
end
#Checking internet connection to google.com (pinging it)
begin
TCPSocket.new 'google.com', 443
rescue SocketError
puts "ERROR: ".colorize(:red) + "The program was unable to find an active internet connection. " \
"Please check your internet connection and try again"
exit
end
#Create string to hold the Arduino's serial connection
@serial_connection = String.new
#Start the bash file, read the file it creates and find out what port the Arduino is connected to
system("bash #{File.dirname(__FILE__)}/detect_serial.sh > serial")
File.open("#{File.dirname(__FILE__)}/serial").each_line do |line|
@serial_connection = line.slice(0..(line.index(' '))) if line.include?("Arduino")
@serial_connection = line.slice(0..(line.index(' '))) if line.include?("Arduino")
end
#FileUtils.rm("#{File.dirname(__FILE__)}/src/serial")
#Gmail username and password
gmail = Gmail.connect("username", "password")
gmail = Gmail.connect("your_username", "your_password")
#count the number of unread messages
prev_unread = gmail.inbox.count(:unread)
begin
prev_unread = gmail.inbox.count(:unread)
rescue Net::IMAP::BadResponseError
puts "ERROR: ".colorize(:red) + "Connecting to your Gmail account has failed (NET::IMAP::BadResponseError)\n" \
"Please ensure that you have entered your correct username and password (refer to README for further details)"
exit
end
#Serial port of the Arduino
puts "Arduino is connected to: #{@serial_connection}"
port_file = @serial_connection.gsub(' ', '')
unless @serial_connection.size > 0
puts "ERROR: ".colorize(:red) + "No Arduino has been found connected to your computer\n" \
"Please check if your Arduino is working and has been properly connected"
exit
else
puts "Arduino is connected to: #{@serial_connection}"
port_file = @serial_connection.gsub(' ', '')
end
#this must be same as the baud rate set on the Arduino
#with Serial.begin

View File

@ -1,8 +1,7 @@
/dev/video0 - Chicony_Electronics_Co._Ltd._TOSHIBA_Web_Camera_-_HD_0x0001
/dev/input/event12 - Chicony_Electronics_Co._Ltd._TOSHIBA_Web_Camera_-_HD_0x0001
/dev/input/mouse2 - 1ea7_2.4G_Mouse
/dev/input/event15 - 1ea7_2.4G_Mouse
/dev/ttyACM4 - Arduino__www.arduino.cc__0043_75735323230351F09102
/dev/input/event7 - Chicony_Electronics_Co._Ltd._TOSHIBA_Web_Camera_-_HD_0x0001
/dev/ttyACM2 - TOSHIBA_F5321gw_847A5C4419678500
/dev/ttyACM1 - TOSHIBA_F5321gw_847A5C4419678500
/dev/ttyACM0 - TOSHIBA_F5321gw_847A5C4419678500
/dev/input/mouse2 - 1ea7_2.4G_Mouse
/dev/input/event15 - 1ea7_2.4G_Mouse