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
DigitalSlaveInput2.cpp
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <unistd.h>
3
4 #include "../hubolib.h"
5 #include "../hubocfg.h" // Required for changing default I2C device.
6
7 using namespace HuboLib;
8
9 /*
10 Compile and link:
11 g++ DigitalSlaveInput2.cpp -L../ -lhubo -lpthread -lrt -o DigitalSlaveInput2.out
12 Run:
13 sudo ./DigitalSlaveInput2.out
14 Purpose:
15 Read all digital inputs of I2cSlave 0 (0x21) in one go.
16 The program will terminate when digital input 2 is lowered to ground.
17 */
18
19 int main(void)
20 {
21 // If required - set the I2C device to work with. The Raspberry Pi uses "/dev/i2c-1" which is default, the Banana Pi uses "/dev/i2c-0"
22 #ifdef BPI
23 g_I2CConfig.m_sI2CDevice = "/dev/i2c-0";
24 #endif
25
26 // Initialize the library once in your program.
27 if (!Initialize())
28 {
29 printf ("Error: Initialize\n");
30 return 1;
31 }
32
33 int slaveNo = 0;
34 unsigned char allInputs = 0;
35
36 while (1)
37 {
38 // Read all 8 digital inputs.
39 Get_Slave_DI_Channels(slaveNo, allInputs);
40 printf ("Slave %d - digital inputs (hex) = 0x%02X\n", slaveNo, allInputs);
41
42 // Break if input 2 is lowered.
43 if (~allInputs & 4)
44 break;
45
46 usleep (1000L * 10L);
47
48 }
49
50 // Free library resources.
51 Uninitialize();
52
53 return 0;
54 }
HuboLib::I2C_Config::m_sI2CDevice
const char * m_sI2CDevice
Definition: hubocfg.h:48
HuboLib::Initialize
bool Initialize()
Initializes the library.
main
int main(void)
Definition: DigitalSlaveInput2.cpp:19
HuboLib::g_I2CConfig
I2C_Config g_I2CConfig
HuboLib::Get_Slave_DI_Channels
bool Get_Slave_DI_Channels(int slaveNo, unsigned char &value)
Retrieves the value of all digital inputs.
HuboLib::Uninitialize
void Uninitialize()
Releases any resources bound to the library.
HuboLib
Definition: hubocfg.h:10