device · LEDs, sensors, battery¶
Controls the MCU to control components.
Class:
Device
DeviceByPiBrain
- class openpibo.device.Device(api_mode=True, port=8080)[source]¶
Bases:
objectFunctions:
code_listsend_cmd()send_raw()eye_on()eye_on_s()eye_off()get_battery()get_dc()get_system()get_pir()get_touch()get_button()Controls the main controller to check piBo’s various states or change the eye color.
example:
from openpibo.device import Device device = Device() # 아래의 모든 예제 이전에 위 코드를 먼저 사용합니다.
Message details:
* VERSION(10): 파이보의 버전을 출력합니다. * msg: '#10:!' * result: 버전정보 (예: '10:FWN200312A') * HALT(11): 파이보를 종료합니다. * msg: '#11:!' * result: 'ok' * DC_CONN(14): 파이보의 충전기 연결 여부를 확인합니다. * msg: '#14:!' * result: '14:on' * ``on``: 연결 되어있음 * ``off``: 연결 되어있지 않음 * BATTERY(15): 파이보의 배터리 잔량을 확인합니다. * msg: '#15:!' * result: 배터리 잔량 정보 (예: '15:100%') * REBOOT(17): 설정 초기화 (Not use) * msg: '#17:!' * result: 'ok' * NEOPIXEL(20): 파이보의 눈(네오픽셀) 색을 변경합니다. - 양쪽 동일하게 설정 * msg: '#20:255,255,255!' * data: 네오픽셀 색 R,G,B ('R,G,B') (예: '255,255,255') * 'R,G,B' 의 포맷으로 입력 * 각 R, G, B는 0~255 정수 * result: 'ok' * NEOPIXEL_FADE(21): 파이보의 눈(네오픽셀) 색을 천천히 변경합니다. - 양쪽 동일하게 설정 * msg: '#21:255,255,255,10!' * data: 네오픽셀 색 R,G,B와 색 변경 속도 d ('R,G,B,d') (예: '255,255,255,10') * 'R,G,B,d' 의 포맷으로 입력 * 각 R, G, B는 0~255 정수 * d는 색상 단위 변화 1당 걸리는 시간으로, 단위는 ms * result: 'ok' * NEOPIXEL_BRIGHTNESS(22): 파이보의 눈(네오픽셀) 밝기를 조절합니다. * msg: '#22:64!' * data: 네오픽셀 밝기 (예: 64) * 0~255 정수 * 기본값: 64 * result: 'ok' * NEOPIXEL_EACH(23): 파이보의 양쪽 눈(네오픽셀) 색을 각각 변경합니다. - 양쪽 각각 설정 * msg: '#23:255,255,255,255,255,255!' * data: 왼쪽 네오픽셀 색 R,G,B와 오른쪽 네오픽셀 색 R,G,B ('R,G,B,R,G,B') (예: '255,255,255,255,255,255') * 'R,G,B,R,G,B' 의 포맷으로 입력 * 각 R, G, B는 0~255 정수 * result: 'ok' * NEOPIXEL_FADE_EACH(24): 파이보의 양쪽 눈(네오픽셀) 색을 각각 천천히 변경합니다. * msg: '#24:255,255,255,255,255,255,10!' * data: 왼쪽 네오픽셀 색 R,G,B와 오른쪽 네오픽셀 색 R,G,B와 색 변화 속도 d ('R,G,B,R,G,B,d') (예: '255,255,255,255,255,255,10') * 'R,G,B,R,G,B' 의 포맷으로 입력 * 각 R, G, B는 0~255 정수 * d는 색상 단위 변화 1당 걸리는 시간으로, 단위는 ms * result: 'ok' * NEOPIXEL_LOOP(25): 파이보의 눈(네오픽셀) 색을 무지개색으로 일정시간동안 변경합니다. * msg: '#25:10!' * data: 색 변화 속도 d (예: 10) * d는 색상 단위 변화 1당 걸리는 시간으로, 단위는 ms * result: 'ok' * NEOPIXEL_OFFSET_SET(26): 파이보의 눈(네오픽셀) 색의 초기 설정 * msg: '#26:255,255,255,255,255,255!' * data: 왼쪽 네오픽셀 오프셋 R,G,B와 오른쪽 네오픽셀 오프셋 R,G,B ('R,G,B,R,G,B') (예: '255,255,255,255,255,255') * 'R,G,B,R,G,B' 의 포맷으로 입력 * 각 R, G, B는 0~255 정수 * result: 'ok' * NEOPIXEL_OFFSET_GET(27): 파이보의 눈(네오픽셀) 오프셋 정보를 반환합니다. * msg: '#27:255,255,255,255,255,255!' * data: 네오픽셀 오프셋 정보 (예: '27:255,255,255,255,255,255') * result: - * NEOPIXEL_EACH_ORG(28): 파이보의 양쪽 눈(네오픽셀) 색을 각각 변경합니다. 단, 오프셋의 영향을 받지 않습니다. * msg: '#28:255,255,255,255,255,255!' * data: 왼쪽 네오픽셀 색 R,G,B와 오른쪽 네오픽셀 색 R,G,B ('R,G,B,R,G,B') (예: '255,255,255,255,255,255') * 'R,G,B,R,G,B' 의 포맷으로 입력 * 각 R, G, B는 0~255 정수 * result: 'ok' * PIR(30): PIR 센서를 켜고 끕니다. * msg: '#30:on!' * data: PIR 센서의 활성화 여부 (예: 'on') * ``on`` : PIR 센서를 켭니다. * ``off`` : PIR 센서를 끕니다. * result: 'ok' * SYSTEM(40): 각종 시스템 정보를 출력합니다. * msg: '#40:!' * data: - * result: 아래의 정보가 모두 출력됩니다. * PIR 감지: * ``person`` : PIR센서가 적외선의 변화를 감지할 때 출력됩니다. * ``nobody`` : ``person`` 출력 후 2초간 적외선의 변화가 없을 때 1회 출력됩니다. * ``-`` : 적외선의 변화가 감지되지 않을 때 또는 PIR센서가 비활성화 상태일 때 출력됩니다. * Touch 감지: * ``touch`` : 터치센서 감지 시 출력됩니다. * ``-`` : 터치센서 감지가 안되면 출력됩니다. * DC잭 연결감지: * ``on`` : DC잭 감지 시 1회 출력됩니다. 이후 ``-`` 가 출력됩니다. * ``off`` : DC잭 감지 해제시 1회 출력됩니다. 이후 ``-`` 가 출력됩니다. * ``-`` : DC잭 신호의 변화가 없을 때 출력됩니다. * 버튼 감지: * ``on`` : 전원 버튼 누름 감지 시 출력됩니다. * ``-`` : 전원 버튼 누름 감지가 안되면 출력됩니다. * 시스템리셋: 현재 지원되지 않습니다. * 전원종료: 현재 지원되지 않습니다.- code_list = {'BATTERY': '15', 'DC_CONN': '14', 'HALT': '11', 'NEOPIXEL': '20', 'NEOPIXEL_BRIGHTNESS': '22', 'NEOPIXEL_EACH': '23', 'NEOPIXEL_EACH_ORG': '28', 'NEOPIXEL_FADE': '21', 'NEOPIXEL_FADE_EACH': '24', 'NEOPIXEL_LOOP': '25', 'NEOPIXEL_OFFSET_GET': '27', 'NEOPIXEL_OFFSET_SET': '26', 'PIR': '30', 'REBOOT': '17', 'SYSTEM': '40', 'VERSION': '10'}¶
- send_cmd(code, data: str = '')[source]¶
Sends a message code/data to the Device. The input message is converted to the
#code:data!format before being sent. See above for message details.example:
device.send_cmd(20, '255,255,255')
- Parameters:
code (str or int) – Message code * 10 : VERSION * 11 : HALT * 14 : DC_CONN * 15 : BATTERY * 17 : REBOOT * 20 : NEOPIXEL * 21 : NEOPIXEL_FADE * 22 : NEOPIXEL_BRIGHTNESS * 23 : NEOPIXEL_EACH * 24 : NEOPIXEL_FADE_EACH * 25 : NEOPIXEL_LOOP * 26 : NEOPIXEL_OFFSET_SET * 27 : NEOPIXEL_OFFSET_GET * 28 : NEOPIXEL_EACH_ORG * 30 : PIR * 40 : SYSTEM
data (str) – Message The data format depends on the value of
code. Depending on the code, data may not be required. example:: device.send_cmd(20, ‘255,255,255’) device.send_cmd(21, ‘255,255,255,10’) device.send_cmd(22, ‘64’) device.send_cmd(23, ‘255,255,255,255,255,255’) device.send_cmd(24, ‘255,255,255,255,255,255,10’) device.send_cmd(25, ‘2’) device.send_cmd(26, ‘255,255,255,255,255,255’) device.send_cmd(28, ‘255,255,255,255,255,255’) device.send_cmd(30, ‘on’) For details, see “Message details” above
- Returns str:
Response received from the Device
- send_raw(raw)[source]¶
Sends the actual message to the Device and receives the response. See above for message details.
example:
device.send_raw('#20:255,255,255!') device.send_raw('#22:64!')
- Parameters:
raw (str) – Actual message sent The format of the message sent to the Device is
#code:data!. The message is sent to the main controller. For details, see “Message details” above- Returns:
Response received from the Device
- eye_on(*color, intv=0)[source]¶
Turns on the LED.
example:
device.eye_on(255,0,0) # 양쪽 눈 제어 device.eye_on(0,255,0,0,0,255) # 양쪽 눈 각각 제어
- Parameters:
color –
RGB (0~255 numbers)
(R, G, B) -> controls both eyes together
(R,G,B,R,G,B) -> controls each eye separately
intv –
interval (time for the RGB value to change by 1)
off if 0
- eye_on_s(colors, intv=0)[source]¶
Turns on the LED.
example:
device.eye_on_s(['#ffffff', '#ffffff']) # 양쪽 눈 제어
- Parameters:
colors –
List of RGB hex strings [‘#ffffff’, ‘#ffffff’]
- get_battery(v=False)[source]¶
Requests battery information.
example:
device.get_battery()
- Parameters:
v – Whether to get only the value or the whole message
- Returns:
Battery information response
- get_dc(v=False)[source]¶
Requests DC connector information.
example:
device.get_dc()
- Parameters:
v – Whether to get only the value or the whole message
- Returns:
DC connector connection information response
- get_system(v=False)[source]¶
Requests the system message.
example:
device.get_system()
- Parameters:
v – Whether to get only the value or the whole message
name – Value to get (‘pir’|’touch’|’dc’|’button’|’all’)
- Returns:
System message information response (pir-touch-dc-button)
- get_pir()[source]¶
Requests the system message. (pir)
example:
device.get_pir()
- Returns:
pir value extracted from the system message information response
- class openpibo.device.DeviceByPiBrain[source]¶
Bases:
objectFunctions:
get_button()led_on()led_on_s()led_off()