Skip to content

Resolve issue #22 doubled output #23

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
33 changes: 19 additions & 14 deletions Shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ void shell_use_buffered_output(shell_bwriter_t writer)
obd.shell_bwriter = writer;
obd.buffercount = 0;
obd.buffertimer = millis();

// Set shell_writer to 0 so that it's no longer called
shell_writer = 0;
}

bool shell_register(shell_program_t program, const char * string)
Expand Down Expand Up @@ -152,21 +155,23 @@ void shell_unregister_all()

void shell_putc(char c)
{
if (initialized != false && shell_writer != 0)
shell_writer(c);
if (initialized != false && obhandle != 0) {
// Keep track of last byte
obhandle->buffertimer = millis();
// Empty buffer if it´s full before storing anything else
if (obhandle->buffercount >= 30) {
// Write output...
if (obhandle->shell_bwriter != 0)
obhandle->shell_bwriter(obhandle->outbuffer, obhandle->buffercount);
// and clear counter
obhandle->buffercount = 0;
if (initialized != false) {
if (shell_writer != 0) {
shell_writer(c);
} else if (obhandle != 0) {
// Keep track of last byte
obhandle->buffertimer = millis();
// Empty buffer if it´s full before storing anything else
if (obhandle->buffercount >= 30) {
// Write output...
if (obhandle->shell_bwriter != 0)
obhandle->shell_bwriter(obhandle->outbuffer, obhandle->buffercount);
// and clear counter
obhandle->buffercount = 0;
}
// Write to buffer always
obhandle->outbuffer[obhandle->buffercount++] = c;
}
// Write to buffer always
obhandle->outbuffer[obhandle->buffercount++] = c;
}
}

Expand Down