Fix doc path
[opentx.git] / radio / src / storage / modelslist.h
blobc5a157207e757a18bb0e0f9305f8f72bb2639aa0
1 /*
2 * Copyright (C) OpenTX
4 * Based on code named
5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #ifndef _MODELSLIST_H_
22 #define _MODELSLIST_H_
24 #include <stdint.h>
25 #include <list>
26 #include "sdcard.h"
28 #define MODELCELL_WIDTH 172
29 #define MODELCELL_HEIGHT 59
31 // modelXXXXXXX.bin F,FF F,3F,FF\r\n
32 #define LEN_MODELS_IDX_LINE (LEN_MODEL_FILENAME + sizeof(" F,FF F,3F,FF\r\n")-1)
34 struct SimpleModuleData
36 uint8_t type;
37 uint8_t rfProtocol;
40 class ModelCell
42 public:
43 char modelFilename[LEN_MODEL_FILENAME+1];
44 char modelName[LEN_MODEL_NAME+1];
45 BitmapBuffer * buffer;
47 bool valid_rfData;
48 uint8_t modelId[NUM_MODULES];
49 SimpleModuleData moduleData[NUM_MODULES];
51 ModelCell(const char * name);
52 ~ModelCell();
54 void save(FIL* file);
56 void setModelName(char* name);
57 void setRfData(ModelData* model);
59 void setModelId(uint8_t moduleIdx, uint8_t id);
60 void setRfModuleData(uint8_t moduleIdx, ModuleData* modData);
62 bool fetchRfData();
63 void loadBitmap();
64 const BitmapBuffer * getBuffer();
65 void resetBuffer();
68 class ModelsCategory: public std::list<ModelCell *>
70 public:
71 char name[LEN_MODEL_FILENAME+1];
73 ModelsCategory(const char * name);
74 ~ModelsCategory();
76 ModelCell * addModel(const char * name);
77 void removeModel(ModelCell * model);
78 void moveModel(ModelCell * model, int8_t step);
79 void save(FIL * file);
82 class ModelsList
84 bool loaded;
85 std::list<ModelsCategory *> categories;
86 ModelsCategory * currentCategory;
87 ModelCell * currentModel;
88 unsigned int modelsCount;
90 void init();
92 public:
94 ModelsList();
95 ~ModelsList();
97 bool load();
98 void save();
99 void clear();
101 const std::list<ModelsCategory *>& getCategories() const {
102 return categories;
105 void setCurrentCategorie(ModelsCategory* cat);
106 ModelsCategory* getCurrentCategory() const {
107 return currentCategory;
110 void setCurrentModel(ModelCell* cell);
111 ModelCell* getCurrentModel() const {
112 return currentModel;
115 unsigned int getModelsCount() const {
116 return modelsCount;
119 bool readNextLine(char * line, int maxlen);
121 ModelsCategory * createCategory();
122 void removeCategory(ModelsCategory * category);
124 ModelCell * addModel(ModelsCategory * category, const char * name);
125 void removeModel(ModelsCategory * category, ModelCell * model);
126 void moveModel(ModelsCategory * category, ModelCell * model, int8_t step);
127 void moveModel(ModelCell * model, ModelsCategory * previous_category, ModelsCategory * new_category);
129 bool isModelIdUnique(uint8_t moduleIdx, char* warn_buf, size_t warn_buf_len);
130 uint8_t findNextUnusedModelId(uint8_t moduleIdx);
132 void onNewModelCreated(ModelCell* cell, ModelData* model);
134 protected:
135 FIL file;
139 extern ModelsList modelslist;
141 #endif // _MODELSLIST_H_