Hubo Library

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

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
177 bool Wait_For_MCP23017_Buffered_Values();
178
188 bool Initialize_MCP23017_Slaves ();
189
203 bool Wait_For_MCP23017_Slaves_Buffered_Values();
204
214 bool Initialize_MCP3x08 ();
215
229 bool Wait_For_MCP3x08_Buffered_Values();
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
915 enum FunctionSelectType
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
935 enum PullUpDownType
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
HuboLib::Get_Slave_DI_Channel
bool Get_Slave_DI_Channel(int slaveNo, int channel, bool &bValue)
Retrieves the value of one digital input for a given slave.
HuboLib::Initialize_MCP3x08
bool Initialize_MCP3x08()
Low level initialization of the MCP3x08 analog input chip.
HuboLib::Wait_For_MCP3x08_Buffered_Values
bool Wait_For_MCP3x08_Buffered_Values()
Waits until the input buffer of the MCP3x08 are initialized from the hardware.
BCM2835::Alternate3
Definition: hubolib.h:922
BCM2835::ReadPin
unsigned short ReadPin(unsigned short pin)
Reads the value of an (input) pin.
BCM2835::Output
Definition: hubolib.h:918
BCM2835::Alternate2
Definition: hubolib.h:921
HuboLib::Delay_MicroSeconds
void Delay_MicroSeconds(unsigned long delay_micros)
delays the execution of the calling thread for the given number of micro seconds. ...
MAX_MCP3x08_CHANNELS
#define MAX_MCP3x08_CHANNELS
Definition: hubolib.h:39
HuboLib::Unregister_ChannelDelayCallback
bool Unregister_ChannelDelayCallback(T_pfn_ChannelDelayCallback pFnChannelDelayCallback)
Unregister a callback previouly registered by a call to Register_ChannelDelayCallback().
HuboLib::Get_MCP9700_Temperature
double Get_MCP9700_Temperature(double volt)
Converts a voltage value of an MCP9700 temperature sensor into the equivalent temperature.
BCM2835::IsGPIOInitialized
bool IsGPIOInitialized()
Returns the status of the initialisation of the GPIO part of the library.
HuboLib::Set_DO_Channel
bool Set_DO_Channel(int channel, bool bValue)
Requests the background thread to set one of the digital outputs to the value specified.
HuboLib::Get_Slave_DO_Channels
bool Get_Slave_DO_Channels(int slaveNo, unsigned char &value)
Retrieves the requested digital output value from the output buffer for a given slave.
HuboLib::Initialize
bool Initialize()
Initializes the library.
HuboLib::Get_AI_Channel_Raw
bool Get_AI_Channel_Raw(int channel, unsigned short &value)
Gets an unbuffered value from the MCP3x08.
BCM2835::SetPin
void SetPin(unsigned char pin)
Sets a pin configured as output to 1.
BCM2835::Alternate5
Definition: hubolib.h:924
HuboLib::Get_DI_Channels_Raw
bool Get_DI_Channels_Raw(unsigned char &values)
Retrieves the unbuffered values of all digital inputs (of the Hubo master module).
HuboLib::Set_Slave_DO_Channel
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...
HuboLib::Set_DO_Channels
bool Set_DO_Channels(unsigned char value)
Requests the background thread to update all 8 bits of the digital output to the value specified...
HuboLib::Get_VRef
double Get_VRef()
Retrieves the reference voltage value used for ADC count convertion.
HuboLib::T_pfn_DIChangedCallback
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
BCM2835::FunctionSelectType
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
HuboLib::Is_DS18x20_Devices
bool Is_DS18x20_Devices(const char *pSensorID)
Check whether a 1wire device name refers to a DS18S20 or DS18B20 temperature sensor.
HuboLib::Get_VRef_Raw
double Get_VRef_Raw()
Retrieves the reference voltage value used for ADC count convertion.
HuboLib::Get_DO_Channels
bool Get_DO_Channels(unsigned char &value)
Retrieves the requested digital output value from the output buffer.
HuboLib::Set_Cycle_Time
bool Set_Cycle_Time(long cycleTime)
Sets the backgrounds threads polling interval in ms.
BCM2835::Alternate0
Definition: hubolib.h:919
BCM2835::FunctionSelectPin
void FunctionSelectPin(unsigned char pin, FunctionSelectType mode)
Use FunctionSelect() to configure the mode of a BCM2835 pin.
HuboLib::Unregister_DIChangedCallback
bool Unregister_DIChangedCallback(T_pfn_DIChangedCallback pFnDIChangedCallback)
Unregister a callback previouly registered by a call to Register_DIChangedCallback().
BCM2835::PullUpDownType
PullUpDownType
Pins configured as input can make use of internal pull up or down resistors.
Definition: hubolib.h:935
BCM2835::Alternate1
Definition: hubolib.h:920
HuboLib::Wait_For_MCP23017_Slaves_Buffered_Values
bool Wait_For_MCP23017_Slaves_Buffered_Values()
Waits until input and output buffers of the MCP23017 slaves are initialized from the hardware...
HuboLib::Unregister_CycleTickCallback
bool Unregister_CycleTickCallback(T_pfn_CycleTickCallback pFnCycleTickCallback)
Unregister a callback previouly registered by a call to Register_CycleTickCallback().
__int64
#define __int64
Definition: hubolib.h:47
HuboLib::Initialize_MCP23017
bool Initialize_MCP23017()
Low level initialization of the MCP23017 IO expander.
HuboLib::T_pfn_CycleTickCallback
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
HuboLib::VersionInfo
void VersionInfo()
Prints version information and other stuff regarding to the library to the console.
HuboLib::Register_DIChangedCallback
bool Register_DIChangedCallback(T_pfn_DIChangedCallback pFnDIChangedCallback)
Register a callback to be called whenever one or more of the digital inputs have changed.
HuboLib::Get_AI_Channel
bool Get_AI_Channel(int channel, unsigned long &count, double &volt)
Get the buffered and oversampled data from the MCP3x08.
BCM2835::FSEL_MASK
Definition: hubolib.h:925
BCM2835::Alternate4
Definition: hubolib.h:923
BCM2835::WritePin
void WritePin(unsigned char pin, unsigned char value)
Sets or clears a pin configured to be an output.
HuboLib::Readback_Slave_DO_Channels
bool Readback_Slave_DO_Channels(int slaveNo, unsigned char &value)
Reads back the digital output latchs of the IO expander for a given slave.
HuboLib::Get_Slave_DI_Channels
bool Get_Slave_DI_Channels(int slaveNo, unsigned char &value)
Retrieves the value of all digital inputs.
HuboLib::T_pfn_ChannelDelayCallback
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
HuboLib::Set_MCP3x08_Oversampling
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.
HuboLib::Uninitialize
void Uninitialize()
Releases any resources bound to the library.
BCM2835::PUD_OFF
Definition: hubolib.h:937
HuboLib::Get_DS18x20_Temperature
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.
BCM2835::Input
Definition: hubolib.h:917
BCM2835::ClearPin
void ClearPin(unsigned char pin)
Resets a pin configured as output to 0.
HuboLib::Get_DI_Channels
bool Get_DI_Channels(unsigned char &value)
Retrieves the value of all digital inputs.
BCM2835::PUD_DOWN
Definition: hubolib.h:938
HuboLib::Get_1w_Devices
bool Get_1w_Devices(std::vector< std::string > &deviceList)
Returns a list of 1wire devices found on the bus.
HuboLib::Set_VRef
void Set_VRef(double volt)
Set the reference voltage value for the ADC.
HuboLib::Set_Slave_DO_Channels
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 ...
HuboLib::GetTime_MicroSeconds
unsigned long long GetTime_MicroSeconds()
Returns the number of micro seconds.
HuboLib::Wait_For_MCP23017_Buffered_Values
bool Wait_For_MCP23017_Buffered_Values()
Waits until input and output buffers of the MCP23017 master are initialized from the hardware...
HuboLib::Test_AD_Board
void Test_AD_Board()
BCM2835
Definition: hubocfg.h:71
BCM2835::PUD_UP
Definition: hubolib.h:939
HuboLib::Get_MCP9701_Temperature
double Get_MCP9701_Temperature(double volt)
Converts a voltage value of an MCP9701 temperature sensor into the equivalent temperature.
HuboLib::GetSlaveDeviceList
bool GetSlaveDeviceList(std::vector< int > &slaveAddressList)
Returns the list of I2C addresses of the MCP23017 slaves.
HuboLib::Get_DI_Channel
bool Get_DI_Channel(int channel, bool &bValue)
Retrieves the value of one digital input.
HuboLib::Readback_DO_Channels
bool Readback_DO_Channels(unsigned char &value)
Reads back the digital output latchs of the IO expander.
HuboLib::Register_ChannelDelayCallback
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...
HuboLib::Register_CycleTickCallback
bool Register_CycleTickCallback(T_pfn_CycleTickCallback pFnCycleTickCallback)
Registers a callback function called on every cycle tick.
HuboLib::Initialize_MCP23017_Slaves
bool Initialize_MCP23017_Slaves()
Low level initialization of the MCP23017 IO expander slaves.
HuboLib
Definition: hubocfg.h:10
BCM2835::SetPullUpDown
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...