diff --git a/HalloWing_Tour_Guide/acquiring_fix.bmp b/HalloWing_Tour_Guide/acquiring_fix.bmp new file mode 100644 index 000000000..8263701b3 Binary files /dev/null and b/HalloWing_Tour_Guide/acquiring_fix.bmp differ diff --git a/HalloWing_Tour_Guide/code.py b/HalloWing_Tour_Guide/code.py new file mode 100644 index 000000000..1a3ad396b --- /dev/null +++ b/HalloWing_Tour_Guide/code.py @@ -0,0 +1,156 @@ +""" +HalloWing GPS Tour Guide + +Adafruit invests time and resources providing this open source code. +Please support Adafruit and open source hardware by purchasing +products from Adafruit! + +Written by Dave Astels for Adafruit Industries +Copyright (c) 2018 Adafruit Industries +Licensed under the MIT license. + +All text above must be included in any redistribution. +""" +import time +from math import sin, cos, radians, atan2, sqrt +import board +from digitalio import DigitalInOut, Direction +import displayio +import audioio +import touchio +from busio import UART +import adafruit_gps + +uart = UART(board.TX, board.RX, baudrate=9600, timeout=3000) +gps = adafruit_gps.GPS(uart) + +# Initialize the GPS module by changing what data it sends and at what rate. + +# Turn on the basic GGA and RMC info (what you typically want) +gps.send_command(b'PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0') + +# Set update rate to once a second (1hz) which is what you typically want. +gps.send_command(b'PMTK220,1000') + +touch_1 = touchio.TouchIn(board.TOUCH1) + +audio = audioio.AudioOut(board.A0) + +backlight = DigitalInOut(board.TFT_BACKLIGHT) +backlight.direction = Direction.OUTPUT +backlight.value = False + +splash = displayio.Group() +board.DISPLAY.show(splash) + + +def play_wave(filename): + try: + wave_file = open(filename, "rb") + wave = audioio.WaveFile(wave_file) + audio.play(wave) + while audio.playing: + pass + wave_file.close() + except OSError: + pass + +def show_image(filename): + image_file = None + try: + image_file = open(filename, "rb") + except OSError: + image_file = open("missing.bmp", "rb") + odb = displayio.OnDiskBitmap(image_file) + face = displayio.Sprite(odb, pixel_shader=displayio.ColorConverter(), position=(0, 0)) + backlight.value = False + splash.append(face) + board.DISPLAY.wait_for_frame() + backlight.value = True + + +def distance_between(location_1, location_2): + """Find the distance betweeto a lat/long""" + R = 3959 # radius of Earth in miles + lat1 = location_1[0] + lat2 = location_2[0] + lon1 = location_1[1] + lon2 = location_2[1] + delta_lat = lat2 - lat1 + delta_lon = lon2 - lon1 + + a = sin(delta_lat / 2) * sin(delta_lat / 2) + \ + cos(lat1) * cos(lat2) * \ + sin(delta_lon / 2) * sin(delta_lon / 2) + c = 2 * atan2(sqrt(a), sqrt(1 - a)) + return R * c + + +previous_num = 0 +previous_distance_code = 0 +num = 0 +image = None +name = None +detail = None + +show_image("welcome.bmp") + +# File with place data +# lat,long,image-file,spoken-name-file,detail-file + +while True: + gps.update() + if gps.has_fix: + + # find the closest listed location + here = (radians(gps.latitude), radians(gps.longitude)) + distance = 10000 + with open("locations.txt", "r") as f: + for line in f: + f_num, f_lat, f_lon, f_image, f_name, f_detail = line.split(',') + f_distance = distance_between((radians(float(f_lat)), radians(float(f_lon))), here) + if f_distance < distance: + num, distance, image, name, detail = f_num, f_distance, f_image, f_name, f_detail + + # categorize the distance + if distance < 0.1: + distance_code = 1 + elif distance < 0.5: + distance_code = 2 + elif distance < 1.0: + distance_code = 3 + else: + distance_code = 4 + + # play the name when asked + if touch_1.value: + play_wave(name) + if previous_distance_code == 1 and distance_code == 1 and previous_num == num: + play_wave(detail) + + # update the display if the location or distance category has changed + # if it's relly close, show the image and play the details + if num != previous_num or distance_code != previous_distance_code: + # print("{0} {1} {2} {3: 0.2f} {4} {5} {6}".format(num, f_lat, f_lon, distance, image, name, detail)) + play_wave("computerbeep.wav") + previous_num = num + previous_distance_code = distance_code + if distance_code == 1: + splash.pop() + show_image(image) + play_wave(name) + play_wave(detail) + elif distance_code == 2: + splash.pop() + show_image("green_circle.bmp") + elif distance_code == 3: + splash.pop() + show_image("yellow_circle.bmp") + else: + splash.pop() + show_image("red_circle.bmp") + else: + splash.pop() + show_image("acquiring_fix.bmp") + + time.sleep(0.25) diff --git a/HalloWing_Tour_Guide/computerbeep.wav b/HalloWing_Tour_Guide/computerbeep.wav new file mode 100644 index 000000000..7d478428a Binary files /dev/null and b/HalloWing_Tour_Guide/computerbeep.wav differ diff --git a/HalloWing_Tour_Guide/covent_garden.bmp b/HalloWing_Tour_Guide/covent_garden.bmp new file mode 100644 index 000000000..3c547eae2 Binary files /dev/null and b/HalloWing_Tour_Guide/covent_garden.bmp differ diff --git a/HalloWing_Tour_Guide/covent_garden_detail.wav b/HalloWing_Tour_Guide/covent_garden_detail.wav new file mode 100644 index 000000000..e689ad528 Binary files /dev/null and b/HalloWing_Tour_Guide/covent_garden_detail.wav differ diff --git a/HalloWing_Tour_Guide/covent_garden_name.wav b/HalloWing_Tour_Guide/covent_garden_name.wav new file mode 100644 index 000000000..5d7f2380c Binary files /dev/null and b/HalloWing_Tour_Guide/covent_garden_name.wav differ diff --git a/HalloWing_Tour_Guide/green_circle.bmp b/HalloWing_Tour_Guide/green_circle.bmp new file mode 100644 index 000000000..f91952c5a Binary files /dev/null and b/HalloWing_Tour_Guide/green_circle.bmp differ diff --git a/HalloWing_Tour_Guide/harriston.bmp b/HalloWing_Tour_Guide/harriston.bmp new file mode 100644 index 000000000..04e5524de Binary files /dev/null and b/HalloWing_Tour_Guide/harriston.bmp differ diff --git a/HalloWing_Tour_Guide/harriston_detail.wav b/HalloWing_Tour_Guide/harriston_detail.wav new file mode 100644 index 000000000..c521388eb Binary files /dev/null and b/HalloWing_Tour_Guide/harriston_detail.wav differ diff --git a/HalloWing_Tour_Guide/harriston_name.wav b/HalloWing_Tour_Guide/harriston_name.wav new file mode 100644 index 000000000..487ac92ed Binary files /dev/null and b/HalloWing_Tour_Guide/harriston_name.wav differ diff --git a/HalloWing_Tour_Guide/locations.txt b/HalloWing_Tour_Guide/locations.txt new file mode 100644 index 000000000..9dc11ff91 --- /dev/null +++ b/HalloWing_Tour_Guide/locations.txt @@ -0,0 +1,3 @@ +1,42.985201,-81.254900,harriston.bmp,harriston_name.wav,harriston_detail.wav +2,42.982640,-81.250504,covent_garden.bmp,covent_garden_name.wav,covent_garden_detail.wav +3,42.988451,-81.254250,los_lobos.bmp,los_lobos_name.wav,los_lobos_detail.wav diff --git a/HalloWing_Tour_Guide/los_lobos.bmp b/HalloWing_Tour_Guide/los_lobos.bmp new file mode 100644 index 000000000..3cd1a8af0 Binary files /dev/null and b/HalloWing_Tour_Guide/los_lobos.bmp differ diff --git a/HalloWing_Tour_Guide/los_lobos_detail.wav b/HalloWing_Tour_Guide/los_lobos_detail.wav new file mode 100644 index 000000000..5c4befb39 Binary files /dev/null and b/HalloWing_Tour_Guide/los_lobos_detail.wav differ diff --git a/HalloWing_Tour_Guide/los_lobos_name.wav b/HalloWing_Tour_Guide/los_lobos_name.wav new file mode 100644 index 000000000..39d5ba905 Binary files /dev/null and b/HalloWing_Tour_Guide/los_lobos_name.wav differ diff --git a/HalloWing_Tour_Guide/missing.bmp b/HalloWing_Tour_Guide/missing.bmp new file mode 100644 index 000000000..fc10004ad Binary files /dev/null and b/HalloWing_Tour_Guide/missing.bmp differ diff --git a/HalloWing_Tour_Guide/red_circle.bmp b/HalloWing_Tour_Guide/red_circle.bmp new file mode 100644 index 000000000..55196384c Binary files /dev/null and b/HalloWing_Tour_Guide/red_circle.bmp differ diff --git a/HalloWing_Tour_Guide/welcome.bmp b/HalloWing_Tour_Guide/welcome.bmp new file mode 100644 index 000000000..7e9683e11 Binary files /dev/null and b/HalloWing_Tour_Guide/welcome.bmp differ diff --git a/HalloWing_Tour_Guide/yellow_circle.bmp b/HalloWing_Tour_Guide/yellow_circle.bmp new file mode 100644 index 000000000..7843b9901 Binary files /dev/null and b/HalloWing_Tour_Guide/yellow_circle.bmp differ