From 77f8704f96e7788914d02e37019901f0645a69d2 Mon Sep 17 00:00:00 2001 From: Tyler Spadgenske Date: Sun, 31 May 2015 12:07:53 +0000 Subject: [PATCH] Removed warnings, added config file for audio, and made logs and configure directories generate automatic --- README.md | 13 ++++++++----- apps/message/message.py | 22 ++++++++++++++++++--- apps/settings/settings.py | 30 ++++++++++++++++++++++++++++ src/framebuffer.py | 10 +++++++--- src/main.py | 41 ++++++++++++++++++++++++++++++++++----- 5 files changed, 100 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 2664065..0a28800 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,16 @@ # TYOS -0.3.7 Beta +0.4.9 Beta
A mobile operating system for the tyfone. -copyright (c) 2015 Tyler Spadgenske +copyright :copyright: 2015 Tyler Spadgenske ##Installation and Setup Follow the guide at:
http://instructables.com/id/Build-Your-Own-Smartphone/
-##Developers -TYOS is now in Beta! Developing your own apps is as easy as pi. Check out the -docs at https://github.com/spadgenske/tyos/wiki +##Docs +Check out the docs at https://github.com/spadgenske/tyos/wiki + +##Update +To update your version of TYOS do so here:
+https://github.com/spadgenske/TYOS/releases diff --git a/apps/message/message.py b/apps/message/message.py index 835e027..c827505 100644 --- a/apps/message/message.py +++ b/apps/message/message.py @@ -5,7 +5,7 @@ #To be packaged with stock TYOS# ################################ -import pygame, time +import pygame, time, os from pygame.locals import * class Run(): @@ -142,13 +142,29 @@ def load_contacts(self): try: contact_file = open('/home/pi/tyos/configure/contacts.conf', 'r') except: + print '***********************************************************' print 'NO CONTACTS FOUND' - print 'PLEASE CREATE /home/pi/tyos/configure/contacts.conf FILE' + print 'PLEASE EDIT /home/pi/tyos/configure/contacts.conf FILE' + print '***********************************************************' + if not os.path.exists('/home/pi/tyos/configure'): + os.mkdir('/home/pi/tyos/configure') + if not os.path.exists('/home/pi/tyos/logs'): + os.mkdir('/home/pi/tyos/logs') #May be in wrong spot, but it works + contact_file = open('/home/pi/tyos/configure/contacts.conf', 'w+') + contact_file.write('#Contacts\n') + contact_file.write('#Use format name=number i.e. Joe=1555666777 # are comments\n') + contact_file.close() + contact_file = open('/home/pi/tyos/configure/contacts.conf', 'r') self.contact_list = contact_file.readlines() contact_file.close() + for i in range(0, len(self.contact_list)): - self.contact_list[i] = self.contact_list[i].rstrip().split('=') + if self.contact_list[i][0] == '#': + pass + #Do Nothing. Line is comment + else: + self.contact_list[i] = self.contact_list[i].rstrip().split('=') def on_first_run(self): self.first = False diff --git a/apps/settings/settings.py b/apps/settings/settings.py index 2f07e1c..967fb98 100644 --- a/apps/settings/settings.py +++ b/apps/settings/settings.py @@ -13,6 +13,7 @@ class Run(): def __init__(self, fona): self.fona = fona self.headset = False + self.get_audio_mode() #Setup colors self.RED = (255,0,0) self.GREEN = (0,255,0) @@ -38,8 +39,37 @@ def __init__(self, fona): self.exit = False self.blit_one_surface = {'surface':[], 'rects':[]} self.blit = {'surfaces':[self.menu, self.fona_power, self.off], 'rects':[self.menu_rect, self.fona_power_rect, self.rect]} + + #Set audio mode text + if self.headset: + self.blit['surfaces'][2] = self.on + else: + self.blit['surfaces'][2] = self.off + self.next_app = None + def get_audio_mode(self): + audio_config = open('/home/pi/tyos/configure/audio.conf', 'r') + file = audio_config.readlines() + + for i in range(0, len(file)):#Parse file + if file[i][0] == '#': + pass + #Do Nothing. Line is comment + else: + file[i] = file[i].rstrip() + if 'mode' in file[i]: #Extract audio mode: 1=Built in, 0=External + mode = file[i] + + mode = mode.split('=') + self.mode = int(mode[1]) + + if self.mode == 1: + self.headset = False + else: + self.headset = True + + def run_app(self): pass diff --git a/src/framebuffer.py b/src/framebuffer.py index d1a0de7..58bcda1 100644 --- a/src/framebuffer.py +++ b/src/framebuffer.py @@ -3,6 +3,7 @@ import time import random +DEBUG = False class pyscope : screen = None; @@ -16,7 +17,8 @@ def __init__(self): # http://www.karoltomala.com/blog/?p=679 disp_no = os.getenv("DISPLAY") if disp_no: - print "I'm running under X display = {0}".format(disp_no) + if DEBUG: + print "I'm running under X display = {0}".format(disp_no) # Check which frame buffer drivers are available # Start with fbcon since directfb hangs with composite output @@ -29,7 +31,8 @@ def __init__(self): try: pygame.display.init() except pygame.error: - print 'Driver: {0} failed.'.format(driver) + if DEBUG: + print 'Driver: {0} failed.'.format(driver) continue found = True break @@ -38,7 +41,8 @@ def __init__(self): raise Exception('No suitable video driver found!') size = (pygame.display.Info().current_w, pygame.display.Info().current_h) - print "Framebuffer size: %d x %d" % (size[0], size[1]) + if DEBUG: + print "Framebuffer size: %d x %d" % (size[0], size[1]) self.screen = pygame.display.set_mode(size, pygame.FULLSCREEN) # Clear the screen to start self.screen.fill((0, 0, 0)) diff --git a/src/main.py b/src/main.py index 0e8bc35..c459dd5 100644 --- a/src/main.py +++ b/src/main.py @@ -8,18 +8,19 @@ If FONA is already on, just run sudo python /home/pi/tyos/src/main.py Upgrade: To check for updates go to https://github.com/spadgenske/TYOS/releases/latest and compare the version number with your -current version of TYOS. If higher, you can update. To your version of TYOS run the command +current version of TYOS. If higher, you can update. To get your version of TYOS run the command sudo python /home/pi/tyos/src/main.py --version ''' -VERSION = '0.3.7' +VERSION = '0.4.9' -import pygame, sys, os, time, datetime, traceback +import pygame, sys, os, time, datetime, traceback, warnings from pygame.locals import * import framebuffer, toolbar, apps, serialport, receive class tyos(): def __init__(self): + warnings.filterwarnings("ignore") for arg in sys.argv: if arg == '--power': self.POWER_FONA = True @@ -39,8 +40,8 @@ def __init__(self): #Setup fona self.fona = serialport.SerialPort() self.fona.connect() - #Set audio in/out to speaker and microphone - self.fona.transmit('AT+CHFA=1') + + self.set_audio() #Setup some important objects self.scope = framebuffer.pyscope() @@ -109,6 +110,36 @@ def __init__(self): self.blit_logo = True self.dead_bat = False + + def set_audio(self): + #Set audio in/out to selected from config file + try: #See if config file exists + self.audio_file = open('/home/pi/tyos/configure/audio.conf', 'r') + except: + if not os.path.exists('/home/pi/tyos/configure'):#If configure directory doesn't exist, create one + os.mkdir('/home/pi/tyos/configure') + + self.audio_file = open('/home/pi/tyos/configure/audio.conf', 'w+')#Create config file and add some lines + self.audio_file.write('#Audio config file\n') + self.audio_file.write('mode=1\n') + self.audio_file.close() + self.audio_file = open('/home/pi/tyos/configure/audio.conf', 'r') + + file = self.audio_file.readlines() + + for i in range(0, len(file)):#Parse file + if file[i][0] == '#': + pass + #Do Nothing. Line is comment + else: + file[i] = file[i].rstrip() + if 'mode' in file[i]: #Extract audio mode: 1=Built in, 0=External + mode = file[i] + + mode = mode.split('=') + mode = mode[1] + + self.fona.transmit('AT+CHFA=' + mode) def blit_time(self): #Convert to 12 hour time then blit it to surface