Class DInput10Module

Inheritance Relationships

Base Type

Class Documentation

class DInput10Module : public Module

This class represents the 10 Digital Inputs Module connected via eMOD bus to controller module. This module has 10 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.

Class example 1

/*
 * This example uses a DInput10Module to display all digital inputs status.
 */
#include "DInput10Module.hpp"
#include "EmodRetMng.hpp"
#include "HAL.hpp"

int main() {
    DInput10Module 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 5 and 6
    module.setPulseFilterTime(DInput10Module::DI_INPUT05 | DInput10Module::DI_INPUT06, 100);

    uint8_t d_inputs[DInput10Module::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 < DInput10Module::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(DInput10Module::DI_INPUT01, &d_input) == 0) {
            printf("DI01 = %x\n", d_input);
        }

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

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

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

        sleepMs(1000);
    }
}

Public Functions

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

Initialize module. It is important to emphasize that init() 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)

Initialize module. It is important to emphasize that init() 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

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

EmodRet getStatus(const uint16_t DI_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] it's true 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 DI_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 DI_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 DI_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 DI_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 DI_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 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 DI_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()

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 = DInput10Module_INPUT01
static constexpr uint16_t DI_INPUT02 = DInput10Module_INPUT02
static constexpr uint16_t DI_INPUT03 = DInput10Module_INPUT03
static constexpr uint16_t DI_INPUT04 = DInput10Module_INPUT04
static constexpr uint16_t DI_INPUT05 = DInput10Module_INPUT05
static constexpr uint16_t DI_INPUT06 = DInput10Module_INPUT06
static constexpr uint16_t DI_INPUT07 = DInput10Module_INPUT07
static constexpr uint16_t DI_INPUT08 = DInput10Module_INPUT08
static constexpr uint16_t DI_INPUT09 = DInput10Module_INPUT09
static constexpr uint16_t DI_INPUT10 = DInput10Module_INPUT10
static constexpr uint16_t DI_ALL_INPUT = DInput10Module_ALL_INPUT
static constexpr uint8_t NUMBER_OF_DI_INPUTS = DInput10Module_NUMBER_OF_DI_INPUTS
static constexpr uint32_t MODE_PRETRIGGER_TIME = DInput10Module_MODE_PRETRIGGER_TIME
static constexpr uint32_t MODE_PULSE_COUNTER = DInput10Module_MODE_PULSE_COUNTER
static constexpr uint32_t MODE_WIDTH_COUNTER = DInput10Module_MODE_WIDTH_COUNTER
static constexpr uint8_t idFunctionINPUTS = DInput10Module_idFunctionINPUTS
static constexpr uint8_t idFunctionCOUNTER01 = DInput10Module_idFunctionCOUNTER01
static constexpr uint8_t idFunctionCOUNTER02 = DInput10Module_idFunctionCOUNTER02
static constexpr uint8_t idFunctionCOUNTER03 = DInput10Module_idFunctionCOUNTER03
static constexpr uint8_t idFunctionCOUNTER04 = DInput10Module_idFunctionCOUNTER04
static constexpr uint8_t idFunctionCOUNTER05 = DInput10Module_idFunctionCOUNTER05
static constexpr uint8_t idFunctionCOUNTER06 = DInput10Module_idFunctionCOUNTER06
static constexpr uint8_t idFunctionCOUNTER07 = DInput10Module_idFunctionCOUNTER07
static constexpr uint8_t idFunctionCOUNTER08 = DInput10Module_idFunctionCOUNTER08
static constexpr uint8_t idFunctionCOUNTER09 = DInput10Module_idFunctionCOUNTER09
static constexpr uint8_t idFunctionCOUNTER10 = DInput10Module_idFunctionCOUNTER10

Protected Functions

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

Protected Attributes

DigitalInputFunctions *digitalInputs