Add more comments, add error checks
parent
2b9d787db4
commit
e774a3f7f9
8
serial
8
serial
|
@ -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
|
|
|
@ -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
|
|
50
src/gmail.rb
50
src/gmail.rb
|
@ -1,7 +1,29 @@
|
||||||
require 'serialport'
|
#!/bin/env ruby
|
||||||
require 'gmail'
|
|
||||||
require 'fileutils'
|
#Check if operating being used it Linux-based
|
||||||
puts File.dirname(__FILE__)
|
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
|
#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")
|
system("bash #{File.dirname(__FILE__)}/detect_serial.sh > serial")
|
||||||
File.open("#{File.dirname(__FILE__)}/serial").each_line do |line|
|
File.open("#{File.dirname(__FILE__)}/serial").each_line do |line|
|
||||||
|
@ -11,14 +33,26 @@ end
|
||||||
#FileUtils.rm("#{File.dirname(__FILE__)}/src/serial")
|
#FileUtils.rm("#{File.dirname(__FILE__)}/src/serial")
|
||||||
|
|
||||||
#Gmail username and password
|
#Gmail username and password
|
||||||
gmail = Gmail.connect("username", "password")
|
gmail = Gmail.connect("your_username", "your_password")
|
||||||
|
|
||||||
#count the number of unread messages
|
#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
|
#Serial port of the Arduino
|
||||||
puts "Arduino is connected to: #{@serial_connection}"
|
unless @serial_connection.size > 0
|
||||||
port_file = @serial_connection.gsub(' ', '')
|
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
|
#this must be same as the baud rate set on the Arduino
|
||||||
#with Serial.begin
|
#with Serial.begin
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
/dev/video0 - Chicony_Electronics_Co._Ltd._TOSHIBA_Web_Camera_-_HD_0x0001
|
/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/event7 - 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/ttyACM2 - TOSHIBA_F5321gw_847A5C4419678500
|
||||||
/dev/ttyACM1 - TOSHIBA_F5321gw_847A5C4419678500
|
/dev/ttyACM1 - TOSHIBA_F5321gw_847A5C4419678500
|
||||||
/dev/ttyACM0 - TOSHIBA_F5321gw_847A5C4419678500
|
/dev/ttyACM0 - TOSHIBA_F5321gw_847A5C4419678500
|
||||||
|
/dev/input/mouse2 - 1ea7_2.4G_Mouse
|
||||||
|
/dev/input/event15 - 1ea7_2.4G_Mouse
|
||||||
|
|
Loading…
Reference in New Issue