Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <cmath>
- #include <unistd.h>
- using namespace std;
- int num=0;
- int val=0;
- double sum=0;
- double avg=0.0;
- double stDev=0.0;
- double err=0.0;
- ifstream myFile_Handler;
- int ReadSensor(string FileName);
- int main(){
- string FileX="/sys/bus/iio/devices/iio:device2/in_accel_x_raw";
- string FileY="/sys/bus/iio/devices/iio:device2/in_accel_y_raw";
- string FileZ="/sys/bus/iio/devices/iio:device2/in_accel_z_raw";
- for (;;){
- cout << " X: " << ReadSensor(FileX) << " Y: " << ReadSensor(FileY) << " Z: "<< ReadSensor(FileZ) << endl;
- sleep(1);
- cout << "\x1b[A" << "\33[2K\r" << std::flush;
- }
- return 0;
- }
- int ReadSensor(string FileName){
- int val;
- ifstream myFile_Handler;
- string myLine;
- myFile_Handler.open(FileName);
- // /sys/bus/iio/devices/iio\:device2/in_accel_x_raw
- if(myFile_Handler.is_open()) {
- while(getline(myFile_Handler, myLine)){
- val = std::stoi(myLine);
- }
- myFile_Handler.close();
- } else {
- cout << "Unable to open the file!";
- }
- return val;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement