|
88 | 88 | _SET_ENT_PASSWD_CMD = const(0x4C)
|
89 | 89 | _SET_ENT_ENABLE_CMD = const(0x4F)
|
90 | 90 |
|
| 91 | +_SET_PIN_MODE_CMD = const(0x50) |
| 92 | +_SET_DIGITAL_WRITE_CMD = const(0x51) |
| 93 | +_SET_ANALOG_WRITE_CMD = const(0x52) |
| 94 | + |
91 | 95 | _START_CMD = const(0xE0)
|
92 | 96 | _END_CMD = const(0xEE)
|
93 | 97 | _ERR_CMD = const(0xEF)
|
@@ -619,3 +623,46 @@ def set_esp_debug(self, enabled):
|
619 | 623 | resp = self._send_command_get_response(_SET_DEBUG_CMD, ((bool(enabled),),))
|
620 | 624 | if resp[0][0] != 1:
|
621 | 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