Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Study mods to InputBuffer - not for merge #559

Open
wants to merge 3 commits into
base: Devt
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions Grbl_Esp32/Custom/atari_1020.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,23 +124,23 @@ void atari_home_task(void* pvParameters) {
if (sys.state == STATE_IDLE) {
switch (homing_phase) {
case HOMING_PHASE_FULL_APPROACH: // a full width move to insure it hits left end
WebUI::inputBuffer.push("G90G0Z1\r"); // lift the pen
macroBuffer.push("G90G0Z1\r"); // lift the pen
sprintf(gcode_line, "G91G0X%3.2f\r", -ATARI_PAPER_WIDTH + ATARI_HOME_POS - 3.0); // plus a little extra
WebUI::inputBuffer.push(gcode_line);
macroBuffer.push(gcode_line);
homing_attempt = 1;
homing_phase = HOMING_PHASE_CHECK;
break;
case HOMING_PHASE_CHECK: // check the limits switch
if (digitalRead(REED_SW_PIN) == 0) {
// see if reed switch is grounded
WebUI::inputBuffer.push("G4P0.1\n"); // dramtic pause
macroBuffer.push("G4P0.1\n"); // dramtic pause
sys_position[X_AXIS] = ATARI_HOME_POS * axis_settings[X_AXIS]->steps_per_mm->get();
sys_position[Y_AXIS] = 0.0;
sys_position[Z_AXIS] = 1.0 * axis_settings[Y_AXIS]->steps_per_mm->get();
gc_sync_position();
plan_sync_position();
sprintf(gcode_line, "G90G0X%3.2f\r", ATARI_PAPER_WIDTH); // alway return to right side to reduce home travel stalls
WebUI::inputBuffer.push(gcode_line);
macroBuffer.push(gcode_line);
current_tool = 1; // local copy for reference...until actual M6 change
gc_state.tool = current_tool;
atari_homing = false; // done with homing sequence
Expand All @@ -151,9 +151,9 @@ void atari_home_task(void* pvParameters) {
break;
case HOMING_PHASE_RETRACT:
sprintf(gcode_line, "G0X%3.2f\r", -ATARI_HOME_POS);
WebUI::inputBuffer.push(gcode_line);
macroBuffer.push(gcode_line);
sprintf(gcode_line, "G0X%3.2f\r", ATARI_HOME_POS);
WebUI::inputBuffer.push(gcode_line);
macroBuffer.push(gcode_line);
homing_phase = HOMING_PHASE_CHECK;
break;
default:
Expand All @@ -166,7 +166,7 @@ void atari_home_task(void* pvParameters) {
if (homing_attempt > ATARI_HOMING_ATTEMPTS) {
// try all positions plus 1
grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "Atari homing failed");
WebUI::inputBuffer.push("G90\r");
macroBuffer.push("G90\r");
atari_homing = false;
}
}
Expand Down Expand Up @@ -227,11 +227,11 @@ void user_tool_change(uint8_t new_tool) {
else
move_count = BUMPS_PER_PEN_CHANGE * ((MAX_PEN_NUMBER - current_tool) + new_tool);
sprintf(gcode_line, "G0Z%3.2f\r", ATARI_TOOL_CHANGE_Z); // go to tool change height
WebUI::inputBuffer.push(gcode_line);
macroBuffer.push(gcode_line);
for (uint8_t i = 0; i < move_count; i++) {
sprintf(gcode_line, "G0X%3.2f\r", ATARI_HOME_POS); //
WebUI::inputBuffer.push(gcode_line);
WebUI::inputBuffer.push("G0X0\r");
macroBuffer.push(gcode_line);
macroBuffer.push("G0X0\r");
}
current_tool = new_tool;
grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "Change to Pen#%d", current_tool);
Expand All @@ -250,23 +250,23 @@ void user_defined_macro(uint8_t index) {
#ifdef MACRO_BUTTON_0_PIN
case CONTROL_PIN_INDEX_MACRO_0:
grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "Pen switch");
WebUI::inputBuffer.push("$H\r");
macroBuffer.push("$H\r");
break;
#endif
#ifdef MACRO_BUTTON_1_PIN
case CONTROL_PIN_INDEX_MACRO_1:
grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "Color switch");
atari_next_pen();
sprintf(gcode_line, "G90G0X%3.2f\r", ATARI_PAPER_WIDTH); // alway return to right side to reduce home travel stalls
WebUI::inputBuffer.push(gcode_line);
macroBuffer.push(gcode_line);
break;
#endif
#ifdef MACRO_BUTTON_2_PIN
case CONTROL_PIN_INDEX_MACRO_2:
// feed out some paper and reset the Y 0
grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "Paper switch");
WebUI::inputBuffer.push("G0Y-25\r");
WebUI::inputBuffer.push("G4P0.1\r"); // sync...forces wait for planner to clear
macroBuffer.push("G0Y-25\r");
macroBuffer.push("G4P0.1\r"); // sync...forces wait for planner to clear
sys_position[Y_AXIS] = 0.0; // reset the Y position
gc_sync_position();
plan_sync_position();
Expand All @@ -279,5 +279,5 @@ void user_defined_macro(uint8_t index) {
void user_m30() {
char gcode_line[20];
sprintf(gcode_line, "G90G0X%3.2f\r", ATARI_PAPER_WIDTH); //
WebUI::inputBuffer.push(gcode_line);
macroBuffer.push(gcode_line);
}
8 changes: 4 additions & 4 deletions Grbl_Esp32/Custom/polar_coaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,17 +225,17 @@ void user_defined_macro(uint8_t index) {
switch (index) {
#ifdef MACRO_BUTTON_0_PIN
case CONTROL_PIN_INDEX_MACRO_0:
WebUI::inputBuffer.push("$H\r"); // home machine
macroBuffer.push("$H\r"); // home machine
break;
#endif
#ifdef MACRO_BUTTON_1_PIN
case CONTROL_PIN_INDEX_MACRO_1:
WebUI::inputBuffer.push("[ESP220]/1.nc\r"); // run SD card file 1.nc
macroBuffer.push("[ESP220]/1.nc\r"); // run SD card file 1.nc
break;
#endif
#ifdef MACRO_BUTTON_2_PIN
case CONTROL_PIN_INDEX_MACRO_2:
WebUI::inputBuffer.push("[ESP220]/2.nc\r"); // run SD card file 2.nc
macroBuffer.push("[ESP220]/2.nc\r"); // run SD card file 2.nc
break;
#endif
#ifdef MACRO_BUTTON_3_PIN
Expand All @@ -247,5 +247,5 @@ void user_defined_macro(uint8_t index) {

// handle the M30 command
void user_m30() {
WebUI::inputBuffer.push("$H\r");
macroBuffer.push("$H\r");
}
2 changes: 1 addition & 1 deletion Grbl_Esp32/src/Grbl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void grbl_init() {
#ifdef ENABLE_BLUETOOTH
WebUI::bt_config.begin();
#endif
WebUI::inputBuffer.begin();
macroBuffer.begin();
}

static void reset_variables() {
Expand Down
3 changes: 2 additions & 1 deletion Grbl_Esp32/src/Grbl.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
#include "Motors/Motors.h"
#include "Stepper.h"
#include "Jog.h"
#include "WebUI/InputBuffer.h"
#include "MacroBuffer.h"
#include "InputBuffer.h"
#include "Settings.h"
#include "SettingsDefinitions.h"
#include "WebUI/WebSettings.h"
Expand Down
54 changes: 54 additions & 0 deletions Grbl_Esp32/src/InputBuffer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
InputBuffer.cpp - inputbuffer functions class

Copyright (c) 2014 Luc Lebosse. All rights reserved.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include "InputBuffer.h"

InputBuffer::InputBuffer() {
begin();
}

void InputBuffer::begin() {
_bufferSize = 0;
_bufferpos = 0;
}

void InputBuffer::push(uint8_t c) {
if (_bufferSize == BUFFERSIZE) {
return;
}
int writeIndex = _bufferpos + _bufferSize;
if (writeIndex >= BUFFERSIZE) {
writeIndex -= BUFFERSIZE;
}
_buffer[writeIndex] = c;
_bufferSize++;
}

int InputBuffer::read(void) {
if (!_bufferSize) {
return -1;
}
int data = _buffer[_bufferpos];
if (++_bufferpos == BUFFERSIZE) {
_bufferpos = 0;
}
_bufferSize--;
return data;
}
43 changes: 43 additions & 0 deletions Grbl_Esp32/src/InputBuffer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#pragma once

/*
InputBuffer.h - circular queue for transferring input data from SerialCheckTask
to protocol_main_loop(). There is an instance of this for each client.

Copyright (c) 2014 Luc Lebosse. All rights reserved.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include <stdint.h>
#include <cstring>

class InputBuffer {
public:
InputBuffer();

void begin();
int available() { return _bufferSize; }
int availableForPush() { return BUFFERSIZE - _bufferSize; }
int read(void);
void push(uint8_t c);

private:
static const int BUFFERSIZE = 128;

uint8_t _buffer[BUFFERSIZE];
uint16_t _bufferSize;
uint16_t _bufferpos;
};
61 changes: 61 additions & 0 deletions Grbl_Esp32/src/MacroBuffer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
MacroBuffer.cpp - for injecting macro data as an input stream

Copyright (c) 2014 Luc Lebosse. All rights reserved.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

// #include "Config.h"
#include "MacroBuffer.h"

MacroBuffer macroBuffer;

MacroBuffer::MacroBuffer() {
begin();
}

void MacroBuffer::begin() {
_bufferSize = 0;
_bufferpos = 0;
}

bool MacroBuffer::push(const char* data) {
int data_size = strlen(data);
if ((data_size + _bufferSize) <= BUFFERSIZE) {
int current = _bufferpos + _bufferSize;
for (int i = 0; i < data_size; i++) {
if (current >= BUFFERSIZE) {
current -= BUFFERSIZE;
}
_buffer[current++] = data[i];
}
_bufferSize += strlen(data);
return true;
}
return false;
}

int MacroBuffer::read(void) {
if (!_bufferSize) {
return -1;
}
int v = _buffer[_bufferpos];
if (++_bufferpos > (BUFFERSIZE - 1)) {
_bufferpos = 0;
}
_bufferSize--;
return v;
}
57 changes: 57 additions & 0 deletions Grbl_Esp32/src/MacroBuffer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#pragma once

/*
MacroBuffer.h - for injecting macro data as an input stream

Copyright (c) 2014 Luc Lebosse. All rights reserved.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include <Stream.h>
#include <cstring>

// MacroBuffer inherits from Stream so it can be used as the input source for
// a "Client". Clients support input via read() and output via print().

class MacroBuffer : public Stream {
public:
MacroBuffer();

void begin();

// push() injects macro data into the stream
bool push(const char* data);

// Virtual method of Print class; discards the data
size_t write(uint8_t c) { return 0; }

// Virtual methods of Stream class
int available() { return _bufferSize; }
int peek(void) { return _bufferSize ? _buffer[_bufferpos] : -1; }
int read(void);
void flush(void) {}

operator bool() const { return true; }

private:
static const int BUFFERSIZE = 128;

uint8_t _buffer[BUFFERSIZE];
uint16_t _bufferSize;
uint16_t _bufferpos;
};

extern MacroBuffer macroBuffer;
4 changes: 2 additions & 2 deletions Grbl_Esp32/src/Report.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ void grbl_send(uint8_t client, const char* text) {
#endif
#if defined(ENABLE_WIFI) && defined(ENABLE_HTTP) && defined(ENABLE_SERIAL2SOCKET_OUT)
if (client == CLIENT_WEBUI || client == CLIENT_ALL)
WebUI::Serial2Socket.write((const uint8_t*)text, strlen(text));
WebUI::Serial2Socket.print(text);
#endif
#if defined(ENABLE_WIFI) && defined(ENABLE_TELNET)
if (client == CLIENT_TELNET || client == CLIENT_ALL)
WebUI::telnet_server.write((const uint8_t*)text, strlen(text));
WebUI::telnet_server.print(text);
#endif
if (client == CLIENT_SERIAL || client == CLIENT_ALL) {
Serial.print(text);
Expand Down
Loading