Skip to content

Commit

Permalink
Merge pull request #106 from bdring/Devt
Browse files Browse the repository at this point in the history
Devt
  • Loading branch information
bdring authored Nov 10, 2021
2 parents 682a5b1 + 439234a commit 99bdb11
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion FluidNC/src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void setup() {
#endif
#ifdef ENABLE_BLUETOOTH
WebUI::bt_config.begin();
allChannels.registration(&WebUI::SerialBT);
allChannels.registration(&WebUI::btChannel);
#endif
WebUI::inputBuffer.begin();
} catch (const AssertionFailed& ex) {
Expand Down
10 changes: 10 additions & 0 deletions FluidNC/src/WebUI/BTConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
namespace WebUI {
BTConfig bt_config;
BluetoothSerial SerialBT;
BTChannel btChannel;
}
// The instance variable for the BTConfig class is in config->_comms

Expand All @@ -24,6 +25,15 @@ const uint8_t* esp_bt_dev_get_address(void);
}

namespace WebUI {
size_t BTChannel::write(uint8_t data) {
static uint8_t lastchar = '\0';
if (_addCR && data == '\n' && lastchar != '\r') {
SerialBT.write('\r');
}
lastchar = data;
return SerialBT.write(data);
}

BTConfig* BTConfig::instance = nullptr;

BTConfig::BTConfig() {}
Expand Down
15 changes: 15 additions & 0 deletions FluidNC/src/WebUI/BTConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@ const char* const DEFAULT_BT_NAME = "FluidNC";
namespace WebUI {
extern BluetoothSerial SerialBT;

class BTChannel : public Channel {
private:
public:
// BTChannel(bool addCR = false) : _linelen(0), _addCR(addCR) {}
BTChannel() : Channel("bluetooth", true) {}
virtual ~BTChannel() = default;

int available() override { return SerialBT.available(); }
int read() override { return SerialBT.read(); }
int peek() override { return SerialBT.peek(); }
void flush() override { return SerialBT.flush(); }
size_t write(uint8_t data) override;
};
extern BTChannel btChannel;

class BTConfig {
private:
static BTConfig* instance; // BT Callback does not support passing parameters. Sigh.
Expand Down

0 comments on commit 99bdb11

Please sign in to comment.