|
133 | 133 | WL_AP_LISTENING = const(7)
|
134 | 134 | WL_AP_CONNECTED = const(8)
|
135 | 135 | WL_AP_FAILED = const(9)
|
| 136 | + |
| 137 | +ADC_ATTEN_DB_0 = const(0) |
| 138 | +ADC_ATTEN_DB_2_5 = const(1) |
| 139 | +ADC_ATTEN_DB_6 = const(2) |
| 140 | +ADC_ATTEN_DB_11 = const(3) |
136 | 141 | # pylint: enable=bad-whitespace
|
137 | 142 |
|
138 | 143 | class ESP_SPIcontrol: # pylint: disable=too-many-public-methods, too-many-instance-attributes
|
@@ -783,26 +788,34 @@ def set_analog_write(self, pin, analog_value):
|
783 | 788 |
|
784 | 789 | def set_digital_read(self, pin):
|
785 | 790 | """
|
786 |
| - Get the digital input value of pin. |
| 791 | + Get the digital input value of pin. Returns the boolean value of the pin. |
787 | 792 |
|
788 | 793 | :param int pin: ESP32 GPIO pin to read from.
|
789 | 794 | """
|
790 | 795 | resp = self._send_command_get_response(_SET_DIGITAL_READ_CMD,
|
791 | 796 | ((pin,),))[0]
|
792 |
| - return resp[0] |
| 797 | + if resp[0] == 0: |
| 798 | + return False |
| 799 | + elif resp[0] == 1: |
| 800 | + return True |
| 801 | + else: |
| 802 | + raise ValueError("_SET_DIGITAL_READ response error", resp_[0]) |
793 | 803 |
|
794 |
| - def set_analog_read(self, pin): |
| 804 | + def set_analog_read(self, pin, atten=ADC_ATTEN_DB_11): |
795 | 805 | """
|
796 |
| - Get the analog input value of pin. |
| 806 | + Get the analog input value of pin. Returns an int between 0 and 65536. |
797 | 807 |
|
798 | 808 | :param int pin: ESP32 GPIO pin to read from.
|
| 809 | + :param int atten: attenuation constant |
799 | 810 | """
|
800 | 811 | resp = self._send_command_get_response(_SET_ANALOG_READ_CMD,
|
801 |
| - ((pin,),))[0] |
| 812 | + ((pin,), (atten,))) |
802 | 813 | resp_a = struct.unpack('<i', resp[0])
|
803 |
| - if resp_a == (-1,): |
804 |
| - raise ValueError("_SET_ANALOG_READ parameter error -1") |
805 |
| - return resp_time |
| 814 | + if resp_a[0] < 0: |
| 815 | + raise ValueError("_SET_ANALOG_READ parameter error", resp_a[0]) |
| 816 | + if self._debug: |
| 817 | + print(resp, resp_a, resp_a[0], 16 * resp_a[0]) |
| 818 | + return 16 * resp_a[0] |
806 | 819 |
|
807 | 820 | def get_time(self):
|
808 | 821 | """The current unix timestamp"""
|
|
0 commit comments