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
DigitalSlaveInput1.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++ DigitalSlaveInput1.cpp -L../ -lhubo -lpthread -lrt -o DigitalSlaveInput1.out
12 Run:
13 sudo ./DigitalSlaveInput1.out
14 Purpose:
15 Read digital inputs 0 and 1 from the I2C slave with index 0 (0x21) and display them in the console.
16 The program will not terminate. Press Ctr-C to exit.
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 Initialize();
28
29 while (1)
30 {
31 bool bState = false;
32
33 int slaveNo = 0;
34
35 // Read digital input number 0.
36 Get_Slave_DI_Channel(slaveNo, 0, bState);
37 printf ("Slave %d - digital input 0 = %s ", slaveNo, bState ? "ON " : "OFF");
38
39 // Read digital input number 1.
40 Get_Slave_DI_Channel(slaveNo, 1, bState);
41 printf ("Slave %d - digital input 1 = %s \n", slaveNo, bState ? "ON " : "OFF");
42
43 usleep (1000L * 10L);
44 }
45
46 // We won't get here - press Ctrl-C to terminate.
47 return 0;
48 }
49
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::I2C_Config::m_sI2CDevice
const char * m_sI2CDevice
Definition: hubocfg.h:48
main
int main(void)
Definition: DigitalSlaveInput1.cpp:19
HuboLib::Initialize
bool Initialize()
Initializes the library.
HuboLib::g_I2CConfig
I2C_Config g_I2CConfig
HuboLib
Definition: hubocfg.h:10