Limits - KL-Psychological-Methodology/TWatch-2020-ESM GitHub Wiki

We try to prefer static allocation in the firmware code in man places. This means that the size of certain stings and arrays need to be predefined at compile time. Thus, there are hard limits for things like the amount of items per questionnaire. Historically, a lot of the current defaults/limits have been derived from a predecessor project which used a microcontroller with less memory, and thus have been chosen to be practical but small enough to fit into that smaller memory. The ESP32 should be able to handle higher limits, but so far we have have had no issues with these in our usecases.

The Default Limits

The limits are defined in the file include/const_defines.h. In that file there is a section indicated by the comment // Maxima definitions. In this sections the following maxima are defined. If these limits are not enough for your specific use case, you can edit them in this file and recompile the firmware.

Constant Name Default Purpose
NAMELENGTH 21 Length of most names, including the name of the study, the name of questionnaires and the names of items.
LOGSTINGLENGTH 1024 When logging responses to the response file, the code utilizes string formatting, requiring a complete string to store the whole line printed to the file. This defines the lengh of this target string.
LABELLENGTH 25 The length of the label strings in the response formats of the Likert scale and visual analogue scale items.
PROMPTLENGTH 251 The length of the item text on questionnaire items.
MAXITEMNUM 20 Maximum number of items per questionnaire.
MENULISTLENGTH 10 Maximum number of menu entries in the GUI. This is also used in the menu listing event-based questionnaires, so this is indirectly the maximum number of event-based questionnaires.
MAXALARMS 30 Maximum number of pregenerated notification times across all questionnaires.
MAXLIKERT 15 The hard maximum for points on a Likert scale item. However, due to the screen size we do not recommend configuring a Likert scale item for more than 7 points.
OPTIONSLENGTH 128 The length of the string encoding all the options for an options type item. Keep in mind that this also includes the \n separators (one bit) between options.
MAXRANDOMGROUPS 5 The maximum number of separate ranges that can be randomized per questionnaire.

A Note on String Lengths

The firmware code mostly uses c-style strings, i.e., arrays of single byte characters. There are two things to keep in mind.

  1. C strings are terminated by a \0, so can only hold one less ASCII character than is their length. E.g., strings set to be NAMELENGTH (21) characters long can actually olny hold a string of 20 character.
  2. Non-ASCII characters are encoded using multiple bytes, meaning that a string set to be of length NAMELENGTH (21, or rather 20+1), can not hold a full 20 letter string containing non-ASCII Characters (e.g., "ö"). UFT-8 will take up one to four bytes per letter, depending on their position in the unicode table (for estimation, ASCII characters will always use 1 byte, other Latin characters will use 2 bytes). This may make changes necessary for languages using glyphs in the later unicode ranges (in these cases also see the section on extending the font in the entry on Language Localization.