Hubo Library
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
LoadTest.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++ LoadTest.cpp -L../ -lhubo -lpthread -lrt -o LoadTest.out
12 Run:
13  sudo ./LoadTest.out
14 Purpose:
15  Lets turn on all relais, and go into an infinite loop to have the CPU consume as much power as possible.
16 */
17 
18 int main(int argc, char* argv[])
19 {
20  if (argc != 2)
21  {
22  printf ("Usage: \n LoadTest.out <digital outputs to activate>\n example: LoadTest.out 5 // this will set channels 0 and 2\n");
23  return 1;
24  }
25 
26  int outValue = 0;
27  if (sscanf (argv[1], "%d", &outValue) != 1)
28  {
29  printf ("Digital output could not be determined!\n");
30  return 1;
31  }
32 
33  printf ("Setting digital outputs to 0x%02X.\n", outValue);
34  printf ("Hit Ctrl+C to terminate.\n");
35 
36  // 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"
37  #ifdef BPI
38  g_I2CConfig.m_sI2CDevice = "/dev/i2c-0";
39  #endif
40 
41  // Initialize the library once in your program.
42  if (!Initialize())
43  {
44  printf ("Error: Initialize\n");
45  return 1;
46  }
47 
48  // Set the cycle time to 2ms (500Hz).
49  Set_Cycle_Time(2);
50 
51  // Finally set the output.
52  Set_DO_Channels (outValue);
53 
54  // Press Ctrl-C to stop.
55  while (1);
56 
57  // Free library resources.
58  Uninitialize();
59 
60  return 0;
61 }
const char * m_sI2CDevice
Definition: hubocfg.h:48
int main(int argc, char *argv[])
Definition: LoadTest.cpp:18
bool Initialize()
Initializes the library.
bool Set_DO_Channels(unsigned char value)
Requests the background thread to update all 8 bits of the digital output to the value specified...
bool Set_Cycle_Time(long cycleTime)
Sets the backgrounds threads polling interval in ms.
I2C_Config g_I2CConfig
void Uninitialize()
Releases any resources bound to the library.