diff --git a/serial b/serial new file mode 100644 index 0000000..744c00a --- /dev/null +++ b/serial @@ -0,0 +1,8 @@ +/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 diff --git a/src/detect_serial.sh b/src/detect_serial.sh new file mode 100644 index 0000000..c733fe1 --- /dev/null +++ b/src/detect_serial.sh @@ -0,0 +1,11 @@ +#!/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 diff --git a/src/detectserial.sh b/src/detectserial.sh new file mode 100644 index 0000000..c733fe1 --- /dev/null +++ b/src/detectserial.sh @@ -0,0 +1,11 @@ +#!/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 diff --git a/src/gmail.rb b/src/gmail.rb new file mode 100644 index 0000000..239936d --- /dev/null +++ b/src/gmail.rb @@ -0,0 +1,58 @@ +require 'serialport' +require 'gmail' +require 'fileutils' +puts File.dirname(__FILE__) +#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") +end + +#FileUtils.rm("#{File.dirname(__FILE__)}/src/serial") + +#Gmail username and password +gmail = Gmail.connect("username", "password") + +#count the number of unread messages +prev_unread = gmail.inbox.count(:unread) + +#Serial port of the Arduino +puts "Arduino is connected to: #{@serial_connection}" +port_file = @serial_connection.gsub(' ', '') + +#this must be same as the baud rate set on the Arduino +#with Serial.begin +baud_rate = 9600 + +data_bits = 8 +stop_bits = 1 +parity = SerialPort::NONE + +#create a SerialPort object using each of the bits of information +port = SerialPort.new(port_file, baud_rate, data_bits, stop_bits, parity) + +wait_time = 4 + +#for an infinite amount of time +loop do + #get the number of unread messages in the inbox + unread = gmail.inbox.count(:unread) + + #lets us know that we've checked the unread messages + puts "Checked unread." + + #check if the number of unread messages has increased + if unread > prev_unread + #Write the subject of the last unread email to the serial port + port.write gmail.inbox.find(:unread).last.subject + + #For debugging purposes + puts "Received email: \n" + gmail.inbox.find(:unread).last.subject + end + + #reset the number of unread emails + prev_unread = unread + + #wait before we make another request to the Gmail servers + sleep wait_time +end diff --git a/src/main.cpp b/src/main.cpp index de7b395..113116c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,9 +1,58 @@ #include +#include +#include + +LiquidCrystal lcd(7, 8, 9, 10, 11, 12); +String incomingString = ""; +int buzzer = 2; void setup() { - // put your setup code here, to run once: + Serial.begin(9600); + lcd.begin(16, 2); + pinMode(buzzer, OUTPUT); +} + +void notifingBeep() { + unsigned char i; + for(i=0;i<50;i++) { + digitalWrite(buzzer, HIGH); + delay(10); + digitalWrite(buzzer, LOW); + delay(10); + } +} + +void got_email(String subject) { + + //Initial two beeps to alert user to incoming email + notifingBeep(); + delay(200); + notifingBeep(); + + lcd.setCursor(0, 0); + lcd.print("You've got mail!"); + delay(5000); + + int str_len = subject.length() + 1; + char char_array[str_len]; + subject.toCharArray(char_array, str_len); + unsigned int i; + + lcd.clear(); + lcd.setCursor(16, 1); + lcd.autoscroll(); + for (i = 0; i < sizeof(char_array) - 1; i++){ + lcd.print(char_array[i]); + delay(500); + } + + //Last beep to inform user of end of email + notifingBeep(); } void loop() { - // put your main code here, to run repeatedly: -} \ No newline at end of file + if(Serial.available() > 0) { + incomingString = Serial.readString(); + got_email(incomingString); + } +} diff --git a/src/serial b/src/serial new file mode 100644 index 0000000..744c00a --- /dev/null +++ b/src/serial @@ -0,0 +1,8 @@ +/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 diff --git a/start b/start new file mode 100755 index 0000000..ebfaa85 --- /dev/null +++ b/start @@ -0,0 +1,3 @@ +#!/bin/env ruby + +load "#{File.dirname(__FILE__)}/src/gmail.rb"