Hubo Library
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
hubolib.h
Go to the documentation of this file.
1 #ifndef HUBOLIB_H
2  #define HUBOLIB_H
3 
4 
5 #include <vector>
6 #include <string>
7 
8 namespace HuboLib
9 {
34  // ************************************************************************************************
35  // Definitions
36  // ************************************************************************************************
37 
38  #ifndef MAX_MCP3x08_CHANNELS
39  #define MAX_MCP3x08_CHANNELS (8)
40  #endif
41 
42  #ifndef MAX_MCP23017_SLAVES
43  #define MAX_MCP23017_SLAVES (7)
44  #endif
45 
46  #ifndef __int64
47  #define __int64 long long
48  #endif
49 
73  typedef void (*T_pfn_CycleTickCallback) (unsigned long* pADChannelValues, unsigned char* pDigitalInputValues, unsigned char* pDigitalOutputValues);
74 
95  typedef void (*T_pfn_ChannelDelayCallback) (__int64 cycleCount, __int64 t_Overrun_ms);
96 
115  typedef void (*T_pfn_DIChangedCallback) (unsigned char changedDigitalInputValues, unsigned char digitalInputValues);
116 
117 
118 
119 
120 
121  // ************************************************************************************************
122  // Hubo initialization
123  // ************************************************************************************************
124 
141  bool Initialize ();
142 
151  void Uninitialize ();
152 
162  bool Initialize_MCP23017 ();
163 
178 
189 
204 
214  bool Initialize_MCP3x08 ();
215 
230 
231 
232 
233 
234  // ************************************************************************************************
235  // Timing and monitoring support
236  // ************************************************************************************************
237 
261  bool Set_Cycle_Time (long cycleTime);
262 
283  bool Register_CycleTickCallback (T_pfn_CycleTickCallback pFnCycleTickCallback);
284 
297  bool Unregister_CycleTickCallback (T_pfn_CycleTickCallback pFnCycleTickCallback);
298 
328  bool Register_ChannelDelayCallback (T_pfn_ChannelDelayCallback pFnChannelDelayCallback);
329 
342  bool Unregister_ChannelDelayCallback (T_pfn_ChannelDelayCallback pFnChannelDelayCallback);
343 
344 
345 
346 
347  // ************************************************************************************************
348  // Digital output support
349  // ************************************************************************************************
350 
364  bool Set_DO_Channels (unsigned char value);
365 
379  bool Set_Slave_DO_Channels (int slaveNo, unsigned char value);
380 
395  bool Set_DO_Channel (int channel, bool bValue);
396 
411  bool Set_Slave_DO_Channel (int slaveNo, int channel, bool bValue);
412 
429  bool Get_DO_Channels (unsigned char& value);
430 
443  bool Get_Slave_DO_Channels (int slaveNo, unsigned char& value);
444 
461  bool Readback_DO_Channels (unsigned char& value);
462 
475  bool Readback_Slave_DO_Channels (int slaveNo, unsigned char& value);
476 
477 
478 
479 
480 
481  // ************************************************************************************************
482  // Digital input support
483  // ************************************************************************************************
484 
497  bool Get_DI_Channels (unsigned char& value);
498 
517  bool Get_DI_Channels_Raw (unsigned char& values);
518 
532  bool Get_Slave_DI_Channels (int slaveNo, unsigned char& value);
533 
548  bool Get_DI_Channel (int channel, bool& bValue);
549 
564  bool Get_Slave_DI_Channel (int slaveNo, int channel, bool& bValue);
565 
566 
587  bool Register_DIChangedCallback (T_pfn_DIChangedCallback pFnDIChangedCallback);
588 
601  bool Unregister_DIChangedCallback (T_pfn_DIChangedCallback pFnDIChangedCallback);
602 
603 
604 
605 
606 
607  // ************************************************************************************************
608  // Analog input support
609  // ************************************************************************************************
610 
624  void Set_VRef (double volt);
625 
636  double Get_VRef ();
637 
651  double Get_VRef_Raw ();
652 
683  bool Set_MCP3x08_Oversampling (unsigned short overSampling[MAX_MCP3x08_CHANNELS]);
684 
705  bool Get_AI_Channel (int channel, unsigned long& count, double& volt);
706 
730  bool Get_AI_Channel_Raw (int channel, unsigned short& value);
731 
732 
733 
734  // ************************************************************************************************
735  // Miscellaneous
736  // ************************************************************************************************
737 
746  void VersionInfo ();
747 
761  double Get_MCP9701_Temperature (double volt);
762 
777  double Get_MCP9700_Temperature (double volt);
778 
790  bool GetSlaveDeviceList (std::vector<int>& slaveAddressList);
791 
801  unsigned long long GetTime_MicroSeconds ();
802 
814  void Delay_MicroSeconds (unsigned long delay_micros);
815 
816 
817 
818 
819  // ************************************************************************************************
820  // 1wire support
821  // ************************************************************************************************
822 
835  bool Get_1w_Devices (std::vector<std::string>& deviceList);
836 
847  bool Is_DS18x20_Devices (const char* pSensorID);
848 
866  bool Get_DS18x20_Temperature (const char* pSensorID, double& temperature, bool& bCRC, long& t_duration_ms);
867 
868 
869 
870 
871  // ************************************************************************************************
872  // Deprecated functions
873  // ************************************************************************************************
874 
875  // Used for testing purposes only.
876  // Measures 2000 analog values while switching relays at the same time.
877  // Min and max values are printed out afterwards.
878  void Test_AD_Board ();
879 
880 } // namespace HuboLib
881 
882 
883 
884 
885 namespace BCM2835
886 {
887 
888  // ************************************************************************************************
889  // BCM2835 GPIO
890  // ************************************************************************************************
891 
916  {
917  Input = 0x00,
918  Output = 0x01,
919  Alternate0 = 0x04,
920  Alternate1 = 0x05,
921  Alternate2 = 0x06,
922  Alternate3 = 0x07,
923  Alternate4 = 0x03,
924  Alternate5 = 0x02,
925  FSEL_MASK = 0x07
926  };
927 
936  {
937  PUD_OFF = 0x00,
938  PUD_DOWN = 0x01,
939  PUD_UP = 0x02
940  };
941 
950  bool IsGPIOInitialized ();
951 
963  void FunctionSelectPin (unsigned char pin, FunctionSelectType mode);
964 
975  void WritePin (unsigned char pin, unsigned char value);
976 
986  void SetPin (unsigned char pin);
987 
997  void ClearPin (unsigned char pin);
998 
1008  void SetPullUpDown (unsigned char pin, PullUpDownType pud);
1009 
1021  unsigned short ReadPin (unsigned short pin);
1022 
1023 } // namespace BCM2835
1024 
1025 #endif // HUBOLIB_H
1026 
bool Get_Slave_DI_Channel(int slaveNo, int channel, bool &bValue)
Retrieves the value of one digital input for a given slave.
bool Initialize_MCP3x08()
Low level initialization of the MCP3x08 analog input chip.
bool Wait_For_MCP3x08_Buffered_Values()
Waits until the input buffer of the MCP3x08 are initialized from the hardware.
unsigned short ReadPin(unsigned short pin)
Reads the value of an (input) pin.
void Delay_MicroSeconds(unsigned long delay_micros)
delays the execution of the calling thread for the given number of micro seconds. ...
#define MAX_MCP3x08_CHANNELS
Definition: hubolib.h:39
bool Unregister_ChannelDelayCallback(T_pfn_ChannelDelayCallback pFnChannelDelayCallback)
Unregister a callback previouly registered by a call to Register_ChannelDelayCallback().
double Get_MCP9700_Temperature(double volt)
Converts a voltage value of an MCP9700 temperature sensor into the equivalent temperature.
bool IsGPIOInitialized()
Returns the status of the initialisation of the GPIO part of the library.
bool Set_DO_Channel(int channel, bool bValue)
Requests the background thread to set one of the digital outputs to the value specified.
bool Get_Slave_DO_Channels(int slaveNo, unsigned char &value)
Retrieves the requested digital output value from the output buffer for a given slave.
bool Initialize()
Initializes the library.
bool Get_AI_Channel_Raw(int channel, unsigned short &value)
Gets an unbuffered value from the MCP3x08.
void SetPin(unsigned char pin)
Sets a pin configured as output to 1.
bool Get_DI_Channels_Raw(unsigned char &values)
Retrieves the unbuffered values of all digital inputs (of the Hubo master module).
bool Set_Slave_DO_Channel(int slaveNo, int channel, bool bValue)
Requests the background thread to set one of the digital outputs to the value specified for a given s...
bool Set_DO_Channels(unsigned char value)
Requests the background thread to update all 8 bits of the digital output to the value specified...
double Get_VRef()
Retrieves the reference voltage value used for ADC count convertion.
void(* T_pfn_DIChangedCallback)(unsigned char changedDigitalInputValues, unsigned char digitalInputValues)
Prototype definition of the callback function beeing called whenever a change of any of the digital i...
Definition: hubolib.h:115
FunctionSelectType
Prior to using a GPIO pin it requires to get defined for its use as input, output or one of the alter...
Definition: hubolib.h:915
bool Is_DS18x20_Devices(const char *pSensorID)
Check whether a 1wire device name refers to a DS18S20 or DS18B20 temperature sensor.
double Get_VRef_Raw()
Retrieves the reference voltage value used for ADC count convertion.
bool Get_DO_Channels(unsigned char &value)
Retrieves the requested digital output value from the output buffer.
bool Set_Cycle_Time(long cycleTime)
Sets the backgrounds threads polling interval in ms.
void FunctionSelectPin(unsigned char pin, FunctionSelectType mode)
Use FunctionSelect() to configure the mode of a BCM2835 pin.
bool Unregister_DIChangedCallback(T_pfn_DIChangedCallback pFnDIChangedCallback)
Unregister a callback previouly registered by a call to Register_DIChangedCallback().
PullUpDownType
Pins configured as input can make use of internal pull up or down resistors.
Definition: hubolib.h:935
bool Wait_For_MCP23017_Slaves_Buffered_Values()
Waits until input and output buffers of the MCP23017 slaves are initialized from the hardware...
bool Unregister_CycleTickCallback(T_pfn_CycleTickCallback pFnCycleTickCallback)
Unregister a callback previouly registered by a call to Register_CycleTickCallback().
#define __int64
Definition: hubolib.h:47
bool Initialize_MCP23017()
Low level initialization of the MCP23017 IO expander.
void(* T_pfn_CycleTickCallback)(unsigned long *pADChannelValues, unsigned char *pDigitalInputValues, unsigned char *pDigitalOutputValues)
Prototype definition of the callback function beeing called an every cycle time tick.
Definition: hubolib.h:73
void VersionInfo()
Prints version information and other stuff regarding to the library to the console.
bool Register_DIChangedCallback(T_pfn_DIChangedCallback pFnDIChangedCallback)
Register a callback to be called whenever one or more of the digital inputs have changed.
bool Get_AI_Channel(int channel, unsigned long &count, double &volt)
Get the buffered and oversampled data from the MCP3x08.
void WritePin(unsigned char pin, unsigned char value)
Sets or clears a pin configured to be an output.
bool Readback_Slave_DO_Channels(int slaveNo, unsigned char &value)
Reads back the digital output latchs of the IO expander for a given slave.
bool Get_Slave_DI_Channels(int slaveNo, unsigned char &value)
Retrieves the value of all digital inputs.
void(* T_pfn_ChannelDelayCallback)(__int64 cycleCount, __int64 t_Overrun_ms)
Prototype definition of the callback function beeing called when the cycle time slice has been violat...
Definition: hubolib.h:95
bool Set_MCP3x08_Oversampling(unsigned short overSampling[MAX_MCP3x08_CHANNELS])
Specifies the ADC channels to be sampled as well as the number they get oversampled.
void Uninitialize()
Releases any resources bound to the library.
bool Get_DS18x20_Temperature(const char *pSensorID, double &temperature, bool &bCRC, long &t_duration_ms)
Retrieve temperature, CRC value and the time that was required to read the temperature.
void ClearPin(unsigned char pin)
Resets a pin configured as output to 0.
bool Get_DI_Channels(unsigned char &value)
Retrieves the value of all digital inputs.
bool Get_1w_Devices(std::vector< std::string > &deviceList)
Returns a list of 1wire devices found on the bus.
void Set_VRef(double volt)
Set the reference voltage value for the ADC.
bool Set_Slave_DO_Channels(int slaveNo, unsigned char value)
Requests the background thread to update all 8 bits of the digital output to the value specified for ...
unsigned long long GetTime_MicroSeconds()
Returns the number of micro seconds.
bool Wait_For_MCP23017_Buffered_Values()
Waits until input and output buffers of the MCP23017 master are initialized from the hardware...
void Test_AD_Board()
double Get_MCP9701_Temperature(double volt)
Converts a voltage value of an MCP9701 temperature sensor into the equivalent temperature.
bool GetSlaveDeviceList(std::vector< int > &slaveAddressList)
Returns the list of I2C addresses of the MCP23017 slaves.
bool Get_DI_Channel(int channel, bool &bValue)
Retrieves the value of one digital input.
bool Readback_DO_Channels(unsigned char &value)
Reads back the digital output latchs of the IO expander.
bool Register_ChannelDelayCallback(T_pfn_ChannelDelayCallback pFnChannelDelayCallback)
Register a callback to be called whenever the cycle time has been violated by more than one cycle tim...
bool Register_CycleTickCallback(T_pfn_CycleTickCallback pFnCycleTickCallback)
Registers a callback function called on every cycle tick.
bool Initialize_MCP23017_Slaves()
Low level initialization of the MCP23017 IO expander slaves.
void SetPullUpDown(unsigned char pin, PullUpDownType pud)
Enables or disables the BCM2835 internal pull -up or -down resistors for a pin configured as an input...