/*
* This class will make use of the nanosleep() function.
* Just to make my original code a little bit smaller...
*
* Usage :
*
* #include "sleep.h"
*
* sleep sl ;
* sl.sleepSec(0.1) // wait 0.1 sec
* sl.sleepNanoSec(100000000) ; // wait 0.1 sec
*
* The function returns a 0 if it failed, 1 if succeeded
*/
/*
* File: sleep.h
* Author: Steven Noppe
*
* Created on 5 februari 2017, 10:03
*/
#ifndef SLEEP_H
#define SLEEP_H
#include <time.h>
class sleep
{
private:
timespec waitTime ;
float hours ;
float minutes ;
float seconds ;
float milliseconds ;
float microseconds ;
longint nanoseconds ;
void resetAll() ;
public:
sleep() ;
int sleepSec(float s) ;
int sleepNanoSec(longint nanoS) ;
int sleepMicroSec(float microS) ;
int sleepMilliSec(float milliS) ;
};
#endif /* SLEEP_H */
#ifndef HMC5883L_H
#define HMC5883L_H
#include <linux/i2c-dev.h> // for the ioctl() function
#include <cmath> // for some math functions
#include <unistd.h> // for the read() and write() function
#include <fcntl.h> // for the open() function
#include <cstdlib> // for the exit() function
#include <fstream> // for some streaming functions...
#include <sstream> // for using string streams
#include <string.h> // for manipulating strings
#include <iomanip> // for setw() and setfill() functions
#include "sleep.h"
/*
* Compiling with GCC, gives a fault because M_PI is not defined
* With an IDE like Netbeans, we do not have that problem
* Thats why we define it here
*/
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
/*
* Same problem here with GCC, it seems he doesn't know what 'true' is
*/
#ifndef true
#define true 1
#endif
usingnamespace std;
class HMC5883L
{
private:
sleep sl ;
short x ;
short y ;
short z ;
short xOffset ;
short yOffset ;
float angle ;
float declinationDegree ;
float declinationMinutes ;
int fd ; // 'fd' stands for 'file descriptor'
unsignedchar buf[16] ;
public:
HMC5883L(short xO, short yO, float declDegree, float declMinutes) ;
short getX()
{
return x ;
}
short getY()
{
return y ;
}
short getZ()
{
return z ;
}
void setXOffset(short xO)
{
xOffset = xO ;
}
void setYOffset(short yO)
{
yOffset = yO ;
}
float getAngle()
{
return angle ;
}
void updateData() ;
void calibrateHMC5883L() ;
void calibrateHMC5883L(int xOffs, int yOffs) ;
} ;
#endif /* HMC5883L_H */