Skip to content

Commit 0f89eab

Browse files
authored
Merge pull request #8 from Mapy542/master
Use F string for RAM use optimization
2 parents 64c4445 + a1f7082 commit 0f89eab

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

src/ODriveCAN.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,13 @@ bool ODriveCAN::getPower(Get_Powers_msg_t& msg, uint16_t timeout_ms) {
137137
void ODriveCAN::onReceive(uint32_t id, uint8_t length, const uint8_t* data) {
138138
#ifdef DEBUG
139139
int byte_index = length - 1;
140-
Serial.println("received:");
141-
Serial.print(" id: 0x");
140+
Serial.println(F("received:"));
141+
Serial.print(F(" id: 0x"));
142142
Serial.println(id, HEX);
143-
Serial.print(" data: 0x");
143+
Serial.print(F(" data: 0x"));
144144
while (byte_index >= 0)
145145
Serial.print(msg.data[byte_index--], HEX);
146-
Serial.println("");
146+
Serial.println(F(""));
147147
#endif // DEBUG
148148
if (node_id_ != (id >> ODriveCAN::kNodeIdShift))
149149
return;
@@ -161,14 +161,14 @@ void ODriveCAN::onReceive(uint32_t id, uint8_t length, const uint8_t* data) {
161161
if (axis_state_callback_ != nullptr)
162162
axis_state_callback_(status, axis_state_user_data_);
163163
else
164-
Serial.println("missing callback");
164+
Serial.println(F("missing callback"));
165165
break;
166166
}
167167
default: {
168168
if (requested_msg_id_ == REQUEST_PENDING)
169169
return;
170170
#ifdef DEBUG
171-
Serial.print("waiting for: 0x");
171+
Serial.print(F("waiting for: 0x"));
172172
Serial.println(requested_msg_id_, HEX);
173173
#endif // DEBUG
174174
if ((id & ODriveCAN::kCmdIdBits) != requested_msg_id_)

src/ODriveUART.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ ODriveUART::ODriveUART(Stream& serial)
1515
: serial_(serial) {}
1616

1717
void ODriveUART::clearErrors() {
18-
serial_ << "sc\n";
18+
serial_ << F("sc\n");
1919
}
2020

2121
void ODriveUART::setPosition(float position) {
@@ -27,23 +27,23 @@ void ODriveUART::setPosition(float position, float velocity_feedforward) {
2727
}
2828

2929
void ODriveUART::setPosition(float position, float velocity_feedforward, float torque_feedforward) {
30-
serial_ << "p " << kMotorNumber << " " << position << " " << velocity_feedforward << " " << torque_feedforward << "\n";
30+
serial_ << F("p ") << kMotorNumber << F(" ") << position << F(" ") << velocity_feedforward << F(" ") << torque_feedforward << F("\n");
3131
}
3232

3333
void ODriveUART::setVelocity(float velocity) {
3434
setVelocity(velocity, 0.0f);
3535
}
3636

3737
void ODriveUART::setVelocity(float velocity, float torque_feedforward) {
38-
serial_ << "v " << kMotorNumber << " " << velocity << " " << torque_feedforward << "\n";
38+
serial_ << F("v ") << kMotorNumber << F(" ") << velocity << F(" ") << torque_feedforward << F("\n");
3939
}
4040

4141
void ODriveUART::setTorque(float torque) {
42-
serial_ << "c " << kMotorNumber << " " << torque << "\n";
42+
serial_ << F("c ") << kMotorNumber << F(" ") << torque << F("\n");
4343
}
4444

4545
void ODriveUART::trapezoidalMove(float position) {
46-
serial_ << "t " << kMotorNumber << " " << position << "\n";
46+
serial_ << F("t ") << kMotorNumber << F(" ") << position << F("\n");
4747
}
4848

4949
ODriveFeedback ODriveUART::getFeedback() {
@@ -52,7 +52,7 @@ ODriveFeedback ODriveUART::getFeedback() {
5252
serial_.read();
5353
}
5454

55-
serial_ << "f " << kMotorNumber << "\n";
55+
serial_ << F("f ") << kMotorNumber << F("\n");
5656

5757
String response = readLine();
5858

@@ -68,20 +68,20 @@ ODriveFeedback ODriveUART::getFeedback() {
6868
}
6969

7070
String ODriveUART::getParameterAsString(const String& path) {
71-
serial_ << "r " << path << "\n";
71+
serial_ << F("r ") << path << F("\n");
7272
return readLine();
7373
}
7474

7575
void ODriveUART::setParameter(const String& path, const String& value) {
76-
serial_ << "w " << path << " " << value << "\n";
76+
serial_ << F("w ") << path << F(" ") << value << F("\n");
7777
}
7878

7979
void ODriveUART::setState(ODriveAxisState requested_state) {
80-
setParameter("axis0.requested_state", String((long)requested_state));
80+
setParameter(F("axis0.requested_state"), String((long)requested_state));
8181
}
8282

8383
ODriveAxisState ODriveUART::getState() {
84-
return (ODriveAxisState)getParameterAsInt("axis0.current_state");
84+
return (ODriveAxisState)getParameterAsInt(F("axis0.current_state"));
8585
}
8686

8787
String ODriveUART::readLine(unsigned long timeout_ms) {

0 commit comments

Comments
 (0)