Class DInput2Relay1Temp2Module
Defined in File DInput2Relay1Temp2Module.hpp
Inheritance Relationships
Base Type
public Module
(Class Module)
Class Documentation
-
class DInput2Relay1Temp2Module : public Module
This class represents the Digital Inputs, Power Relay and Temperature Module connected via eMOD bus to controller module. Firstly, this module has 2 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. Secondly, it has 1 power relay that can be activated or deactivated. If a polling is to be performed more than once per second, it's recommended to handle function call. Lastly, it has 2 temperature sensors and the temperature of each one can be obtained separately.
Class example 1
/* * This example uses a DInput2Relay1Temp2Module to display 2 digital inputs, activate/deactivate a relay and measure temperatures. */ #include "DInput2Relay1Temp2Module.hpp" #include "EmodRetMng.hpp" #include "HAL.hpp" int main() { printf("Initializing modulesDi2Pr1T2 ...\n\n"); DInput2Relay1Temp2Module modulesDi2Pr1T2; if (modulesDi2Pr1T2.init() != 0) { printf("Module could not be initialized!\n"); return 1; } // Configures module parameters modulesDi2Pr1T2.configAllPulseWidth(0); modulesDi2Pr1T2.setPulseFilterTime(DInput2Relay1Temp2Module::kDigitalInputAll, 10); modulesDi2Pr1T2.configAllTempSensor(DInput2Relay1Temp2Module::TempSensorConfig::kTwoWirePt100Sensor); while (1) { //Test Digital Inputs for (int j = 0; j < DInput2Relay1Temp2Module::kNumberOfDigitalInputs; j++) { uint16_t mask = 0x0001 << j; bool new_data = false; uint8_t status; uint32_t pulse_count = 0; modulesDi2Pr1T2.getStatus(mask, &status, &new_data); if (new_data) { printf("\tNEW VALUE for INPUT %.2d: %d\n", j + 1, status); } else { printf("\tNO CHANGE for INPUT %.2d: %d\n", j + 1, status); } modulesDi2Pr1T2.getPulseCount(mask, &pulse_count); printf("Pulse count DI0%d = %d\n", j, pulse_count); } //Test Temperature Sensors for (uint8_t i = 0; i < DInput2Relay1Temp2Module::kNumberOfTemperatureSensors; i++) { DInput2Relay1Temp2Module::TempSensorID proper_id = static_cast<DInput2Relay1Temp2Module::TempSensorID>(1 << i); int16_t value; modulesDi2Pr1T2.getTempSensor(proper_id, &value); printf("Temp sensor T0%d = %d\n", i, value); } //Test Relay modulesDi2Pr1T2.activateAll(); sleepMs(1000); modulesDi2Pr1T2.deactivateAll(); sleepMs(1000); } return 1; }
Public Types
-
enum class TempSensorConfig : uint8_t
Values:
-
enumerator kTwoWirePt100Sensor
-
enumerator kThreeWirePt100Sensor
-
enumerator kFourWirePt100Sensor
-
enumerator kTwoWirePt1000Sensor
-
enumerator kThreeWirePt1000Sensor
-
enumerator kFourWirePt1000Sensor
-
enumerator kTwoWirePt100Sensor
-
enum class DigitalInputFunctionMode : uint32_t
Values:
-
enumerator kPretriggerTime
-
enumerator kPulseCounter
-
enumerator kWidthCounter
-
enumerator kPretriggerTime
-
typedef void (*DInput2Relay1Temp2ModuleCallback_Type)(const uint8_t *data, uint16_t data_len, uint8_t id_function, void *ctx)
Public Functions
-
DInput2Relay1Temp2Module()
-
~DInput2Relay1Temp2Module()
-
EmodRet init(const DInput2Relay1Temp2ModuleCallback_Type callback_func = nullptr, void *const callback_context = nullptr, const uint8_t variant = 1)
Initialize module. It is important to emphasize that it is mandatory to call this method 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 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[kNumberOfDigitalInputs], 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[kNumberOfDigitalInputs])
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[kNumberOfDigitalInputs])
Gets number of pulses occurred in all inputs.
- Parameters
counts -- [out] number of pulses for each digital input.
-
EmodRet resetPulseCount(const 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 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[kNumberOfDigitalInputs])
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 uint16_t relay_mask, const uint32_t width_ms)
Configure pulse width of a relay or 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 uint16_t relay_mask)
Activates a relay or set of relays.
- Parameters
relay_mask -- [in] relay or list of relays to activate.
-
EmodRet deactivate(const uint16_t relay_mask)
Deactivates a relay or set of relays.
- Parameters
relay_mask -- [in] relay or list of relays to deactivate.
-
EmodRet getRelayStatus(const uint16_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 configTempSensor(const TempSensorID sensor_id, const TempSensorConfig config)
Select configuration on a temperature sensor.
- Parameters
sensor_mask -- [in] temperature sensor number to set the configuration, as enumerated above in the constants section.
config -- [in] type of temperature sensor as enumerated above in the constants section.
-
EmodRet configAllTempSensor(const TempSensorConfig config)
Select a common configuration on all temperature sensors.
- Parameters
config -- [in] type of temperature sensor as enumerated above in the constants section.
-
EmodRet getTempSensorConfig(const TempSensorID sensor_id, TempSensorConfig *temp_sensor_config)
Gets configuration from a specified temperature sensor.
- Parameters
sensor_mask -- [in] temperature sensor number to get the status, as enumerated above in the constants section.
config -- [out] returns the type of temperature sensor as enumerated above in the constants section.
-
EmodRet getTempSensor(const TempSensorID sensor_id, int16_t *value)
Gets temperature (in hundredths of a degree) from a specified sensor.
- Parameters
sensor_mask -- [in] temperature sensor number to get the status, as enumerated above in the constants section.
value -- [out] temperature in hundredths of a celsius degree. It is kUnplugged (as enumerated in the constants above) if the sensor is unplugged.
-
EmodRet getAllTempSensor(std::vector<int16_t> *data)
Gets all sensor temperatures (in hundredths of a degree).
- Parameters
data -- [out] a size 2 vector of temperatures. Its content is cleared in the process. Temperatures are given in hundredths of a celsius degree. A value in the vector is kUnplugged (as enumerated in the constants above) if the corresponding sensor is unplugged.
-
EmodRet configEventAtTimeIntervalDI(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 switchToModeDI(const uint16_t input_mask, const DigitalInputFunctionMode 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 configEventOnNewDataDI(void)
Configures module for calling init callback_func when new data on input occurs.
-
EmodRet configEventOnValueChangeDI(const uint32_t threshold, const uint16_t event_mask = kDigitalInputAll)
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(optional) -- [in] bit mask representing inputs that must trigger the event. Default value is kDigitalInputAll.
-
EmodRet configEventAtTimeIntervalTemp(const uint32_t time_interval, const uint32_t event_mask = kTempSensorAll)
Configures module for calling init callback_func at specified period.
- Parameters
time_interval -- [in] period in milliseconds. Minimum value is 500ms.
event_mask(optional) -- [in] bit mask representing temperature sensors that must trigger the event. Default value is kTempSensorAll.
-
EmodRet configEventOnValueChangeTemp(const uint32_t threshold, const uint32_t event_mask = kTempSensorAll)
Configures module for calling init callback_func when sensor changes its value by a specified amount.
- Parameters
threshold -- [in] amount of samples that triggers the event (use hundredths of a degree).
event_mask(optional) -- [in] bit mask representing temperature sensors that must trigger the event. Default value is kTempSensorAll.
-
EmodRet configEventWithinRangeTemp(const uint32_t low_limit, const uint32_t high_limit, const uint32_t event_mask = kTempSensorAll)
Configures module for calling init callback_func when sensor enters the specified range.
- Parameters
low_limit -- [in] low limit of the range in samples (use voltageToSample() for conversion).
high_limit -- [in] high limit of the range in samples (use voltageToSample() for conversion).
event_mask(optional) -- [in] bit mask representing inputs that must trigger the event. Default value is kTempSensorAll.
-
EmodRet configEventOutOfRangeTemp(const uint32_t low_limit, const uint32_t high_limit, const uint32_t event_mask = kTempSensorAll)
Configures module for calling init callback_func when sensor gets out of the specified range.
- Parameters
low_limit -- [in] low limit of the range in samples (use voltageToSample() for conversion).
high_limit -- [in] high limit of the range in samples (use voltageToSample() for conversion).
event_mask(optional) -- [in] bit mask representing inputs that must trigger the event. Default value is kTempSensorAll.
Public Static Attributes
-
static constexpr uint8_t kNumberOfDigitalInputs = DInput2Relay1Temp2Module_NUMBER_OF_DI
-
static constexpr uint8_t kNumberOfRelays = DInput2Relay1Temp2Module_NUMBER_OF_RELAYS
-
static constexpr uint8_t kNumberOfTemperatureSensors = DInput2Relay1Temp2Module_NUMBER_OF_TEMP
-
static constexpr int16_t kMaxTemperature = 25000
-
static constexpr int16_t kMinTemperature = -10000
-
static constexpr int16_t kUnplugged = -20099
-
static constexpr uint16_t kDigitalInputAll = DInput2Relay1Temp2Module_ALL_DIGITAL_INPUT
-
static constexpr uint16_t kRelayAll = 0x0001
-
static constexpr uint8_t kTempSensorAll = DInput2Relay1Temp2Module_ALL_TEMP_INPUT
-
enum class TempSensorConfig : uint8_t