Skip to content

Commit ef09874

Browse files
committed
word count display on rev.4
1 parent 1bf1a2a commit ef09874

File tree

5 files changed

+34
-21
lines changed

5 files changed

+34
-21
lines changed

micro-journal-rev-4-esp32/src/display/ST7735/WordProcessor/WordProcessor.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,9 @@ void WP_render_status(TFT_eSPI *ptft, U8g2_for_TFT_eSPI *pu8f)
253253
pu8f->setCursor(screen_width - font_width / 2, font_width * 2 / 3);
254254
pu8f->print(String(file_index));
255255

256-
#ifdef DEBUG
256+
// Word count print
257257
int small_font_width = 10;
258-
int bufferSize = Editor::getInstance().getBufferSize();
258+
int bufferSize = Editor::getInstance().wordCountFile + Editor::getInstance().wordCountBuffer; ;
259259
String bufferStr = String(bufferSize);
260260
// Calculate x position so it's right-aligned
261261
int textWidth = bufferStr.length() * small_font_width;
@@ -268,7 +268,6 @@ void WP_render_status(TFT_eSPI *ptft, U8g2_for_TFT_eSPI *pu8f)
268268
// Draw buffer size
269269
pu8f->setCursor(x, y);
270270
pu8f->print(bufferStr);
271-
#endif
272271

273272
// height 100% 80
274273
float batteryPercent = app["battery"].as<float>();

micro-journal-rev-4-esp32/src/service/Editor/Editor.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ void Editor::saveFile()
217217
// If file doesn't exist, create it
218218
file = gfs()->open(fileName.c_str(), "w+"); // create + read/write
219219
}
220-
220+
221221
if (!file)
222222
{
223223
//
@@ -288,6 +288,10 @@ void Editor::saveFile()
288288

289289
//
290290
savingInProgress = false;
291+
292+
#if defined(DEBUG) && defined(BOARD_PICO)
293+
printMemoryUsage();
294+
#endif
291295
}
292296

293297
// Make the current file empty

micro-journal-rev-4-esp32/src/service/Editor/Editor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <Arduino.h>
55

66
#ifdef BOARD_PICO
7-
#define BUFFER_SIZE 1000
7+
#define BUFFER_SIZE 2000
88
#endif
99

1010
#ifdef BOARD_ESP32_S3

micro-journal-rev-4-esp32/src/service/Tools/Tools.cpp

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ String formatNumber(int num)
3232
return formattedNumber;
3333
}
3434

35-
3635
// Get the size of a file in bytes
3736
size_t fileSize(String fileName)
3837
{
@@ -41,14 +40,14 @@ size_t fileSize(String fileName)
4140
{
4241
File file = SD.open(fileName, FILE_READ);
4342
if (!file)
44-
{ //something bad happened
45-
char buffer [32];
43+
{ // something bad happened
44+
char buffer[32];
4645
sprintf(buffer, "Failed to open a file. %s\n", fileName);
4746
_log(buffer);
4847
file_size = -1;
4948
}
50-
else
51-
{ //file exists
49+
else
50+
{ // file exists
5251
file_size = file.size();
5352
}
5453
//
@@ -58,7 +57,6 @@ size_t fileSize(String fileName)
5857
return file_size;
5958
}
6059

61-
6260
// Create an array of String objects
6361
// Many of these ascii codes can be tracked back to:
6462
// https://en.wikipedia.org/wiki/ISO/IEC_8859 column 1 of the table
@@ -195,15 +193,13 @@ static const String extended_ascii[128] = {
195193

196194
String asciiToUnicode(uint8_t value)
197195
{
198-
if (value < 128)
199-
return "";
196+
if (value < 128)
197+
return "";
200198

201-
uint8_t code = value - 128;
202-
return extended_ascii[code];
199+
uint8_t code = value - 128;
200+
return extended_ascii[code];
203201
}
204202

205-
206-
207203
String format(const char *format, ...)
208204
{
209205
char buffer[256]; // Adjust the size according to your needs
@@ -212,4 +208,16 @@ String format(const char *format, ...)
212208
vsnprintf(buffer, sizeof(buffer), format, args);
213209
va_end(args);
214210
return String(buffer);
215-
}
211+
}
212+
213+
#if defined(DEBUG) && defined(BOARD_PICO)
214+
extern "C" char* sbrk(int incr);
215+
216+
217+
void printMemoryUsage()
218+
{
219+
char top;
220+
ptrdiff_t free_memory = &top - reinterpret_cast<char*>(sbrk(0));
221+
Serial.printf("Stack Free: %td bytes\n", abs(free_memory));
222+
}
223+
#endif
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#ifndef Tools_h
2-
#define Tools_h
1+
#pragma once
32

43
#include <Arduino.h>
54

@@ -8,4 +7,7 @@ size_t fileSize(String fileName);
87
String asciiToUnicode(uint8_t value);
98
String format(const char *format, ...);
109

11-
#endif
10+
11+
#if defined(DEBUG) && defined(BOARD_PICO)
12+
void printMemoryUsage();
13+
#endif

0 commit comments

Comments
 (0)