Exploring BeagleBone  V1.0
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
TestCode.cxx File Reference
#include <iostream>
#include "gpio/GPIO.h"
#include "gpio/PWM.h"
#include "sensor/ADXL345.h"
#include <unistd.h>
#include <pthread.h>
#include "bus/I2CDevice.h"
#include "bus/SPIDevice.h"
#include "display/SevenSegmentDisplay.h"
#include "display/LCDCharacterDisplay.h"
Include dependency graph for TestCode.cxx:

Functions

int callbackFunction (int var)
 
int main ()
 

Function Documentation

int callbackFunction ( int  var)
46  {
47  cout << "BBB Button Pressed!" << var << endl;
48  return var;
49 }
int main ( )
51  {
52 
53  int32_t x = 54;
54 
55 
56  /*if(getuid()!=0){
57  cout << "You must run this program as root. Exiting." << endl;
58  return -1;
59  }*/
60 
61  /*SPIDevice spi(1,0);
62  ADXL345 acc1(&spi);
63  acc1.displayPitchAndRoll(100);
64 
65  I2CDevice i2c(1,0x53);
66  ADXL345 acc2(&i2c);
67  acc2.displayPitchAndRoll(100);*/
68 
69 
70  LCDCharacterDisplay display(new SPIDevice(2,0), 16, 2);
71  display.clear();
72  display.setAutoscroll(true);
73 
74  //display.setScrollDisplayLeft(true);
75  //display.setCursorPosition(0,2);
76  display.print("Exploring BB");
77  //usleep(2000000);
78 
79  //display.setCursorPosition(1,0);
80  //display.print("by Derek Molloy");
81  //usleep(2000000);
82 
83 /*
84  SevenSegmentDisplay disp(new SPIDevice(1,0), 2);
85  //display.setNumberBase(7);
86  for(int i=80; i>=0; i--){
87  disp.write(i);
88  usleep(250000);
89  }*/
90 
91 
92 
93  // SPIDevice spi(1,0); // chip select 0 on bus 1
94  // spi.setSpeed(1000000); // set the speed to 1 MHz
95  // cout << "The device ID is: " << (int) spi.readRegister(0x00) << endl;
96  // spi.setMode(SPIDevice::MODE3); // set the mode to Mode3
97  // spi.writeRegister(0x2D, 0x08); // POWER_CTL for the ADXL345
98  // spi.debugDumpRegisters(0x40); // Dump the 64 registers from 0x00
99 
100 
101 
102  /*for(int i=0; i<=255; i++){
103  spi.write((unsigned int)i);
104  usleep(500000);
105  }*/
106 
107 
108 
109 
110  //cout << "The device ID is: " << (int) spi.readRegister(0x00) << endl;
111  //spi.writeRegister(0x2D, 0x08); //POWER_CTL
112  //spi.debugDumpRegisters(0x40);
113 
114 
115 
116  //spi.readRegister(0x80 + 0x32);
117  //spi.readRegister(0x80 + 0x33);
118 
119 
120  /*I2C i2c(1,0x53);
121  cout << "The address is: " << (int)i2c.readRegister(0x00) << endl;
122  unsigned char* data = i2c.readRegisters(0x40);
123  cout << "The value of the first address is: " << (int) *data << endl;*/
124 
125  /* I2C
126  ADXL345 sensor(1, 0x53);
127  sensor.readSensorState();
128  cout << "The x acceleration is " << sensor.getAccelerationX() << endl;
129  cout << "The y acceleration is " << sensor.getAccelerationY() << endl;
130  cout << "The z acceleration is " << sensor.getAccelerationZ() << endl;
131  */
132  //sensor.updateSensorState();
133 
134  //sensor.debugDumpRegisters();
135 
136  /*sensor.setResolution(ADXL345::NORMAL);
137  sensor.setRange(ADXL345::PLUSMINUS_4_G);
138  sensor.readSensorState();
139  //sensor.calculatePitchAndRoll();
140 
141  sensor.setResolution(ADXL345::HIGH);
142  sensor.setRange(ADXL345::PLUSMINUS_16_G);
143  sensor.readSensorState();*/
144 
145  // sensor.displayPitchAndRoll();
146 
147 
148 
149 
150  //cout << "**Resolution is: " << (int)sensor.getResolution() << " and Range is: " << (int)sensor.getRange() << endl;
151 
152 
153 
154  /*PWM pwm("pwm_test_P9_22.15");
155  //pwm.calibrateAnalogMax(3.318);
156  //pwm.analogWrite(1.25);
157 
158  pwm.setPeriod(10000);
159  pwm.setDutyCycle(50.0f);
160  pwm.setPolarity(PWM::ACTIVE_LOW);
161  pwm.run();*/
162 
163  /*pwm.setPeriod(10000);
164  cout << "The period is: " << pwm.getPeriod() << endl;
165  pwm.setFrequency(1000);
166  cout << "The frequency is: " << pwm.getFrequency() << endl;
167  cout << "The period is: " << pwm.getPeriod() << endl;
168  pwm.setDutyCycle(66.66f);
169  cout << "The duty cycle is: " << pwm.getDutyCycle() << endl;
170  cout << "The duty cycle% is: " << pwm.getDutyCyclePercent() << endl;
171  cout << "The polarity is: " << pwm.getPolarity() << endl;
172  pwm.invertPolarity();
173  cout << "The polarity is: " << pwm.getPolarity() << endl;
174  cout << "Is running? " << pwm.isRunning() << endl;
175  pwm.stop();
176  cout << "Is running? " << pwm.isRunning() << endl;*/
177 
178 /* cout << "BeagleBone Poll Test" << endl;
179 
180  GPIO inGPIO(48);
181  GPIO outGPIO(60);
182 
183  inGPIO.setDirection(GPIO::INPUT);
184  inGPIO.setEdgeType(GPIO::RISING);
185  outGPIO.setDirection(GPIO::OUTPUT);
186 
187  cout << "GPIO(48) has value: " << inGPIO.getValue() << endl;
188  inGPIO.setDebounceTime(200);
189  inGPIO.waitForEdge(&callbackFunction);
190  outGPIO.toggleOutput(100);
191  cout << "Poll Started: Press the button:" << endl;
192  usleep(10000000);
193  cout << "Finished sleeping for 10 seconds" << endl;*/
194 
195 
196  //GPIO outgpio(60);
197  /*gpio.setDirection(OUTPUT);
198  gpio.setEdge(NONE);
199 
200  for (int i=0; i<100000; i++){
201  gpio.setValue(HIGH);
202  gpio.setValue(LOW);
203  }*/
204 
205  /*gpio.streamOpen();
206  for (int i=0; i<1000000; i++){
207  gpio.streamWrite(HIGH);
208  gpio.streamWrite(LOW);
209  }
210  gpio.streamClose();*/
211 
212 
213  /*GPIO ingpio(48);
214  ingpio.setDirection(INPUT);
215  ingpio.setEdge(FALLING);
216  for (int i=0; i<10; i++){
217  usleep(1000000);
218  cout << "GPIO(48) has value: " << ingpio.getValue() << endl;
219  }*/
220 
221  //cout << "finished" << endl;
222  return 0;
223 }
Generic SPI Device class that can be used to connect to any type of SPI device and read or write to i...
Definition: SPIDevice.h:39
A class that provides an interface to an LCD character module. It provices support for multiple rows ...
Definition: LCDCharacterDisplay.h:39