コード例 #1
0
ファイル: recieveBLE.py プロジェクト: 83tb/band60
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..."
コード例 #2
0
ファイル: recieveBLE.py プロジェクト: 83tb/band60
def InitBLE():
  global read_packet_stop
  ble.silent = 1
  ble.handleDataRX = ReceiveData

  ble.ser = serial.Serial("/dev/tty.usbmodem1421", 115200, timeout=.2)
  ble.ser.flushInput()
  ble.ser.flushOutput()
  ble.ser.flush()

  read_packet_stop = threading.Event()
  ble.read_packet_thread = threading.Thread(target=ble.readPacketThread,  args=(2, read_packet_stop))
  ble.read_packet_thread.start()

  ble.initializeBLE()
コード例 #3
0
ファイル: recieveBLE.py プロジェクト: 83tb/band60
def ConnectBLE():
  ble.searchForDevices(1)

  if not ble.deviceList:
    print "No devices found!"
  else:
    question = 'Available Devices:'     
    for i in range(len(ble.deviceList)):
      question = question + '\r\n' + str(i+1) + '.' + str(ble.deviceList[i])
      
    print question,"\n"
    
    print "Please select a device:"
    devNum = input()
    
    if (devNum > len(ble.deviceList)):
      print "Not a valid device!"
    else:
    
      dev = ble.deviceList[devNum-1]
      ble.connectToDevice(dev)
      
      print "Connected to: \"",dev.name,"\""
      RSSI = dev.RSSI
      RSSI = RSSI if RSSI <= 127 else RSSI - 256 
      print "RSSI: ",dev.RSSI,"dBm\n"
      
      ble.enableRXIndicator()
コード例 #4
0
ファイル: recieveBLE.py プロジェクト: 83tb/band60
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