From 739144d57e8f53c0b3f668f2183ce0026a43c964 Mon Sep 17 00:00:00 2001 From: Andrew Gillham Date: Tue, 3 Oct 2023 23:48:07 -0500 Subject: [PATCH] =?UTF-8?q?Fix=20off=20by=20one=20on=20the=20capture=20buf?= =?UTF-8?q?fer=20due=20to=20earlier=20debugging.=20I=20finally=20realized?= =?UTF-8?q?=20I=20was=20checking=20if=20an=20unsigned=20int=20was=20less?= =?UTF-8?q?=20than=20zero.=20=20=20Thanks=20Szil=C3=A1rd=20for=20the=20cor?= =?UTF-8?q?rect=20indexes=20in=20the=20issue=20comments.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../logic_analyzer_inline_2mhz.ino | 6 +++--- .../logic_analyzer_inline_4mhz.ino | 6 +++--- logic_analyzer_sigrok/logic_analyzer_sigrok.ino | 16 ++++++++-------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/logic_analyzer_sigrok/logic_analyzer_inline_2mhz.ino b/logic_analyzer_sigrok/logic_analyzer_inline_2mhz.ino index d92b708..423037b 100644 --- a/logic_analyzer_sigrok/logic_analyzer_inline_2mhz.ino +++ b/logic_analyzer_sigrok/logic_analyzer_inline_2mhz.ino @@ -2,7 +2,7 @@ * * SUMP Protocol Implementation for Arduino boards. * - * Copyright (c) 2011,2012,2013,2014,2015,2016,2017,2018,2019,2020,2021 Andrew Gillham + * Copyright (c) 2011,2012,2013,2014,2015,2016,2017,2018,2019,2020,2021,2022,2023 Andrew Gillham * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -45,7 +45,7 @@ */ void captureInline2mhz() { - unsigned int i; + signed int i; /* * basic trigger, wait until all trigger conditions are met on port. @@ -14441,7 +14441,7 @@ void captureInline2mhz() { * dump the samples back to the SUMP client. nothing special * is done for any triggers, this is effectively the 0/100 buffer split. */ - for (i = readCount ; i > 0; i--) { + for (i = readCount-1 ; i >= 0; i--) { #ifdef USE_PORTD Serial.write(logicdata[i] >> 2); #else diff --git a/logic_analyzer_sigrok/logic_analyzer_inline_4mhz.ino b/logic_analyzer_sigrok/logic_analyzer_inline_4mhz.ino index 09d7eb5..3280f6f 100644 --- a/logic_analyzer_sigrok/logic_analyzer_inline_4mhz.ino +++ b/logic_analyzer_sigrok/logic_analyzer_inline_4mhz.ino @@ -2,7 +2,7 @@ * * SUMP Protocol Implementation for Arduino boards. * - * Copyright (c) 2011,2012,2013,2014,2015,2016,2017,2018,2019,2020,2021 Andrew Gillham + * Copyright (c) 2011,2012,2013,2014,2015,2016,2017,2018,2019,2020,2021,2022,2023 Andrew Gillham * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -45,7 +45,7 @@ */ void captureInline4mhz() { - unsigned int i; + signed int i; /* * basic trigger, wait until all trigger conditions are met on port. @@ -14441,7 +14441,7 @@ void captureInline4mhz() { * dump the samples back to the SUMP client. nothing special * is done for any triggers, this is effectively the 0/100 buffer split. */ - for (i = readCount ; i > 0; i--) { + for (i = readCount-1 ; i >= 0; i--) { #ifdef USE_PORTD Serial.write(logicdata[i] >> 2); #else diff --git a/logic_analyzer_sigrok/logic_analyzer_sigrok.ino b/logic_analyzer_sigrok/logic_analyzer_sigrok.ino index f44fec5..7feecc0 100644 --- a/logic_analyzer_sigrok/logic_analyzer_sigrok.ino +++ b/logic_analyzer_sigrok/logic_analyzer_sigrok.ino @@ -177,8 +177,8 @@ void captureInline2mhz(void); #define DEBUG_OFF PORTD = B00000000 #endif /* USE_PORTD */ -//#define DEBUG_MENU -//#define DEBUG +#define DEBUG_MENU +#define DEBUG #ifdef DEBUG #define MAX_CAPTURE_SIZE DEBUG_CAPTURE_SIZE @@ -533,7 +533,7 @@ void getCmd() { */ void captureMicro() { - unsigned int i; + signed int i; /* * basic trigger, wait until all trigger conditions are met on port. @@ -622,7 +622,7 @@ void captureMicro() { * dump the samples back to the SUMP client. nothing special * is done for any triggers, this is effectively the 0/100 buffer split. */ - for (i = readCount ; i > 0; i--) { + for (i = readCount-1 ; i >= 0; i--) { #ifdef USE_PORTD Serial.write(logicdata[i] >> 2); #else @@ -649,7 +649,7 @@ void captureMicro() { * this basic functionality. */ void captureMilli() { - unsigned int i = 0; + signed int i = 0; if (rleEnabled) { /* @@ -697,7 +697,7 @@ void captureMilli() { delay(delayTime); } } - for (i = readCount ; i > 0; i--) { + for (i = readCount-1 ; i >= 0; i--) { #ifdef USE_PORTD Serial.write(logicdata[i] >> 2); #else @@ -715,7 +715,7 @@ void captureMilli() { * */ void triggerMicro() { - unsigned int i = 0; + signed int i = 0; logicIndex = 0; triggerIndex = 0; @@ -890,7 +890,7 @@ void triggerMicro() { for (i = 0 ; i < readCount; i++) { if (logicIndex < 0) { - logicIndex = readCount; + logicIndex = readCount - 1; } #ifdef USE_PORTD Serial.write(logicdata[logicIndex--] >> 2);