Skip to content

Commit ef7edb7

Browse files
committed
Move other stuff from the sketch
1 parent f02e357 commit ef7edb7

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

src/MKRMotorShield.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include "MKRMotorShield.h"
2+
3+
void setDataPIDGains(Commands cmd, uint8_t target, int16_t P, int16_t I, int16_t D) {
4+
Wire.beginTransmission(I2C_ADDRESS);
5+
Wire.write((uint8_t)cmd);
6+
Wire.write((uint8_t)target);
7+
Wire.write((uint8_t*)&P, 2);
8+
Wire.write((uint8_t*)&I, 2);
9+
Wire.write((uint8_t*)&D, 2);
10+
Wire.endTransmission();
11+
}
12+
13+
void setData(Commands cmd, uint8_t target, int data) {
14+
Wire.beginTransmission(I2C_ADDRESS);
15+
Wire.write((uint8_t)cmd);
16+
Wire.write((uint8_t)target);
17+
Wire.write((uint8_t*)&data, 4);
18+
Wire.endTransmission();
19+
}
20+
21+
int getData(Commands cmd, uint8_t target, uint8_t* buf) {
22+
Wire.beginTransmission(I2C_ADDRESS);
23+
Wire.write((uint8_t)cmd);
24+
Wire.write((uint8_t)target);
25+
Wire.endTransmission();
26+
27+
Wire.requestFrom(I2C_ADDRESS, 5);
28+
mc::irq_status = Wire.read();
29+
30+
int i = 0;
31+
while (Wire.available()) {
32+
buf[i++] = (uint8_t)Wire.read();
33+
}
34+
return i;
35+
}
36+
37+
int getData(Commands cmd, uint8_t* buf) {
38+
return getData(cmd, 0, buf);
39+
}

src/MKRMotorShield.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,9 @@
66
#include "MotorController.h"
77
#include "Common.h"
88
#include "PID.h"
9+
10+
void setDataPIDGains(Commands cmd, uint8_t target, int16_t P, int16_t I, int16_t D);
11+
void setData(Commands cmd, uint8_t target, int data);
12+
int getData(Commands cmd, uint8_t target, uint8_t* buf);
13+
int getData(Commands cmd, uint8_t* buf);
14+

src/MotorController.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace mc {
44

5+
static volatile uint8_t irq_status;
6+
57
class MotorController {
68
public:
79
MotorController() {};

0 commit comments

Comments
 (0)