Class DInput5Relay2Module

Inheritance Relationships

Base Type

Class Documentation

class DInput5Relay2Module : public Module

This class represents the Digital Inputs and Power Relays Module connected via eMOD bus to controller module. On the one hand, this module has 5 independent digital inputs and the status of each one can be obtained separately. If a polling is to be performed more than once per second, it's recommended to handle function call. And on the other hand, has 2 independent power relays than can be activated or deactivated separately. If a polling is to be performed more than once per second, it's recommended to handle function call.

Class example 1

/*
 * This example uses a DInput5Relay2Module to display all digital inputs status and activate/deactivates relays.
 */
#include "DInput5Relay2Module.hpp"
#include "EmodRetMng.hpp"
#include "HAL.hpp"

int main() {
    DInput5Relay2Module module;
    if (module.init() != 0) {
        printf("Module could not be initialized!\n");
        return 1;
    }

    // Reset all pulse count
    module.resetAllPulseCount();

    // Sets pulse filter for inputs 1 and 2
    module.setPulseFilterTime(DInput5Relay2Module::DI_INPUT01 | DInput5Relay2Module::DI_INPUT02, 100);

    uint8_t d_inputs[DInput5Relay2Module::NUMBER_OF_DI_INPUTS];
    uint32_t pulse_count = 0;
    while (1) {
        // Gets all input status
        if (module.getAllStatus(d_inputs) == 0) {
            for (size_t i = 0; i < DInput5Relay2Module::NUMBER_OF_DI_INPUTS; i++) {
                printf("DI0%d = %d ", i + 1, d_inputs[i]);
            }
            printf("\n");
        }

        uint8_t d_input;
        // Gets input 1 status
        if (module.getStatus(DInput5Relay2Module::DI_INPUT01, &d_input) == 0) {
            printf("DI01 = %x\n", d_input);
        }

        // Gets input 2 status
        if (module.getStatus(DInput5Relay2Module::DI_INPUT02, &d_input) == 0) {
            printf("DI02 = %x\n", d_input);
        }

        // Gets pulse count for input 1
        if (module.getPulseCount(DInput5Relay2Module::DI_INPUT01, &pulse_count) == 0) {
            printf("Pulse count DI01 = %d\n", pulse_count);
        }

        // Gets pulse count for input 2
        if (module.getPulseCount(DInput5Relay2Module::DI_INPUT02, &pulse_count) == 0) {
            printf("Pulse count DI02 = %d\n", pulse_count);
        }

        sleepMs(1000);

        // Test relays
        module.activate(DInput5Relay2Module::RELAY1);
        sleepMs(500);
        module.activate(DInput5Relay2Module::RELAY2);
        sleepMs(500);
        module.deactivate(DInput5Relay2Module::RELAY1);
        sleepMs(500);
        module.deactivate(DInput5Relay2Module::RELAY2);
        sleepMs(500);
    }
}

Public Functions

DInput5Relay2Module()
~DInput5Relay2Module()
EmodRet init(const DInput5Relay2ModuleCallback_Type callback_func = nullptr, void *const callback_context = nullptr, const uint8_t variant = 1)

Initialize module. It is important to emphasize that this method is mandatory to call it and must be called always after instantiating the module. It can be called several times, each of which the module is initialized again.

Parameters
  • callback_func(optional) -- [in] function that will be called when a configured event occurs.

  • callback_context(optional) -- [in] context that will be passed to the callback function.

  • variant(optional) -- [in] identifies the module in case more than one module of the same type are present.

EmodRet init(const uint8_t variant)
EmodRet getStatus(const uint16_t input_mask, uint8_t *status, bool *new_data = nullptr)

Gets a digital input status.

Parameters
  • input_mask -- [in] digital input number to get the status, as enumerated above in the constants section.

  • status -- [out] returns last received input number status (0: deactivated, 1: activated).

  • new_data(optional) -- [out] returns if new data has arrived since the last function call. If status has not been received yet, NO_NEW_DATA_READ is returned. Parameter is initialized inside the class.

