Bioscara
DALSA's DIY SCARA Robot Arm.
Loading...
Searching...
No Matches
mJoint.hpp
Go to the documentation of this file.
1
15
17{
31 template <typename T>
32 int Joint::read(const stp_reg_t reg, T &data, u_int8_t &flags)
33 {
34 size_t size = sizeof(T) + RFLAGS_SIZE;
35 char buf[MAX_BUFFER + RFLAGS_SIZE];
36 int n = readFromI2CDev(this->handle, reg, buf, size);
37 if (n != static_cast<int>(size))
38 {
39 return -1;
40 }
41 memcpy(&data, buf, size - RFLAGS_SIZE);
42 memcpy(&flags, buf + size - RFLAGS_SIZE, RFLAGS_SIZE);
43 return 0;
44 }
45
61 template <typename T>
62 int Joint::write(const stp_reg_t reg, T data, u_int8_t &flags)
63 {
64 size_t size = sizeof(T) + RFLAGS_SIZE;
65 char buf[MAX_BUFFER + RFLAGS_SIZE];
66 memcpy(buf, &data, size - RFLAGS_SIZE);
67 int rc = writeToI2CDev(this->handle, reg, buf, size - RFLAGS_SIZE, buf + size - RFLAGS_SIZE);
68 rc = rc > 0 ? 0 : rc;
69 memcpy(&flags, buf + size - RFLAGS_SIZE, RFLAGS_SIZE);
70 return rc;
71 }
72}
u_int8_t flags
State flags transmitted with every I2C transaction.
Definition mBaseJoint.h:394
stp_reg_t
register and command definitions
Definition mBaseJoint.h:39
int write(const stp_reg_t reg, T data, u_int8_t &flags)
Wrapper function to send command to the I2C slave.
Definition mJoint.hpp:62
int read(const stp_reg_t reg, T &data, u_int8_t &flags)
Wrapper function to request data from the I2C slave.
Definition mJoint.hpp:32
int handle
I2C bus handle.
Definition mJoint.h:175
A file containing utility macros and functions.
#define MAX_BUFFER
Maximum size of I2C Payload in bytes.
Definition joint.h:26
#define RFLAGS_SIZE
Size of the return flags in bytes.
Definition joint.h:33
File including the Joint class.
Definition mBaseJoint.h:19
Low level utility for I2C communication on Raspberry Pi using lgpio library.
int readFromI2CDev(const int dev_handle, const int reg, char *buffer, const int data_length)
reads block of bytes from device to buffer
Definition uI2C.cpp:16
int writeToI2CDev(const int dev_handle, const int reg, char *tx_buffer, const int data_length, char *RFLAGS_buffer)
writes block of bytes from buffer to device
Definition uI2C.cpp:36