Add setAnalogRead type & command handler. Add core analogRead function.

This commit is contained in:
anecdata
2019-10-13 21:32:06 -05:00
parent b90bbd6349
commit 5687201ec9
3 changed files with 25 additions and 1 deletions

View File

@@ -18,6 +18,7 @@
*/
#include <driver/ledc.h>
#include <driver/adc.h>
#include "wiring_analog.h"
@@ -43,3 +44,11 @@ void analogWrite(uint32_t pin, uint32_t value)
};
ledc_channel_config(&ledc_conf);
}
int analogRead(uint32_t pin)
{
adc1_config_width(ADC_WIDTH_BIT_12);
adc1_config_channel_atten(pin,ADC_ATTEN_DB_11);
int val = adc1_get_raw(pin);
return val;
}

View File

@@ -28,6 +28,8 @@ extern "C" {
extern void analogWrite(uint32_t pin, uint32_t value);
extern int analogRead(uint32_t pin);
#ifdef __cplusplus
}
#endif

View File

@@ -1007,6 +1007,19 @@ int setDigitalRead(const uint8_t command[], uint8_t response[])
return 6;
}
int setAnalogRead(const uint8_t command[], uint8_t response[])
{
uint8_t pin = command[4];
int value = digitalRead(pin);
response[2] = 1; // number of parameters
response[3] = sizeof(value); // parameter 1 length
memcpy(&response[4], &value, sizeof(value));
return 5 + sizeof(value);
}
int wpa2EntSetIdentity(const uint8_t command[], uint8_t response[]) {
char identity[32 + 1];
@@ -1125,7 +1138,7 @@ const CommandHandlerType commandHandlers[] = {
setClientCert, setCertKey, NULL, NULL, sendDataTcp, getDataBufTcp, insertDataBuf, NULL, NULL, NULL, wpa2EntSetIdentity, wpa2EntSetUsername, wpa2EntSetPassword, wpa2EntSetCACert, wpa2EntSetCertKey, wpa2EntEnable,
// 0x50 -> 0x5f
setPinMode, setDigitalWrite, setAnalogWrite, setDigitalRead,
setPinMode, setDigitalWrite, setAnalogWrite, setDigitalRead, setAnalogRead,
};
#define NUM_COMMAND_HANDLERS (sizeof(commandHandlers) / sizeof(commandHandlers[0]))