Untitled

 avatar
unknown
plain_text
2 years ago
957 B
3
Indexable
//#include "TMP102/tmp102.hpp"
#include "TF03/tf03.hpp"
#include <iostream>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <fstream>
#include <fcntl.h>


int main(int argc, char const *argv[])
{
    tf03 dist(DEFAULT_TF03_TTY_PATH);
    //tmp102 temp(DEFAULT_TMP102_TTY_PATH);
    int distance;
    int fd = open("../../Payload-SDK-master/laser_data.txt", O_WRONLY | O_CREAT, 0666);
    struct flock f1;
    f1.l_whence = SEEK_SET;
    f1.l_start = 0;
    f1.l_len = 0;
    f1.l_pid = getpid();
    
    
    while (1)
    {

        distance = dist.getDist();
        cout << distance << " cm" << endl;
        f1.l_type = F_WRLCK;
        fcntl(fd, F_SETLKW, &f1);
        FILE* file=fdopen(fd,"w");
        fprintf(file, "%d", distance);
        //temp.getTemp() << endl;
        f1.l_type=F_UNLCK;
        fcntl(fd, F_SETLKW, &f1);
        usleep(100);
        fclose(file);
    }
        

    
    
    
    
    
    return 0;
}
Editor is loading...