pairing

ํŽ˜์–ด๋ง ๋ณ€๊ฒฝ ํ›„ ๋ณ€๊ฒฝ๋œ ์ •๋ณด ํ™•์ธ

# ์กฐ์ข…๊ธฐ์˜ ํŽ˜์–ด๋ง ์ •๋ณด๋ฅผ ๋ณ€๊ฒฝํ•˜๊ณ , ๋ณ€๊ฒฝ๋œ ์ •๋ณด๋ฅผ ์š”์ฒญํ•œ ํ›„ ์‘๋‹ต์„ ๊ธฐ๋‹ค๋ ค ์ถœ๋ ฅํ•˜๋Š” ์˜ˆ์ œ
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()

Last updated