MCPcopy Create free account
hub / github.com/TailsmanDesign/PocketMage_PDA / updateTaskArray

Function updateTaskArray

Code/PocketMage_V3/src/OS_APPS/TASKS.cpp:89–152  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

87}
88
89void updateTaskArray() {
90 SDActive = true;
91 pocketmage::setCpuSpeed(240);
92
93 const char* tasksFile = "/sys/tasks.txt";
94
95 // If the file doesn't exist, create it to ensure the app can run on first launch
96 if (!global_fs->exists(tasksFile)) {
97 File f = global_fs->open(tasksFile, FILE_WRITE);
98 if (f) {
99 f.close();
100 } else {
101 ESP_LOGE(TAG, "Failed to create tasks file.");
102 if (SAVE_POWER) pocketmage::setCpuSpeed(POWER_SAVE_FREQ);
103 SDActive = false;
104 return;
105 }
106 }
107
108 File file = global_fs->open(tasksFile, "r");
109 if (!file) {
110 ESP_LOGE(TAG, "Failed to open file to read: %s", tasksFile);
111 if (SAVE_POWER) pocketmage::setCpuSpeed(POWER_SAVE_FREQ);
112 SDActive = false;
113 return;
114 }
115
116 tasks.clear(); // Clear the existing vector before loading the new data
117
118 // Loop through the file, line by line
119 while (file.available()) {
120 String line = file.readStringUntil('\n');
121 line.trim();
122
123 // Skip empty lines
124 if (line.length() == 0) {
125 continue;
126 }
127
128 int delimiterPos1 = line.indexOf('|');
129 int delimiterPos2 = line.indexOf('|', delimiterPos1 + 1);
130 int delimiterPos3 = line.indexOf('|', delimiterPos2 + 1);
131
132 // Basic validation for substrings
133 if (delimiterPos1 == -1 || delimiterPos2 == -1 || delimiterPos3 == -1) {
134 ESP_LOGW(TAG, "Malformed line in tasks file: %s", line.c_str());
135 continue;
136 }
137
138 // Extract task name, due date, priority, and completed status
139 String taskName = line.substring(0, delimiterPos1);
140 String dueDate = line.substring(delimiterPos1 + 1, delimiterPos2);
141 String priority = line.substring(delimiterPos2 + 1, delimiterPos3);
142 String completed = line.substring(delimiterPos3 + 1);
143
144 // Add the task to the vector
145 tasks.push_back({taskName, dueDate, priority, completed});
146 }

Callers 2

checkTimeoutFunction · 0.85
TASKS_INITFunction · 0.85

Calls 2

setCpuSpeedFunction · 0.85
clearMethod · 0.80

Tested by

no test coverage detected