mirror of
https://github.com/bdring/Grbl_Esp32.git
synced 2025-08-29 09:10:03 +02:00
clang format
This commit is contained in:
@@ -30,16 +30,14 @@ namespace Spindles {
|
||||
_parity = Uart::Parity::None;
|
||||
// TODO: should defaults be set here? What happens if the motor settings in the VFD are wrong or default?
|
||||
// I think they are overloaded with DEFAULT_SPINDLE_RPM_MAX and DEFAULT_SPINDLE_RPM_MIN
|
||||
_max_rpm = 24000;
|
||||
_min_rpm = 6000;
|
||||
_max_rpm = 24000;
|
||||
_min_rpm = 6000;
|
||||
_max_freq = 40000;
|
||||
}
|
||||
|
||||
void L510::direction_command(SpindleState mode, ModbusCommand& data) {
|
||||
// Note: The direction command is always called on M3,M4, and M5
|
||||
// This is where the spindle start/stop should be sent
|
||||
|
||||
|
||||
// This is where the spindle start/stop should be sent
|
||||
|
||||
// NOTE: data length is excluding the CRC16 checksum.
|
||||
data.tx_length = 6;
|
||||
@@ -49,7 +47,7 @@ namespace Spindles {
|
||||
data.msg[2] = 0x25; // Command ID 0x2501
|
||||
data.msg[3] = 0x01;
|
||||
data.msg[4] = 0x00;
|
||||
switch(mode){
|
||||
switch (mode) {
|
||||
case SpindleState::Disable:
|
||||
//data.msg[4] = 0x00;
|
||||
data.msg[5] = 0x00;
|
||||
@@ -64,8 +62,7 @@ namespace Spindles {
|
||||
}
|
||||
|
||||
void L510::set_speed_command(uint32_t rpm, ModbusCommand& data) {
|
||||
|
||||
// NOTE: data length is excluding the CRC16 checksum.
|
||||
// NOTE: data length is excluding the CRC16 checksum.
|
||||
data.tx_length = 6;
|
||||
data.rx_length = 6;
|
||||
|
||||
@@ -78,13 +75,13 @@ namespace Spindles {
|
||||
data.msg[5] = uint8_t(freq & 0xFF);
|
||||
|
||||
#ifdef VFD_DEBUG_MODE2
|
||||
grbl_msg_sendf(CLIENT_SERIAL,MsgLevel::Info,"setting speed to: %d",speed);
|
||||
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "setting speed to: %d", speed);
|
||||
#endif
|
||||
}
|
||||
uint16_t L510::rpm_to_frequency(uint32_t rpm){
|
||||
auto max_rpm = this->_max_rpm;
|
||||
auto max_freq = this->_max_freq;
|
||||
uint16_t freq = (uint32_t(rpm) * max_freq) / uint32_t(max_rpm);
|
||||
uint16_t L510::rpm_to_frequency(uint32_t rpm) {
|
||||
auto max_rpm = this->_max_rpm;
|
||||
auto max_freq = this->_max_freq;
|
||||
uint16_t freq = (uint32_t(rpm) * max_freq) / uint32_t(max_rpm);
|
||||
if (freq < 0) {
|
||||
freq = 0;
|
||||
}
|
||||
@@ -94,11 +91,11 @@ namespace Spindles {
|
||||
return freq;
|
||||
}
|
||||
|
||||
uint32_t L510::freq_to_rpm(uint16_t freq){
|
||||
auto max_rpm = this->_max_rpm;
|
||||
auto max_freq = this->_max_freq;
|
||||
uint32_t rpm = (freq*max_rpm)/max_freq;
|
||||
if(rpm < 0){
|
||||
uint32_t L510::freq_to_rpm(uint16_t freq) {
|
||||
auto max_rpm = this->_max_rpm;
|
||||
auto max_freq = this->_max_freq;
|
||||
uint32_t rpm = (freq * max_rpm) / max_freq;
|
||||
if (rpm < 0) {
|
||||
// sometimes it returns -1 which causes an alarm
|
||||
rpm = 0;
|
||||
}
|
||||
@@ -111,32 +108,30 @@ namespace Spindles {
|
||||
data.tx_length = 6;
|
||||
data.rx_length = 11;
|
||||
|
||||
|
||||
// read parameters 02-03..02-06
|
||||
|
||||
// Send:
|
||||
|
||||
// Send:
|
||||
data.msg[1] = 0x03; // READ
|
||||
data.msg[2] = 0x02; // 0x0203 = Get max rpm
|
||||
data.msg[3] = 0x03;
|
||||
data.msg[4] = 0x00; // Read 4 values
|
||||
data.msg[5] = 0x04;
|
||||
|
||||
|
||||
|
||||
// Recv: ??
|
||||
|
||||
return [](const uint8_t* response, Spindles::VFD* vfd) -> bool {
|
||||
uint32_t rpm = (response[3] << 8) | response[4];
|
||||
uint32_t rpm = (response[3] << 8) | response[4];
|
||||
|
||||
// NOTE: the frequency is stored xxx.x but the input command is frequency * 100;
|
||||
uint16_t freq = (response[9] << 8) | response[10];
|
||||
freq = freq * 10;
|
||||
auto l510 = static_cast<L510*>(vfd);
|
||||
freq = freq * 10;
|
||||
auto l510 = static_cast<L510*>(vfd);
|
||||
|
||||
l510->_max_rpm = rpm;
|
||||
l510->_max_rpm = rpm;
|
||||
l510->_max_freq = freq;
|
||||
|
||||
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "L510 initialized: spindle max_rpm %d max_freq %d", vfd->_max_rpm,l510->_max_freq);
|
||||
grbl_msg_sendf(
|
||||
CLIENT_SERIAL, MsgLevel::Info, "L510 initialized: spindle max_rpm %d max_freq %d", vfd->_max_rpm, l510->_max_freq);
|
||||
|
||||
return true;
|
||||
};
|
||||
@@ -144,13 +139,12 @@ namespace Spindles {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
VFD::response_parser L510::get_status_ok(ModbusCommand& data){
|
||||
VFD::response_parser L510::get_status_ok(ModbusCommand& data) {
|
||||
// NOTE: data length is excluding the CRC16 checksum.
|
||||
data.tx_length = 6;
|
||||
data.rx_length = 5;
|
||||
|
||||
|
||||
// Send:
|
||||
// Send:
|
||||
data.msg[1] = 0x03; // READ
|
||||
data.msg[2] = 0x25; // 0x2520 = Get state
|
||||
data.msg[3] = 0x20;
|
||||
@@ -158,14 +152,14 @@ namespace Spindles {
|
||||
data.msg[5] = 0x01;
|
||||
|
||||
return [](const uint8_t* response, Spindles::VFD* vfd) -> bool {
|
||||
uint32_t vfd_state = (response[3] << 8) | response[4];
|
||||
uint32_t vfd_state = (response[3] << 8) | response[4];
|
||||
|
||||
if(bitRead(vfd_state,3)){
|
||||
grbl_msg_sendf(CLIENT_SERIAL,MsgLevel::Info,"L510 Fault detected");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
if (bitRead(vfd_state, 3)) {
|
||||
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "L510 Fault detected");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
VFD::response_parser L510::get_current_rpm(ModbusCommand& data) {
|
||||
@@ -206,10 +200,10 @@ namespace Spindles {
|
||||
// Receive: 01 03 00 02 00 02
|
||||
// ----- status
|
||||
|
||||
return [](const uint8_t* response, Spindles::VFD* vfd) -> bool {
|
||||
return [](const uint8_t* response, Spindles::VFD* vfd) -> bool {
|
||||
uint16_t got = (uint16_t(response[3]) << 8) | uint16_t(response[4]);
|
||||
bool dir = bitRead(got,1);
|
||||
return true;
|
||||
};
|
||||
bool dir = bitRead(got, 1);
|
||||
return true;
|
||||
};
|
||||
}
|
||||
}
|
@@ -32,11 +32,11 @@ namespace Spindles {
|
||||
response_parser get_current_direction(ModbusCommand& data) override;
|
||||
|
||||
// what is this, what should it do?
|
||||
bool supports_actual_rpm() const override { return true; }
|
||||
bool safety_polling() const override { return true; }
|
||||
bool supports_actual_rpm() const override { return true; }
|
||||
bool safety_polling() const override { return true; }
|
||||
response_parser get_status_ok(ModbusCommand& data) override;
|
||||
uint16_t rpm_to_frequency(uint32_t rpm);
|
||||
uint32_t freq_to_rpm(uint16_t);
|
||||
uint16_t rpm_to_frequency(uint32_t rpm);
|
||||
uint32_t freq_to_rpm(uint16_t);
|
||||
//uint32_t set_rpm(uint32_t rpm) override;
|
||||
void start_spindle();
|
||||
|
||||
|
Reference in New Issue
Block a user