Program Listing for File DInput2Relay1Temp2Module.hpp

Return to documentation for file (doc/include/DInput2Relay1Temp2Module.hpp)

#ifndef DINPUT2RELAY1TEMP2_MODULE_HPP_
#define DINPUT2RELAY1TEMP2_MODULE_HPP_

#include "DInput2Relay1Temp2Module.h"
#include "Module.hpp"

// Forward declaration
class RelayFunctions;
class DigitalInputFunctions;
class TemperatureFunctions;

class DInput2Relay1Temp2Module : public Module {
    friend class DInput2Relay1Temp2Napi;

protected:
    RelayFunctions* relays_;
    DigitalInputFunctions* digital_inputs_;
    TemperatureFunctions* temperature_sensors_;

    EmodRet initFunctions();

    // Needed for bindings
    uint8_t getFunctsOffsetIdDI();
    uint8_t getInputFunctsOffsetIdDI();

public:
    // Number of I/O.
    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;

    // Special Temp constants.
    static constexpr int16_t kMaxTemperature = 25000;
    static constexpr int16_t kMinTemperature = -10000;
    static constexpr int16_t kUnplugged = -20099;

    // Identifiers
    enum DigitalInputID : uint16_t {
        kDigitalInput1 = 0x0001,
        kDigitalInput2 = 0x0002,
    };

    enum RelayID : uint16_t {
        kRelay1 = 0x0001,
    };

    enum TempSensorID : uint8_t {
        kTempSensor1 = 0x01,
        kTempSensor2 = 0x02,
    };

    // All bits mask
    static constexpr uint16_t kDigitalInputAll = DInput2Relay1Temp2Module_ALL_DIGITAL_INPUT;
    static constexpr uint16_t kRelayAll = 0x0001;
    static constexpr uint8_t kTempSensorAll = DInput2Relay1Temp2Module_ALL_TEMP_INPUT;

    // Temperature Sensor Configurations
    enum class TempSensorConfig : uint8_t {
        kTwoWirePt100Sensor = 1,
        kThreeWirePt100Sensor = 2,
        kFourWirePt100Sensor = 3,
        kTwoWirePt1000Sensor = 4,
        kThreeWirePt1000Sensor = 5,
        kFourWirePt1000Sensor = 6
    };

    // Digital Input Function mode
    enum class DigitalInputFunctionMode : uint32_t {
        kPretriggerTime = 0x00000000,
        kPulseCounter = 0x00000001,
        kWidthCounter = 0x00000002,
    };

    // Type Defs

    typedef void (*DInput2Relay1Temp2ModuleCallback_Type)(const uint8_t* data, uint16_t data_len, uint8_t id_function, void* ctx);

    // Constructor, destructor and init methods
    DInput2Relay1Temp2Module();
    ~DInput2Relay1Temp2Module();

    EmodRet init(const DInput2Relay1Temp2ModuleCallback_Type callback_func = nullptr, void* const callback_context = nullptr, const uint8_t variant = 1);
    EmodRet init(const uint8_t variant);

    // DI methods

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

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

    EmodRet setPulseFilterTime(const uint16_t input_mask, const uint32_t ms_time);

    EmodRet setAllPulseFilterTime(const uint32_t ms_time);

    EmodRet getPulseFilterTime(const uint16_t input_mask, uint32_t* ms_time);

    EmodRet getAllPulseFilterTime(uint32_t ms_times[kNumberOfDigitalInputs]);

    EmodRet getPulseCount(const uint16_t input_mask, uint32_t* count);

    EmodRet getAllPulseCount(uint32_t counts[kNumberOfDigitalInputs]);

    EmodRet resetPulseCount(const uint16_t input_mask);

    EmodRet resetAllPulseCount();

    EmodRet getPulseWidth(const uint16_t input_mask, uint32_t* width);

    EmodRet getAllPulseWidth(uint32_t widths[kNumberOfDigitalInputs]);

    // Relays methods

    EmodRet configPulseWidth(const uint16_t relay_mask, const uint32_t width_ms);

    EmodRet configAllPulseWidth(const uint32_t width_ms);

    EmodRet activate(const uint16_t relay_mask);

    EmodRet deactivate(const uint16_t relay_mask);

    EmodRet activateAll(void);

    EmodRet deactivateAll(void);

    EmodRet getRelayStatus(const uint16_t relay_mask, uint8_t* status);

    EmodRet getAllRelayStatus(uint8_t* status);

    // Temperature sensor methods

    EmodRet configTempSensor(const TempSensorID sensor_id, const TempSensorConfig config);

    EmodRet configAllTempSensor(const TempSensorConfig config);

    EmodRet getTempSensorConfig(const TempSensorID sensor_id, TempSensorConfig* temp_sensor_config);

    EmodRet getTempSensor(const TempSensorID sensor_id, int16_t* value);

    EmodRet getAllTempSensor(std::vector<int16_t>* data);

    // DI Callback methods

    EmodRet configEventAtTimeIntervalDI(const uint32_t time_interval);

    EmodRet switchToModeDI(const uint16_t input_mask, const DigitalInputFunctionMode mode);

    EmodRet configEventOnNewDataDI(void);

    EmodRet configEventOnValueChangeDI(const uint32_t threshold, const uint16_t event_mask = kDigitalInputAll);

    // Temperature Callback methods

    EmodRet configEventAtTimeIntervalTemp(const uint32_t time_interval, const uint32_t event_mask = kTempSensorAll);

    EmodRet configEventOnValueChangeTemp(const uint32_t threshold, const uint32_t event_mask = kTempSensorAll);

    EmodRet configEventWithinRangeTemp(const uint32_t low_limit, const uint32_t high_limit, const uint32_t event_mask = kTempSensorAll);

    EmodRet configEventOutOfRangeTemp(const uint32_t low_limit, const uint32_t high_limit, const uint32_t event_mask = kTempSensorAll);

    EmodRet resetEventConfig(void);
};

#endif  // DINPUT2RELAY1TEMP2_MODULE_HPP_