Skip to content

Commit

Permalink
Merge pull request #23 from DCC-EX:devel
Browse files Browse the repository at this point in the history
Add missing comments and doco
  • Loading branch information
peteGSX authored Jan 6, 2025
2 parents 605e428 + f0554d6 commit e5a31dc
Show file tree
Hide file tree
Showing 138 changed files with 12,911 additions and 1,653 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Docs

on:
push:
branches: [ main ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/[email protected]
- name: Requirements
run: |
sudo apt-get install doxygen graphviz
- name: Build docs
run: |
cd docs
# touch _build/html/.nojekyll
doxygen Doxyfile.in
- name: Deploy
uses: JamesIves/github-pages-deploy-action@ba1486788b0490a235422264426c45848eac35c6
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: gh-pages # The branch the action should deploy to.
folder: docs/_build/html # The folder the action should deploy.
21 changes: 21 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Tests

on:
push:
branches: [main, devel]
pull_request:
branches: [main, devel]

jobs:
run-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- name: Install Python Wheel
run: pip install wheel
- name: Install PlatformIO Core
run: pip install -U platformio
- name: Install valgrind
run: sudo apt install -y valgrind
- name: Run GoogleTest
run: python -m platformio test -v -e native_test -a "--gtest_shuffle" -a "--gtest_repeat=5"
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,10 @@
.vscode
.DS_Store
config.h
myConfig.h
myDevices.h
build
_build
venv
docs/ex-display/
platformio.ini.test
205 changes: 0 additions & 205 deletions Arial9pt7b.h

This file was deleted.

62 changes: 45 additions & 17 deletions AtFinder.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
/*
* © 2024 Chris Harlow
* © 2024 Peter Cole
*
* This is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* It 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this code. If not, see <https://www.gnu.org/licenses/>.
*/

#include "AtFinder.h"
#include <Arduino.h>


/* This is a finite state automation (FSA) to recognize a dccex output message
in the format <@ screenid screenrow "text">.
Expand All @@ -14,25 +31,26 @@ At any given time, the state is one of the enum values.
Within each state, the parsed character is either used as appropriate or ignored
and the state may or may not change to a different state. */

DISPLAY_CALLBACK AtFinder::callback = nullptr;
uint8_t AtFinder::maxTextLength = 0;
char *AtFinder::text = nullptr;
uint8_t AtFinder::_maxTextLength = 0;
char *AtFinder::_text = nullptr;
CallbackInterface *AtFinder::_callback = nullptr;
Logger *AtFinder::_logger = nullptr;

// Set maximum accepted length of "text". Longer texts will be trimmed.
// Set callback function that will be called when message detected.

// Note: the code is safe if setup is not called before use because the
// code can not reach the text handling or callback states.
// code can not reach the text handling or callback states.
// If the sketch has no reference to the setup function at all,
// then compiler constant propagation is smart enough to realise
// that it can never reach the text handling states, and thus
// the entire function has no effect and is eliminated from the link.


void AtFinder::setup(uint8_t _maxTextLength, DISPLAY_CALLBACK _callback) {
maxTextLength = _maxTextLength;
text = (char *)malloc(maxTextLength + 1);
callback = _callback;
void AtFinder::setup(uint8_t maxTextLength, CallbackInterface *callback) {
_maxTextLength = maxTextLength;
_text = (char *)malloc(_maxTextLength + 1);
_callback = callback;
LOG(LogLevel::LOG_DEBUG, "AtFinder::setup with _maxTextLength %d", _maxTextLength);
}

void AtFinder::processInputChar(char hot) {
Expand All @@ -57,7 +75,7 @@ void AtFinder::processInputChar(char hot) {
state = SET_OPCODE;
return;
case SET_OPCODE: // waiting for opcode
state = (hot == '@' && callback) ? SKIP_SPACES1 : FIND_START;
state = (hot == '@' && _callback) ? SKIP_SPACES1 : FIND_START;
return;
case SKIP_SPACES1: // skip spaces to screen id
if (hot == ' ')
Expand All @@ -82,7 +100,7 @@ void AtFinder::processInputChar(char hot) {
screenRow = 0;
state = BUILD_ROW;
[[fallthrough]]; // character will be reinterpreted
case BUILD_ROW: // building screen row
case BUILD_ROW: // building screen row
if (hot == ' ') {
state = SKIP_SPACES3;
return;
Expand All @@ -105,14 +123,24 @@ void AtFinder::processInputChar(char hot) {
case COPY_TEXT: // copying text to buffer
if (hot == '"') {
// end of text found
text[textLength] = 0;
if (callback)
callback(screenId, screenRow, text); // ET PHONE HOME!
_text[textLength] = 0;
if (_callback) {
_callback->updateScreen(screenId, screenRow, _text);
}
state = FIND_START;
return;
}
if (textLength < maxTextLength)
text[textLength++] = hot;
if (textLength < _maxTextLength)
_text[textLength++] = hot;
return;
}
}

void AtFinder::cleanUp() {
free(AtFinder::_text);
AtFinder::_text = nullptr;
AtFinder::_callback = nullptr;
AtFinder::_logger = nullptr;
}

void AtFinder::setLogger(Logger *logger) { _logger = logger; }
Loading

0 comments on commit e5a31dc

Please sign in to comment.