Skip to content

Commit

Permalink
Merge pull request #10 from vetonsaliu8/master
Browse files Browse the repository at this point in the history
Add analog_read capability
  • Loading branch information
hmaarrfk authored Jul 14, 2021
2 parents e0cc1a8 + 77a11ef commit 60535ea
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 0.0.15

* Add the ability to do analog reads.

### 0.0.14

* Enable reading and writing a contiguous payload of bytes
Expand Down
5 changes: 5 additions & 0 deletions src/commandconstants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ int analog_write(CommandRouter *cmd, int argc, const char **argv);
int analog_write_frequency(CommandRouter *cmd, int argc, const char **argv);
int analog_write_resolution(CommandRouter *cmd, int argc, const char **argv);

// Analog IO
int analog_read(CommandRouter *cmd, int argc, const char **argv);

// SPI support
int spi_begin(CommandRouter *cmd, int argc, const char **argv);
int spi_end(CommandRouter *cmd, int argc, const char **argv);
Expand Down Expand Up @@ -98,6 +101,8 @@ command_item_t command_list[] = {
"analog_write_frequency pin frequency", analog_write_frequency},
{"analog_write_resolution", "Write the resolution of the PWM timer",
"analog_write_resolution bitdepth", analog_write_resolution},
{"analog_read", "Read the value of an analog pin, 0-255",
"analog_read pin", analog_read},
{"spi_begin", "SPI Begin", "spi_begin", spi_begin},
{"spi_end", "SPI End", "spi_end", spi_begin},
{"spi_set_mosi", "SPI set MOSI", "spi_set_mosi mosi", spi_set_mosi},
Expand Down
11 changes: 11 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,17 @@ int analog_write(CommandRouter *cmd, int argc, const char **argv) {
return 0;
}

int analog_read(CommandRouter *cmd, int argc, const char **argv) {
if (argc != 2)
return EINVAL;

uint8_t pin = strtol(argv[1], nullptr, 0);
uint8_t value = analogRead(pin);

snprintf(cmd->buffer, cmd->buffer_size, "%d", value);
return 0;
}

int analog_write_frequency(CommandRouter *cmd, int argc, const char **argv) {
int pin;
int frequency;
Expand Down

0 comments on commit 60535ea

Please sign in to comment.