Change indentation
parent
d57eeea7b1
commit
f9affe4641
36
src/gmail.rb
36
src/gmail.rb
|
@ -27,7 +27,7 @@ end
|
||||||
#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|
|
||||||
@serial_connection = line.slice(0..(line.index(' '))) if line.include?("Arduino")
|
@serial_connection = line.slice(0..(line.index(' '))) if line.include?("Arduino")
|
||||||
end
|
end
|
||||||
|
|
||||||
#FileUtils.rm("#{File.dirname(__FILE__)}/src/serial")
|
#FileUtils.rm("#{File.dirname(__FILE__)}/src/serial")
|
||||||
|
@ -69,24 +69,24 @@ wait_time = 4
|
||||||
|
|
||||||
#for an infinite amount of time
|
#for an infinite amount of time
|
||||||
loop do
|
loop do
|
||||||
#get the number of unread messages in the inbox
|
#get the number of unread messages in the inbox
|
||||||
unread = gmail.inbox.count(:unread)
|
unread = gmail.inbox.count(:unread)
|
||||||
|
|
||||||
#lets us know that we've checked the unread messages
|
#lets us know that we've checked the unread messages
|
||||||
puts "Checked unread."
|
puts "Checked unread."
|
||||||
|
|
||||||
#check if the number of unread messages has increased
|
#check if the number of unread messages has increased
|
||||||
if unread > prev_unread
|
if unread > prev_unread
|
||||||
#Write the subject of the last unread email to the serial port
|
#Write the subject of the last unread email to the serial port
|
||||||
port.write gmail.inbox.find(:unread).last.subject
|
port.write gmail.inbox.find(:unread).last.subject
|
||||||
|
|
||||||
#For debugging purposes
|
#For debugging purposes
|
||||||
puts "Received email: \n" + gmail.inbox.find(:unread).last.subject
|
puts "Received email: \n" + gmail.inbox.find(:unread).last.subject
|
||||||
end
|
end
|
||||||
|
|
||||||
#reset the number of unread emails
|
#reset the number of unread emails
|
||||||
prev_unread = unread
|
prev_unread = unread
|
||||||
|
|
||||||
#wait before we make another request to the Gmail servers
|
#wait before we make another request to the Gmail servers
|
||||||
sleep wait_time
|
sleep wait_time
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue