Skip to content

Commit 42bd006

Browse files
committedMar 8, 2017
Added some functionality of ControlBoard and usage of board macros for compilation
1 parent 95300d4 commit 42bd006

File tree

4 files changed

+239
-0
lines changed

4 files changed

+239
-0
lines changed
 

‎avr/libraries/LottieLemon/src/LottieLemon.h

+5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@
1919
#ifndef LOTTIE_LEMON_H
2020
#define LOTTIE_LEMON_H
2121

22+
#ifdef ARDUINO_AVR_ROBOT_MOTOR
2223
#include "utility/LottieLemonMotorBoard.h"
24+
#endif
25+
#ifdef ARDUINO_AVR_ROBOT_CONTROL
26+
#include "utility/LottieLemonControlBoard.h"
27+
#endif
2328

2429
namespace LottieLemon {
2530

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
/*
2+
Copyright (c) 2012 Arduino LLC. All right reserved.
3+
4+
This library is free software; you can redistribute it and/or
5+
modify it under the terms of the GNU Lesser General Public
6+
License as published by the Free Software Foundation; either
7+
version 2.1 of the License, or (at your option) any later version.
8+
9+
This library is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
Lesser General Public License for more details.
13+
14+
You should have received a copy of the GNU Lesser General Public
15+
License along with this library; if not, write to the Free Software
16+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
*/
18+
19+
#include <Arduino.h>
20+
#include <TwoWayIntegerEasyTransfer.h>
21+
#include "../LottieLemon.h"
22+
23+
#ifdef ARDUINO_AVR_ROBOT_CONTROL
24+
25+
using namespace LottieLemon;
26+
27+
static void _requestData(uint8_t command) {
28+
TwoWayIntegerEasyTransfer.writeByte(command);
29+
TwoWayIntegerEasyTransfer.sendData();
30+
if (TwoWayIntegerEasyTransfer.hasReceivedData()) {
31+
TwoWayIntegerEasyTransfer.processInput();
32+
}
33+
}
34+
35+
ControlBoard::ControlBoard()
36+
: _multiplexer{ NOT_A_PIN, MUXA, MUXB, MUXC, MUXD } {
37+
}
38+
39+
void ControlBoard::setMode(uint8_t mode) {
40+
TwoWayIntegerEasyTransfer.writeByte(COMMAND_SWITCH_MODE);
41+
TwoWayIntegerEasyTransfer.writeByte(mode);
42+
TwoWayIntegerEasyTransfer.sendData();
43+
}
44+
45+
void ControlBoard::pauseMode(bool isPaused) {
46+
TwoWayIntegerEasyTransfer.writeByte(COMMAND_PAUSE_MODE);
47+
TwoWayIntegerEasyTransfer.writeByte(isPaused);
48+
TwoWayIntegerEasyTransfer.sendData();
49+
}
50+
51+
bool ControlBoard::isActionDone(void) {
52+
static bool actionValue;
53+
TwoWayIntegerEasyTransfer.attach(
54+
[](uint8_t command, IntegerEasyTransfer &) {
55+
if (command == COMMAND_ACTION_DONE) {
56+
actionValue = true;
57+
}
58+
else {
59+
actionValue = false;
60+
}
61+
});
62+
if (TwoWayIntegerEasyTransfer.hasReceivedData()) {
63+
TwoWayIntegerEasyTransfer.processInput();
64+
}
65+
return actionValue;
66+
}
67+
68+
void ControlBoard::lineFollowConfig(
69+
uint8_t kP, uint8_t kD,
70+
uint8_t robotSpeedPercentage, uint8_t intergrationTimeMillis) {
71+
TwoWayIntegerEasyTransfer.writeByte(COMMAND_LINE_FOLLOW_CONFIG);
72+
TwoWayIntegerEasyTransfer.writeByte(kP);
73+
TwoWayIntegerEasyTransfer.writeByte(kD);
74+
TwoWayIntegerEasyTransfer.writeByte(robotSpeedPercentage);
75+
TwoWayIntegerEasyTransfer.writeByte(intergrationTimeMillis);
76+
TwoWayIntegerEasyTransfer.sendData();
77+
}
78+
79+
void ControlBoard::motorsWrite(int speedLeft, int speedRight) {
80+
TwoWayIntegerEasyTransfer.writeByte(COMMAND_RUN);
81+
TwoWayIntegerEasyTransfer.writeInt(speedLeft);
82+
TwoWayIntegerEasyTransfer.writeInt(speedRight);
83+
TwoWayIntegerEasyTransfer.sendData();
84+
}
85+
86+
void ControlBoard::motorsStop(void) {
87+
TwoWayIntegerEasyTransfer.writeByte(COMMAND_MOTORS_STOP);
88+
TwoWayIntegerEasyTransfer.sendData();
89+
}
90+
91+
bool ControlBoard::digitalRead(uint8_t port) {
92+
return false;
93+
}
94+
95+
void ControlBoard::digitalWrite(uint8_t port, bool value) {
96+
/*
97+
//bottom TKs, just for communication purpose
98+
enum {
99+
B_TK1 = 201,
100+
B_TK2 = 202,
101+
B_TK3 = 203,
102+
B_TK4 = 204
103+
};
104+
#define D10 B_TK1
105+
#define D9 B_TK2
106+
#define D8 B_TK4
107+
#define D7 B_TK3
108+
*/
109+
/*
110+
Type Code Label
111+
D12 [TKD5] (D5) MUXC Not safe to use!
112+
D6 [TKD4] (D4) MUXA Not safe to use!
113+
A4 [TKD3] (D3)
114+
A3 [TKD2] (D2)
115+
A2 [TKD1] (D1)
116+
A1 [TKD0] (D0)
117+
D17 [LED1] (LED)
118+
Type Code Label
119+
A11 [B_TK4] (D8)
120+
A6 [B_TK3] (D7)
121+
A1 [B_TK2] (D9)
122+
A0 [B_TK1] (D10)
123+
X0..X7 @ mux
124+
*/
125+
}
126+
127+
int ControlBoard::analogRead(uint8_t port) {
128+
return 0;
129+
}
130+
131+
void ControlBoard::analogWrite(uint8_t port, uint8_t value) {
132+
}
133+
134+
uint8_t ControlBoard::updateIR(uint16_t * ir, uint8_t size) {
135+
static const uint8_t MAX_IR_DATA = 5;
136+
static uint16_t irValues[MAX_IR_DATA];
137+
static uint8_t maxItems;
138+
maxItems = min(MAX_IR_DATA, size);
139+
TwoWayIntegerEasyTransfer.attach(
140+
[](uint8_t command, IntegerEasyTransfer & request) {
141+
for (uint16_t i = 0; i < MAX_IR_DATA; i++) {
142+
if (command == COMMAND_READ_IR_RE) {
143+
irValues[i] = request.readInt();
144+
}
145+
else {
146+
irValues[i] = 0;
147+
}
148+
}
149+
});
150+
_requestData(COMMAND_READ_IR);
151+
memcpy(ir, irValues, maxItems * sizeof(uint16_t));
152+
return maxItems;
153+
}
154+
155+
int LottieLemon::ControlBoard::trimRead() {
156+
static int trimmerValue;
157+
TwoWayIntegerEasyTransfer.attach(
158+
[](uint8_t command, IntegerEasyTransfer & request) {
159+
if (command == COMMAND_READ_TRIM_RE) {
160+
trimmerValue = request.readInt();
161+
}
162+
else {
163+
trimmerValue = 0;
164+
}
165+
});
166+
_requestData(COMMAND_READ_TRIM);
167+
return trimmerValue;
168+
}
169+
170+
int ControlBoard::knobRead() {
171+
return /*Arduino*/::analogRead(POT);
172+
}
173+
174+
#endif // ARDUINO_AVR_ROBOT_CONTROL
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
Copyright (c) 2012 Arduino LLC. All right reserved.
3+
4+
This library is free software; you can redistribute it and/or
5+
modify it under the terms of the GNU Lesser General Public
6+
License as published by the Free Software Foundation; either
7+
version 2.1 of the License, or (at your option) any later version.
8+
9+
This library is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
Lesser General Public License for more details.
13+
14+
You should have received a copy of the GNU Lesser General Public
15+
License along with this library; if not, write to the Free Software
16+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
*/
18+
19+
#ifndef LOTTIE_LEMON_CONTROL_BOARD_H
20+
#define LOTTIE_LEMON_CONTROL_BOARD_H
21+
22+
#include <stdint.h>
23+
#include <AnalogMultiplexer.h>
24+
25+
namespace LottieLemon {
26+
27+
class ControlBoard {
28+
29+
AMxx4067 _multiplexer;
30+
31+
public:
32+
ControlBoard();
33+
void setMode(uint8_t mode);
34+
void pauseMode(bool isPaused);
35+
bool isActionDone(void);
36+
void lineFollowConfig(
37+
uint8_t kP, uint8_t kD,
38+
uint8_t robotSpeedPercentage, uint8_t intergrationTimeMillis
39+
);
40+
41+
void motorsWrite(int speedLeft, int speedRight);
42+
void motorsStop(void);
43+
44+
bool digitalRead(uint8_t port /*TK0..TK7, TKD0..TKD5, B_TK1..B_TK4*/);
45+
void digitalWrite(uint8_t port /*TKD0..TKD5, B_TK1..B_TK4*/, bool value);
46+
int analogRead(uint8_t port /*TK0..TK7, TKD0..TKD5, B_TK1..B_TK4*/);
47+
void analogWrite(uint8_t port /*TKD4*/, uint8_t value);
48+
49+
uint8_t updateIR(uint16_t * /*[out]*/ ir, uint8_t size);
50+
int trimRead(void);
51+
52+
int knobRead(void);
53+
};
54+
}
55+
56+
#endif // LOTTIE_LEMON_CONTROL_BOARD_H

‎avr/libraries/LottieLemon/src/utility/LottieLemonMotorBoard.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include <TwoWayIntegerEasyTransfer.h>
2121
#include "../LottieLemon.h"
2222

23+
#ifdef ARDUINO_AVR_ROBOT_MOTOR
24+
2325
using namespace LottieLemon;
2426

2527
static MotorBoard * _motorBoard = nullptr;
@@ -328,3 +330,5 @@ float MotorBoard::getBatteryDischargeMilliamps() {
328330
float adcVoltage = (5.0f / 1023.0f) * adcValue;
329331
return adcVoltage / 0.00075f; // Compensate sense resistor and gain.
330332
}
333+
334+
#endif // ARDUINO_AVR_ROBOT_MOTOR

0 commit comments

Comments
 (0)