mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-23 18:56:38 +00:00
Change strtod() into CharToFloat() saving 8k code
Change strtod() into CharToFloat() saving 8k code
This commit is contained in:
parent
af733afbe5
commit
0b3c237627
@ -69,49 +69,56 @@ void (* const A4988Command[])(void) PROGMEM = {
|
|||||||
&CmndDoMove,&CmndDoRotate,&CmndDoTurn,&CmndSetMIS,&CmndSetSPR,&CmndSetRPM};
|
&CmndDoMove,&CmndDoRotate,&CmndDoTurn,&CmndSetMIS,&CmndSetSPR,&CmndSetRPM};
|
||||||
|
|
||||||
void CmndDoMove(void) {
|
void CmndDoMove(void) {
|
||||||
|
// Move the motor the given number of steps (positive values: clockwise, negative values: counterclockwise)
|
||||||
if (XdrvMailbox.data_len > 0) {
|
if (XdrvMailbox.data_len > 0) {
|
||||||
long stepsPlease = strtoul(XdrvMailbox.data,nullptr,10);
|
long stepsPlease = strtol(XdrvMailbox.data, nullptr, 10);
|
||||||
myA4988->doMove(stepsPlease);
|
myA4988->doMove(stepsPlease);
|
||||||
ResponseCmndDone();
|
ResponseCmndDone();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CmndDoRotate(void) {
|
void CmndDoRotate(void) {
|
||||||
|
// Rotate the motor the given number of degrees (positive values: clockwise, negative values: counterclockwise)
|
||||||
if (XdrvMailbox.data_len > 0) {
|
if (XdrvMailbox.data_len > 0) {
|
||||||
long degrsPlease = strtoul(XdrvMailbox.data,nullptr,10);
|
long degrsPlease = strtol(XdrvMailbox.data, nullptr, 10);
|
||||||
myA4988->doRotate(degrsPlease);
|
myA4988->doRotate(degrsPlease);
|
||||||
ResponseCmndDone();
|
ResponseCmndDone();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CmndDoTurn(void) {
|
void CmndDoTurn(void) {
|
||||||
|
// Spin the motor the given number of turns (positive values: clockwise, negative values: counterclockwise)
|
||||||
if (XdrvMailbox.data_len > 0) {
|
if (XdrvMailbox.data_len > 0) {
|
||||||
float turnsPlease = strtod(XdrvMailbox.data,nullptr);
|
// float turnsPlease = strtod(XdrvMailbox.data,nullptr);
|
||||||
|
float turnsPlease = CharToFloat(XdrvMailbox.data); // Save 8k code size over strtod()
|
||||||
myA4988->doTurn(turnsPlease);
|
myA4988->doTurn(turnsPlease);
|
||||||
ResponseCmndDone();
|
ResponseCmndDone();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CmndSetMIS(void) {
|
void CmndSetMIS(void) {
|
||||||
if (PinUsed(GPIO_A4988_MS1) && PinUsed(GPIO_A4988_MS1, 1) && PinUsed(GPIO_A4988_MS1, 2) && (XdrvMailbox.data_len > 0)) {
|
// 1,2,4,8,16 Set micro stepping increment - 1/1 (full steps) to 1/16 (default = 1)
|
||||||
short newMIS = strtoul(XdrvMailbox.data,nullptr,10);
|
if (PinUsed(GPIO_A4988_MS1) && PinUsed(GPIO_A4988_MS1, 1) && PinUsed(GPIO_A4988_MS1, 2) && (XdrvMailbox.payload > 0)) {
|
||||||
myA4988->setMIS(newMIS);
|
// short newMIS = strtoul(XdrvMailbox.data,nullptr,10);
|
||||||
|
myA4988->setMIS(XdrvMailbox.payload);
|
||||||
ResponseCmndDone();
|
ResponseCmndDone();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CmndSetSPR(void) {
|
void CmndSetSPR(void) {
|
||||||
if (XdrvMailbox.data_len > 0) {
|
// Set the number of steps the given motor needs for one revolution (default = 200)
|
||||||
int newSPR = strtoul(XdrvMailbox.data,nullptr,10);
|
if (XdrvMailbox.payload > 0) {
|
||||||
myA4988->setSPR(newSPR);
|
// int newSPR = strtoul(XdrvMailbox.data,nullptr,10);
|
||||||
|
myA4988->setSPR(XdrvMailbox.payload);
|
||||||
ResponseCmndDone();
|
ResponseCmndDone();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CmndSetRPM(void) {
|
void CmndSetRPM(void) {
|
||||||
if (XdrvMailbox.data_len > 0) {
|
// Set revolutions per minute (default = 30)
|
||||||
short newRPM = strtoul(XdrvMailbox.data,nullptr,10);
|
if (XdrvMailbox.payload > 0) {
|
||||||
myA4988->setRPM(newRPM);
|
// short newRPM = strtoul(XdrvMailbox.data,nullptr,10);
|
||||||
|
myA4988->setRPM(XdrvMailbox.payload);
|
||||||
ResponseCmndDone();
|
ResponseCmndDone();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user