e_drone for python / Examples / Pairing

Modified : 2021.1.4



페어링 변경 후 변경된 정보 확인

# 조종기의 페어링 정보를 변경하고, 변경된 정보를 요청한 후 응답을 기다려 출력하는 예제
from time import sleep

from e_drone.drone import *
from e_drone.protocol import *


if __name__ == '__main__':

    drone = Drone(False)
    drone.open()

    # 페어링 설정
    drone.sendPairing(DeviceType.Controller, 0x0001, 0x0002, 0x0003, 0x04, 0x05)
    sleep(0.01)

    # 페어링데이터 요청
    drone.sendRequest(DeviceType.Controller, DataType.Pairing)
    
    timeStart = time.time()

    while True:
        sleep(0.01)
        dataType = drone.check()
        
        if    dataType == DataType.Pairing:
            pairing = drone.getData(DataType.Pairing)

            print("Address: 0x{0:04X}{1:04X}{2:04X} / {0}.{1}.{2}".format(
                pairing.address0, 
                pairing.address1, 
                pairing.address2))

            print("Scramble: {0}".format(pairing.scramble))
            print("Channel: {0}".format(pairing.channel))
            break

        if time.time() > timeStart + 1:
            break
    
    drone.close()



페어링 변경 후 변경된 정보 확인(이벤트 함수 등록)

# 조종기의 페어링 정보를 변경하고, 변경된 정보를 요청한 후 이벤트 핸들러를 통해 응답을 출력하는 예제
from time import sleep

from e_drone.drone import *
from e_drone.protocol import *


def eventPairing(pairing):
    print("eventPairing()")

    print("Address: 0x{0:04X}{1:04X}{2:04X} / {0}.{1}.{2}".format(
        pairing.address0, 
        pairing.address1, 
        pairing.address2))

    print("Scramble: {0}".format(pairing.scramble))
    print("Channel: {0}".format(pairing.channel))


if __name__ == '__main__':

    drone = Drone()
    drone.open()

    # 이벤트 핸들링 함수 등록
    drone.setEventHandler(DataType.Pairing, eventPairing)

    # 페어링 설정
    drone.sendPairing(DeviceType.Controller, 0x0005, 0x0006, 0x0007, 0x08, 0x09)
    sleep(0.01)

    # 페어링데이터 요청
    drone.sendRequest(DeviceType.Controller, DataType.Pairing)
    sleep(0.1)
    
    drone.close()



e_drone for python

  1. Intro
  2. Command Line
  3. System
  4. Protocol
  5. Drone
  6. Examples - Ping
  7. Examples - Information
  8. Examples - Pairing
  9. Examples - Control
  10. Examples - Sensor
  11. Examples - Motor
  12. Examples - Setup
  13. Examples - Buzzer
  14. Examples - Vibrator
  15. Examples - Light
  16. Examples - Display
  17. Examples - Input
  18. Examples - Error


Index