-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworkout_storage.h
More file actions
66 lines (52 loc) · 2.26 KB
/
Copy pathworkout_storage.h
File metadata and controls
66 lines (52 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#pragma once
#include <Arduino.h>
#include <vector>
#include <ArduinoJson.h>
#include <LittleFS.h>
struct SwimStep {
uint16_t pace100s; // seconds per 100 m (0 = rest)
uint32_t durSec; // duration in seconds
String note; // user‐entered note
};
// A workout is an ordered list of items. Each item is either a single swim or a
// "set": a group of swims repeated `repeat` times. Sets do not nest (one level).
struct WorkoutItem {
bool isSet = false; // false = plain swim, true = a repeated set
uint16_t repeat = 1; // set repeat count (>= 1); ignored for a plain swim
String note; // optional set label
SwimStep swim{}; // valid when !isSet
std::vector<SwimStep> swims; // valid when isSet
};
struct Workout {
String id; // unique workout ID
String name;
std::vector<WorkoutItem> items; // authored structure (preserves sets)
};
// One run-time step after expanding every set, carrying set context so the
// run screen / LED panel can show "Set 2/3".
struct FlatStep {
SwimStep swim;
int16_t setIndex = -1; // -1 = not in a set; else 0-based index among the workout's sets
uint16_t setRep = 0; // 1-based repetition within its set
uint16_t setReps = 0; // total repetitions of its set
uint16_t setSize = 0; // number of distinct swims in its set (one repetition)
uint16_t setPos = 0; // 0-based position of this swim within one repetition
String setName; // the set's own name, for rows whose swim has no note
};
namespace WorkoutStorage {
/** Initialise LittleFS; must be called once in setup(). */
bool begin();
/** List all workout IDs (reads /workouts/*.json). */
std::vector<String> list_ids();
/** Load a single workout by ID. Returns false if not found. */
bool load(String id, Workout &out);
/** Save or overwrite a workout (writes /workouts/w<ID>.json). */
bool save(const Workout &w);
/** Erase the workout file for this ID. */
bool erase(String id);
/** JSON <→> Workout codecs. */
String to_json(const Workout &w);
bool from_json(const uint8_t *data, size_t len, Workout &w);
/** Expand all sets into a flat run-time list (with set context per step). */
std::vector<FlatStep> flatten(const Workout &w);
}