Example #1
0
def TerminateProgram():
  global read_packet_stop
  print "Termination started..."
  ble.ble_disconnect(0)
  #stop the thread which is reading packets
  read_packet_stop.set()
  ble.ser.close()
  print "Closing..."
Example #2
0
def MainLoop():
  global mode, CHECK_VCC, TEMP, CHECK_BATT
  
  selection = 1
  while (selection != 99):
      
    if (selection == 1):
      print "Menu:"
      print "   1. Print this menu"
      print "   2. Connect"
      print "   3. Disconnect"
      print "   4. Toggle LED"
      print "   5. Get VCC"
      print "   6. Get Temperature"
      print "   7. Get Battery V"
      print "   8. Send arbitrary data"
      print "   9. Reset system"
      print "   99. Quit"
      
    elif (selection == 2):
      ConnectBLE()
      
    elif (selection == 3):
      print "Disconnecting from device..."
      ble.ble_disconnect(0)
      
    elif (selection == 4):
      print "Toggling LED...\n"
      ble.sendData(array.array('B', '1') )
      
    elif (selection == 5):
      print "Getting VCC...\n"
      mode = CHECK_VCC
      ble.sendData(array.array('B', '4') )
      
    elif (selection == 6):
      print "Getting temperature...\n"
      mode = TEMP
      ble.sendData(array.array('B', '5') )
      
    elif (selection == 7):
      print "Getting battery voltage...\n"
      mode = CHECK_BATT
      ble.sendData(array.array('B', '6') )
      
    elif (selection == 8):
      value = raw_input("Please enter data to send: ")
      ble.sendData(array.array('B', value ) )
                  
    elif (selection == 9):
      print "Resetting system..."
      ble.resetBLE()
            
      
    else:
      print "Not an option.\n"
      

    print "Please enter a number:"
    selection = input()
    print "\n"    
    
    
  return