|
54 | 54 | # pylint: disable=bad-whitespace
|
55 | 55 | _SET_NET_CMD = const(0x10)
|
56 | 56 | _SET_PASSPHRASE_CMD = const(0x11)
|
| 57 | +_SET_DEBUG_CMD = const(0x1A) |
57 | 58 |
|
58 | 59 | _GET_CONN_STATUS_CMD = const(0x20)
|
59 | 60 | _GET_IPADDR_CMD = const(0x21)
|
|
87 | 88 | _SET_ENT_PASSWD_CMD = const(0x4C)
|
88 | 89 | _SET_ENT_ENABLE_CMD = const(0x4F)
|
89 | 90 |
|
| 91 | +_SET_PIN_MODE_CMD = const(0x50) |
| 92 | +_SET_DIGITAL_WRITE_CMD = const(0x51) |
| 93 | +_SET_ANALOG_WRITE_CMD = const(0x52) |
| 94 | + |
90 | 95 | _START_CMD = const(0xE0)
|
91 | 96 | _END_CMD = const(0xEE)
|
92 | 97 | _ERR_CMD = const(0xEF)
|
@@ -611,3 +616,53 @@ def socket_close(self, socket_num):
|
611 | 616 | resp = self._send_command_get_response(_STOP_CLIENT_TCP_CMD, self._socknum_ll)
|
612 | 617 | if resp[0][0] != 1:
|
613 | 618 | raise RuntimeError("Failed to close socket")
|
| 619 | + |
| 620 | + def set_esp_debug(self, enabled): |
| 621 | + """Enable/disable debug mode on the ESP32. Debug messages will be |
| 622 | + written to the ESP32's UART.""" |
| 623 | + resp = self._send_command_get_response(_SET_DEBUG_CMD, ((bool(enabled),),)) |
| 624 | + if resp[0][0] != 1: |
| 625 | + raise RuntimeError("Failed to set debug mode") |
| 626 | + |
| 627 | + def set_pin_mode(self, pin, mode): |
| 628 | + """ |
| 629 | + Set the io mode for a GPIO pin. |
| 630 | +
|
| 631 | + :param int pin: ESP32 GPIO pin to set. |
| 632 | + :param value: direction for pin, digitalio.Direction or integer (0=input, 1=output). |
| 633 | + """ |
| 634 | + if mode == Direction.OUTPUT: |
| 635 | + pin_mode = 1 |
| 636 | + elif mode == Direction.INPUT: |
| 637 | + pin_mode = 0 |
| 638 | + else: |
| 639 | + pin_mode = mode |
| 640 | + resp = self._send_command_get_response(_SET_PIN_MODE_CMD, |
| 641 | + ((pin,), (pin_mode,))) |
| 642 | + if resp[0][0] != 1: |
| 643 | + raise RuntimeError("Failed to set pin mode") |
| 644 | + |
| 645 | + def set_digital_write(self, pin, value): |
| 646 | + """ |
| 647 | + Set the digital output value of pin. |
| 648 | +
|
| 649 | + :param int pin: ESP32 GPIO pin to write to. |
| 650 | + :param bool value: Value for the pin. |
| 651 | + """ |
| 652 | + resp = self._send_command_get_response(_SET_DIGITAL_WRITE_CMD, |
| 653 | + ((pin,), (value,))) |
| 654 | + if resp[0][0] != 1: |
| 655 | + raise RuntimeError("Failed to write to pin") |
| 656 | + |
| 657 | + def set_analog_write(self, pin, analog_value): |
| 658 | + """ |
| 659 | + Set the analog output value of pin, using PWM. |
| 660 | +
|
| 661 | + :param int pin: ESP32 GPIO pin to write to. |
| 662 | + :param float value: 0=off 1.0=full on |
| 663 | + """ |
| 664 | + value = int(255 * analog_value) |
| 665 | + resp = self._send_command_get_response(_SET_ANALOG_WRITE_CMD, |
| 666 | + ((pin,), (value,))) |
| 667 | + if resp[0][0] != 1: |
| 668 | + raise RuntimeError("Failed to write to pin") |
0 commit comments