Skip to content

Commit

Permalink
Support ESP32 v2.x platform - tone and noTone added in 2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
ridencww committed Sep 5, 2022
1 parent a9546d8 commit 4ce6153
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 4 additions & 3 deletions cww_MorseTx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "cww_MorseTx.h"

/*
version 1.2.1: Ignore all non-Morse characters
version 1.2.1: Ignore all non-Morse characters, support ESP32 v2.x+ that has tone/noTone
version 1.2.0: Change speed to float type to support speeds less than 1 word per minute
version 1.1.1: Isolate variables to support multiple instances. Fix divide by zero error when speed = 0
version 1.1.0: ESP32 support. Fixed compiler warning about a constant to char* conversion.
Expand Down Expand Up @@ -171,8 +171,9 @@ void cww_MorseTx::send(const char* str) {
}
}

// Only define tone/noTone for ESP32 platform 1.x (ESP_ARDUINO_VERSION_MAJOR added in 2.x)
#ifdef ESP32

#ifndef ESP_ARDUINO_VERSION_MAJOR
void tone(uint8_t pin, unsigned int frequency) {
if (ledcRead(TONE_CHANNEL)) {
// log_e("Tone channel %d is already in use", ledcRead(TONE_CHANNEL));
Expand All @@ -186,5 +187,5 @@ void noTone(uint8_t pin) {
ledcDetachPin(pin);
ledcWrite(TONE_CHANNEL, 0);
}

#endif
#endif
6 changes: 3 additions & 3 deletions cww_MorseTx.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
#define cww_MorseTx_h

#ifdef ESP32

#ifndef TONE_CHANNEL
#define TONE_CHANNEL 0
#endif

// Only define tone/noTone for ESP32 platform 1.x (ESP_ARDUINO_VERSION_MAJOR added in 2.x)
#ifndef ESP_ARDUINO_VERSION_MAJOR
void tone(uint8_t pin, unsigned int frequency);
void noTone(uint8_t pin);

#endif
#endif

class cww_MorseTx {
Expand Down

0 comments on commit 4ce6153

Please sign in to comment.