parent
515e9055d0
commit
ae81a1f11d
@ -0,0 +1,13 @@
|
||||
#ifndef _EXECUTEBASH_H_
|
||||
#define _EXECUTEBASH_H_
|
||||
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <array>
|
||||
|
||||
std::string execBash(const char* cmd);
|
||||
|
||||
#endif //_EXECUTEBASH_H_
|
@ -0,0 +1,16 @@
|
||||
#include "i2c_driver.h"
|
||||
#include "systemCall.h"
|
||||
|
||||
I2C_Driver::I2C_Driver()
|
||||
{
|
||||
}
|
||||
|
||||
std::string I2C_Driver::readByte(const uint8_t& address, const uint8_t& reg)
|
||||
{
|
||||
std::string addrs = std::to_string(address);
|
||||
std::string regs = std::to_string(reg);
|
||||
std::string command = "i2cget -y 1 " + addrs + " " + regs;
|
||||
char* c = const_cast<char*>(command.c_str());
|
||||
return execBash(c);
|
||||
}
|
||||
|
@ -0,0 +1,24 @@
|
||||
#include <stdint.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
class I2C_Driver
|
||||
{
|
||||
public:
|
||||
I2C_Driver();
|
||||
std::string readByte(const uint8_t& address, const uint8_t& reg);
|
||||
uint16_t readWord(const uint8_t& address, const uint8_t& reg);
|
||||
|
||||
bool writeByte(const uint8_t& address, const uint8_t& reg, const uint8_t& data); // retuns 0 when a sucsessful transation ocures
|
||||
bool writeWord(const uint8_t& address, const uint8_t& reg, const uint16_t& data); // retuns 0 when a sucsessful transation ocures
|
||||
|
||||
private:
|
||||
/* unsigned char device_address;
|
||||
unsigned char device_reg;
|
||||
unsigned char send_buffer[100];
|
||||
unsigned char recieve_buffer[100];
|
||||
unsigned char blocks;
|
||||
*/
|
||||
};
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,15 @@
|
||||
#include "systemCall.h"
|
||||
|
||||
|
||||
std::string execBash(const char* cmd) {
|
||||
std::array<char, 128> buffer;
|
||||
std::string result;
|
||||
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd, "r"), pclose);
|
||||
if (!pipe) {
|
||||
throw std::runtime_error("popen() failed!");
|
||||
}
|
||||
while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
|
||||
result += buffer.data();
|
||||
}
|
||||
return result;
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
#ifndef _SYSTEMCALL_H_
|
||||
#define _SYSTEMCALL_H_
|
||||
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <array>
|
||||
|
||||
// Ide from : https://stackoverflow.com/questions/478898/how-do-i-execute-a-command-and-get-the-output-of-the-command-within-c-using-po
|
||||
std::string execBash(const char* cmd);
|
||||
|
||||
#endif // _SYSTEMCALL_H_
|
Binary file not shown.
Loading…
Reference in new issue