Skip to content

Commit

Permalink
IDF 5.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilia O. authored and Ilia O. committed Dec 4, 2024
1 parent ebf0b1c commit b00c3df
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 13 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ LidarSerial.begin(baud_rate, SERIAL_8N1, 4, 5); // GPIO4 as RX1, GPIO5 as TX1
## Release notes

## v0.5.9
- support for Espressif SDK 5.x (ESP32 Arduino 3.x)
- added ESP32-C3 LD14P example
- added ESP32-S3 LD14P example

Expand Down
8 changes: 4 additions & 4 deletions examples/lds_basic_esp32/lds_basic_esp32.ino
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,18 @@ void lidar_motor_pin_callback(float value, LDS::lds_pin_t lidar_pin) {
int pin = (lidar_pin == LDS::LDS_MOTOR_EN_PIN) ?
LDS_MOTOR_EN_PIN : LDS_MOTOR_PWM_PIN;

if (value <= LDS::DIR_INPUT) {
if (value <= (float)LDS::DIR_INPUT) {
// Configure pin direction
if (value == LDS::DIR_OUTPUT_PWM) {
if (value == (float)LDS::DIR_OUTPUT_PWM) {
ledcSetup(LDS_MOTOR_PWM_CHANNEL, LDS_MOTOR_PWM_FREQ, LDS_MOTOR_PWM_BITS);
ledcAttachPin(pin, LDS_MOTOR_PWM_CHANNEL);
} else
pinMode(pin, (value == LDS::DIR_INPUT) ? INPUT : OUTPUT);
pinMode(pin, (value == (float)LDS::DIR_INPUT) ? INPUT : OUTPUT);
return;
}

if (value < LDS::VALUE_PWM) // set constant output
digitalWrite(pin, (value == LDS::VALUE_HIGH) ? HIGH : LOW);
digitalWrite(pin, (value == (float)LDS::VALUE_HIGH) ? HIGH : LOW);
else { // set PWM duty cycle
int pwm_value = ((1<<LDS_MOTOR_PWM_BITS)-1)*value;
ledcWrite(LDS_MOTOR_PWM_CHANNEL, pwm_value);
Expand Down
12 changes: 8 additions & 4 deletions examples/ydlidar_x2_esp32/ydlidar_x2_esp32.ino
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,22 @@ void lidar_motor_pin_callback(float value, LDS::lds_pin_t lidar_pin) {
int pin = (lidar_pin == LDS::LDS_MOTOR_EN_PIN) ?
LDS_MOTOR_EN_PIN : LDS_MOTOR_PWM_PIN;

if (value <= LDS::DIR_INPUT) {
if (value <= (float)LDS::DIR_INPUT) {
// Configure pin direction
if (value == LDS::DIR_OUTPUT_PWM) {
if (value == (float)LDS::DIR_OUTPUT_PWM) {
#if ESP_IDF_VERSION_MAJOR >= 5
ledcAttachChannel(pin, LDS_MOTOR_PWM_FREQ, LDS_MOTOR_PWM_BITS, LDS_MOTOR_PWM_CHANNEL);
#else
ledcSetup(LDS_MOTOR_PWM_CHANNEL, LDS_MOTOR_PWM_FREQ, LDS_MOTOR_PWM_BITS);
ledcAttachPin(pin, LDS_MOTOR_PWM_CHANNEL);
#endif
} else
pinMode(pin, (value == LDS::DIR_INPUT) ? INPUT : OUTPUT);
pinMode(pin, (value == (float)LDS::DIR_INPUT) ? INPUT : OUTPUT);
return;
}

if (value < LDS::VALUE_PWM) // set constant output
digitalWrite(pin, (value == LDS::VALUE_HIGH) ? HIGH : LOW);
digitalWrite(pin, (value == (float)LDS::VALUE_HIGH) ? HIGH : LOW);
else { // set PWM duty cycle
int pwm_value = ((1<<LDS_MOTOR_PWM_BITS)-1)*value;
ledcWrite(LDS_MOTOR_PWM_CHANNEL, pwm_value);
Expand Down
14 changes: 9 additions & 5 deletions examples/ydlidar_x4_esp32/ydlidar_x4_esp32.ino
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,22 @@ void lidar_motor_pin_callback(float value, LDS::lds_pin_t lidar_pin) {
int pin = (lidar_pin == LDS::LDS_MOTOR_EN_PIN) ?
LDS_MOTOR_EN_PIN : LDS_MOTOR_PWM_PIN;

if (value <= LDS::DIR_INPUT) {
if (value <= (float)LDS::DIR_INPUT) {
// Configure pin direction
if (value == LDS::DIR_OUTPUT_PWM) {
if (value == (float)LDS::DIR_OUTPUT_PWM) {
#if ESP_IDF_VERSION_MAJOR >= 5
ledcAttachChannel(pin, LDS_MOTOR_PWM_FREQ, LDS_MOTOR_PWM_BITS, LDS_MOTOR_PWM_CHANNEL);
#else
ledcSetup(LDS_MOTOR_PWM_CHANNEL, LDS_MOTOR_PWM_FREQ, LDS_MOTOR_PWM_BITS);
ledcAttachPin(pin, LDS_MOTOR_PWM_CHANNEL);
#endif
} else
pinMode(pin, (value == LDS::DIR_INPUT) ? INPUT : OUTPUT);
pinMode(pin, (value == (float)LDS::DIR_INPUT) ? INPUT : OUTPUT);
return;
}

if (value < LDS::VALUE_PWM) // set constant output
digitalWrite(pin, (value == LDS::VALUE_HIGH) ? HIGH : LOW);
if (value < (float)LDS::VALUE_PWM) // set constant output
digitalWrite(pin, (value == (float)LDS::VALUE_HIGH) ? HIGH : LOW);
else { // set PWM duty cycle
int pwm_value = ((1<<LDS_MOTOR_PWM_BITS)-1)*value;
ledcWrite(LDS_MOTOR_PWM_CHANNEL, pwm_value);
Expand Down
11 changes: 11 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

LDS KEYWORD1
LDS_YDLIDAR_X4 KEYWORD1
LDS_YDLIDAR_X4_PRO KEYWORD1
LDS_YDLIDAR_X3 KEYWORD1
LDS_YDLIDAR_X3_PRO KEYWORD1
LDS_YDLIDAR_X2_X2L KEYWORD1
Expand Down Expand Up @@ -40,6 +41,16 @@ setInfoCallback KEYWORD2
setErrorCallback KEYWORD2
init KEYWORD2
getModelName KEYWORD2
setScanTargetFreqHz KEYWORD2
getTargetScanFreqHz KEYWORD2
getCurrentScanFreqHz KEYWORD2
getSamplingRateHz KEYWORD2
setScanPIDCoeffs KEYWORD2
setScanPIDSamplePeriodMs KEYWORD2
resultCodeToString KEYWORD2
infoCodeToString KEYWORD2
pinIDToString KEYWORD2
pinStateToString KEYWORD2

#######################################
# Constants (LITERAL1)
Expand Down

0 comments on commit b00c3df

Please sign in to comment.