Update ES32A08.cpp

This commit is contained in:
2025-02-05 20:28:29 -05:00
parent d9f556dce5
commit 7487c171f6

View File

@@ -381,19 +381,46 @@ int ES32A08::rawReadAnalogVoltage(int channel) {
return analogRead(voltageInputPins[channel]); return analogRead(voltageInputPins[channel]);
} }
// Set single relay
/**
* @brief Sets the state of a specified relay.
*
* This function sets the state (on or off) of the relay specified by the
* relay parameter. It updates the currentRelays variable and sends the
* updated state to the shift register.
*
* @param relay The relay number to set (0-based index).
* @param state The desired state of the relay (true for on, false for off).
*/
void ES32A08::setRelay(int relay, bool state) { void ES32A08::setRelay(int relay, bool state) {
bitWrite(currentRelays, relay, state); bitWrite(currentRelays, relay, state);
sendToShiftRegister(); sendToShiftRegister();
} }
// Set all relays (0b00000000 - 0b11111111) // Set all relays (0b00000000 - 0b11111111)
/**
* @brief Sets the state of the relays.
*
* This function updates the current state of the relays and sends the new state
* to the shift register.
*
* @param relayStates An unsigned long representing the desired state of the relays.
*/
void ES32A08::setRelays(unsigned long relayStates) { void ES32A08::setRelays(unsigned long relayStates) {
currentRelays = relayStates; currentRelays = relayStates;
sendToShiftRegister(); sendToShiftRegister();
} }
// Read all digital inputs // Read all digital inputs
/**
* @brief Reads the digital inputs from a shift register.
*
* This function reads 8 digital inputs from a shift register connected to the
* microcontroller. It first loads the inputs by toggling the LOAD165_PIN, then
* reads each bit by toggling the CLK165_PIN and reading the DATA165_PIN.
*
* @return uint8_t A byte representing the state of the 8 digital inputs.
*/
uint8_t ES32A08::readDigitalInputs() { uint8_t ES32A08::readDigitalInputs() {
uint8_t inputs = 0; uint8_t inputs = 0;
digitalWrite(LOAD165_PIN, LOW); digitalWrite(LOAD165_PIN, LOW);
@@ -413,6 +440,16 @@ uint8_t ES32A08::readDigitalInputs() {
} }
// Read single digital input // Read single digital input
/**
* @brief Reads the state of a specified digital input.
*
* This function checks the state of a digital input specified by the input number.
* The input number must be between 1 and 8, inclusive. If the input number is out
* of this range, the function returns false.
*
* @param inputNumber The number of the digital input to read (1-8).
* @return true if the specified digital input is high, false if it is low or if the input number is out of range.
*/
bool ES32A08::readDigitalInput(int inputNumber) { bool ES32A08::readDigitalInput(int inputNumber) {
if (inputNumber < 1 || inputNumber > 8) if (inputNumber < 1 || inputNumber > 8)
return false; return false;
@@ -421,9 +458,27 @@ bool ES32A08::readDigitalInput(int inputNumber) {
} }
// Set "PWR" onboard LED // Set "PWR" onboard LED
/**
* @brief Sets the state of the power LED.
*
* This function controls the power LED by setting its state to the specified value.
*
* @param state The desired state of the power LED.
* - `true` to turn the LED off.
* - `false` to turn the LED on.
*/
void ES32A08::setPWRLED(bool state) { digitalWrite(PWR_LED_PIN, !state); } void ES32A08::setPWRLED(bool state) { digitalWrite(PWR_LED_PIN, !state); }
// Read single button state // Read single button state
/**
* @brief Reads the state of a specified button.
*
* This function reads the digital state of a button specified by its number.
* It returns `true` if the button is pressed and `false` otherwise.
*
* @param buttonNumber The number of the button to read (1-based index).
* @return `true` if the button is pressed, `false` otherwise.
*/
bool ES32A08::readButton(int buttonNumber) { bool ES32A08::readButton(int buttonNumber) {
return !digitalRead(buttonPins[buttonNumber - 1]); return !digitalRead(buttonPins[buttonNumber - 1]);
} }