EmodRet getAllStatus(uint8_t status[NUMBER_OF_DI_INPUTS], bool *new_data = nullptr)

Gets all digital input status.

Parameters
  • status -- [out] returns last received input number status (0: deactivated, 1: activated) for each digital input.

  • new_data(optional) -- [out] returns if new data has arrived since the last function call. If a digital input status has not been received yet, NO_NEW_DATA_READ is returned in that input. Parameter is initialized inside the class.

EmodRet setPulseFilterTime(const uint16_t input_mask, const uint32_t ms_time)

Sets the pulse filter time. All pulses with a shorter time will be discarded.

Parameters
  • input_mask -- [in] digital input number to get the status, as enumerated above in the constants section.

  • ms_time -- [in] pulse width (in ms). Value range 0 to 2^32-1. A 0-value means disable pulse. Default value is 0.

EmodRet setAllPulseFilterTime(const uint32_t ms_time)

Sets the pulse filter time for all inputs.

Parameters

ms_time -- [in] pulse width (in ms). Value range 0 to 2^32-1. A 0-value means disable pulse. Default value is 0.

EmodRet getPulseFilterTime(const uint16_t input_mask, uint32_t *ms_time)

Gets current pulse filter time.

Parameters
  • input_mask -- [in] digital input number to get the status, as enumerated above in the constants section.

  • ms_time -- [out] pulse width (in ms).

EmodRet getAllPulseFilterTime(uint32_t ms_times[NUMBER_OF_DI_INPUTS])

Gets current pulse filter time for all inputs.

Parameters

ms_time -- [out] pulse width (in ms) for each input.

EmodRet getPulseCount(const uint16_t input_mask, uint32_t *count)

Gets number of pulses occurred in an input after a reset.

Parameters
  • input_mask -- [in] digital input number to get the status, as enumerated above in the constants section.

  • count -- [out] number of pulses.

EmodRet getAllPulseCount(uint32_t counts[NUMBER_OF_DI_INPUTS])

Gets number of pulses occurred in all inputs.

Parameters

counts -- [out] number of pulses for each digital input.

EmodRet resetPulseCount(uint16_t input_mask)

Resets the number of pulses in an input.

Parameters

input_mask -- [in] digital input number to get the status, as enumerated above in the constants section.

EmodRet resetAllPulseCount()

Resets the number of pulses in all inputs.

EmodRet getPulseWidth(const uint16_t input_mask, uint32_t *width)

Gets last pulse width occurred in an input.

Parameters
  • input_mask -- [in] digital input number to get the status, as enumerated above in the constants section.

  • width -- [out] pulse width (in ms).

EmodRet getAllPulseWidth(uint32_t widths[NUMBER_OF_DI_INPUTS])

Gets last pulse width occurred in all inputs.

Parameters

widths -- [out] an array of counts representing the last pulse width occurred in each input.

EmodRet configPulseWidth(const uint8_t relay_mask, const uint32_t width_ms)

Configure pulse width of a relay o list of relays. When pulse width is 0 a relay stays in the current state, and there is no pulse.

Parameters
  • relay_mask -- [in] relay or list of relays to configure.

  • width_ms -- [in] pulse width in ms. Value range 0 to 2^32-1. A 0-value means disable pulse. Default value is 0.

EmodRet configAllPulseWidth(const uint32_t width_ms)

Configure pulse width of al relays When pulse width is 0 a relay stays in the current state, and there is no pulse.

Parameters

width_ms -- [in] pulse width in ms. Value range 0 to 2^32-1. A 0-value means disable pulse. Default value is 0.

EmodRet activate(const uint8_t relay_mask)

Activates a relay or set of relays.

Parameters

relay_mask -- [in] relay or list of relays to activate.

EmodRet deactivate(const uint8_t relay_mask)

Deactivates a relay or set of relays.

Parameters

relay_mask -- [in] relay or list of relays to deactivate.

EmodRet activateAll(void)

Activates all module relays.

EmodRet deactivateAll(void)

Deactivates all module relays.

EmodRet getRelayStatus(const uint8_t relay_mask, uint8_t *status)

