Waveshare 8ch Relay Board Example
A simple repository containing (functioning) examples of how to use the Waveshare 8ch relay board.
|
#include <algorithm>
#include <iostream>
#include <fstream>
#include <regex>
#include <string>
#include <stdint.h>
#include <sys/stat.h>
#include <unistd.h>
Go to the source code of this file.
Functions | |
template<typename... Args> | |
string | formatString (const string &format, Args... args) |
Simple string formatter template function. More... | |
bool | directoryExists (string dirPath) |
Whether or not a given directory exists or not. More... | |
bool | parseArgs (int32_t argC, char **argV) |
Parses command-line arguments passed to the application. More... | |
void | enableGpio () |
Enables a given GPIO pin. More... | |
void | setGpio () |
Sets a GPIO pin on/off, depending on the desired state. More... | |
void | showHelp () |
Prints the help text. More... | |
int | main (int32_t argC, char **argV) |
Variables | |
static uint32_t | g_channel = 0 |
The selected channel to enable and/or toggle. More... | |
static bool | g_state = false |
The desired state for the channel (on/off) More... | |
static const uint32_t | CHANNELS [8] |
A simple array representing a map to the channels on the relay board, corresponding to the GPIO pings. More... | |
bool directoryExists | ( | string | dirPath | ) |
Whether or not a given directory exists or not.
Determines whether or not a given directory exists.
dirPath | The path to check. |
Definition at line 99 of file channel_select.cpp.
void enableGpio | ( | ) |
Enables a given GPIO pin.
Enables use of the desired GPIO pin.
Definition at line 142 of file channel_select.cpp.
References g_channel.
string formatString | ( | const string & | format, |
Args... | args | ||
) |
Simple string formatter template function.
Args | The arguments to be formatted into the string |
format | The C-style format string |
args | Varargs list of arguments |
Definition at line 60 of file channel_select.cpp.
int main | ( | int32_t | argC, |
char ** | argV | ||
) |
Definition at line 79 of file channel_select.cpp.
References parseArgs(), and showHelp().
bool parseArgs | ( | int32_t | argC, |
char ** | argV | ||
) |
Parses command-line arguments passed to the application.
Parses arguments passed to the application and sets the required parameters accordingly.
argC | The total arg count |
argV | A pointer-pointer to the arg list |
Definition at line 116 of file channel_select.cpp.
References g_channel, g_state, and showHelp().
Referenced by main().
void setGpio | ( | ) |
Sets a GPIO pin on/off, depending on the desired state.
Sets the desired GPIO pin either on or off, depending on cmd-args.
Definition at line 165 of file channel_select.cpp.
void showHelp | ( | ) |
Prints the help text.
Prints the help text to the console.
Definition at line 177 of file channel_select.cpp.
Referenced by main(), and parseArgs().
|
static |
A simple array representing a map to the channels on the relay board, corresponding to the GPIO pings.
E.g.: CHANNELS[0] = channel 1 = GPIO5
Definition at line 45 of file channel_select.cpp.
|
static |
The selected channel to enable and/or toggle.
Definition at line 36 of file channel_select.cpp.
Referenced by enableGpio(), parseArgs(), and setGpio().
|
static |
The desired state for the channel (on/off)
Definition at line 37 of file channel_select.cpp.
Referenced by parseArgs(), and setGpio().