Gets a relay status.

Parameters
  • relay_mask -- [in] relay mask number to get the status.

  • status -- [out] every bit represents a relay order status. Status is 1 when is activate and 0 when deactivate.

EmodRet getAllRelayStatus(uint8_t *status)

Gets all relay status.

Parameters

status -- [out] every bit represents a relay order status. Status is 1 when is activate and 0 when deactivate.

EmodRet configEventAtTimeInterval(const uint32_t time_interval)

Configures module for calling init callback_func at specified period.

Parameters

time_interval -- [in] period in milliseconds. Minimum value is 500ms,

EmodRet switchToMode(const uint16_t input_mask, const uint32_t mode)

Usually, this function only needs to be called at the beginning in the configuration stage.

Parameters
  • input_mask -- [in] digital input number to be configured.

  • mode -- [in] desired mode for the input; PULSE_COUNTER or PULSE_WIDTH as enumerated above in the constants section.

EmodRet configEventOnNewData(void)

Configures module for calling init callback_func when new data on input occurs.

EmodRet configEventOnValueChange(const uint32_t threshold, const uint32_t event_mask = DI_ALL_INPUT)

Configures module for calling init callback_func when input changes its value by a specified amount, accordingly to the configured mode (see switchToMode).

Parameters
  • threshold -- [in] amount of COUNT_PULSE's or miliseconds PULSE_WIDTH that triggers the event.

  • event_mask -- [in] bit mask representing inputs that must trigger the event.

EmodRet resetEventConfig(void)

Resets all previously configured events.

Public Static Attributes

static constexpr uint16_t DI_INPUT01 = DInput5Relay2Module_INPUT01
static constexpr uint16_t DI_INPUT02 = DInput5Relay2Module_INPUT02
static constexpr uint16_t DI_INPUT03 = DInput5Relay2Module_INPUT03
static constexpr uint16_t DI_INPUT04 = DInput5Relay2Module_INPUT04
static constexpr uint16_t DI_INPUT05 = DInput5Relay2Module_INPUT05
static constexpr uint16_t DI_ALL_INPUT = DInput5Relay2Module_ALL_INPUT
static constexpr uint8_t RELAY1 = DInput5Relay2Module_RELAY1
static constexpr uint8_t RELAY2 = DInput5Relay2Module_RELAY2
static constexpr uint8_t ALL_RELAY = DInput5Relay2Module_ALL_RELAY
static constexpr uint8_t NUMBER_OF_DI_INPUTS = DInput5Relay2Module_NUMBER_OF_DI_INPUTS
static constexpr uint8_t NUMBER_OF_RELAYS = DInput5Relay2Module_NUMBER_OF_RELAYS
static constexpr uint32_t MODE_PRETRIGGER_TIME = DInput5Relay2Module_MODE_PRETRIGGER_TIME
static constexpr uint32_t MODE_PULSE_COUNTER = DInput5Relay2Module_MODE_PULSE_COUNTER
static constexpr uint32_t MODE_WIDTH_COUNTER = DInput5Relay2Module_MODE_WIDTH_COUNTER
static constexpr uint8_t idFunctionINPUTS = DInput5Relay2Module_idFunctionINPUTS
static constexpr uint8_t idFunctionCOUNTER01 = DInput5Relay2Module_idFunctionCOUNTER01
static constexpr uint8_t idFunctionCOUNTER02 = DInput5Relay2Module_idFunctionCOUNTER02
static constexpr uint8_t idFunctionCOUNTER03 = DInput5Relay2Module_idFunctionCOUNTER03
static constexpr uint8_t idFunctionCOUNTER04 = DInput5Relay2Module_idFunctionCOUNTER04
static constexpr uint8_t idFunctionCOUNTER05 = DInput5Relay2Module_idFunctionCOUNTER05

Protected Functions

EmodRet initFunctions()
uint8_t getFunctionsOffsetId()
uint8_t getInputsOffsetId()

Protected Attributes

RelayFunctions *relays
DigitalInputFunctions *digitalInputs