tcMenu
Loading...
Searching...
No Matches
MessageProcessors.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 https://www.thecoderscorner.com (Dave Cherry).
3 * This product is licensed under an Apache license, see the LICENSE file in the top-level directory.
4 *
5 * MessageProcessors.h - standard message processors that decode tcMenu messages.
6 */
7
8#ifndef _TCMENU_MESSAGEPROCESSORS_H_
9#define _TCMENU_MESSAGEPROCESSORS_H_
10
11#include <PlatformDetermination.h>
12#include <SimpleCollections.h>
13#include "tcMenu.h"
14
21class TagValueRemoteConnector; // forward reference
22struct FieldAndValue; // forward reference
23
36 struct {
37 MenuItem* item;
38 int changeValue;
39 uint32_t correlation;
40 ChangeType changeType;
41 } value;
42 struct {
43 uint8_t major, minor;
44 ApiPlatform platform;
45 bool authProvided;
46 } join;
47 struct {
48 char name[20];
49 } pairing;
50 struct {
51 char mode;
52 uint8_t button;
53 uint32_t correlation;
54 } dialog;
55 struct {
56 HeartbeatMode hbMode;
57 } hb;
58 struct {
59 uint8_t data[20];
60 } custom;
61 struct {
62 uint16_t length;
63 const uint8_t* data;
64 } formLoad;
65};
66
67typedef void (*FieldUpdateFunction)(TagValueRemoteConnector*, FieldAndValue*, MessageProcessorInfo*);
68
77private:
79 FieldUpdateFunction fieldUpdateFn;
80
82 uint16_t msgType;
83
84public:
85 // as this class is stored in a btree list, it needs copy constructors and = operators implemented
86 MsgHandler() : fieldUpdateFn(nullptr), msgType(0xffff) {}
87 MsgHandler(uint16_t msgType, FieldUpdateFunction fn) : fieldUpdateFn(fn), msgType(msgType) {}
88 MsgHandler(const MsgHandler& other) = default;
89 MsgHandler& operator=(const MsgHandler& other) = default;
90 uint16_t getKey() const { return msgType; }
92 if(fieldUpdateFn) fieldUpdateFn(rc, fv, info);
93 }
94};
95
100
105
110
115
128
130 const char* formName;
131 const uint8_t* formDataGzipped;
132 const uint16_t formDataLen;
133};
134
147private:
149 BtreeList<uint16_t, MsgHandler> messageHandlers;
150 MsgHandler* currHandler;
151 static const EmbedControlFlashedForm** flashedFormTemplates;
152public:
153 static void setFormTemplatesInFlash(const EmbedControlFlashedForm** formTemplatesInFlash) { flashedFormTemplates = formTemplatesInFlash; }
154 static const EmbedControlFlashedForm** getFormTemplatesInFlash() { return flashedFormTemplates; }
155
160
164 void initialise();
165
169 void newMsg(uint16_t msgType);
173 void fieldUpdate(TagValueRemoteConnector* connector, FieldAndValue* field);
174
207 void addCustomMsgHandler(uint16_t msgType, FieldUpdateFunction callback) {
208 messageHandlers.add(MsgHandler(msgType, callback));
209 }
210};
211
212#endif /* _TCMENU_MESSAGEPROCESSORS_H_ */
void fieldUpdatePairingMsg(TagValueRemoteConnector *connector, FieldAndValue *field, MessageProcessorInfo *info)
Definition MessageProcessors.cpp:96
void fieldUpdateHeartbeatMsg(TagValueRemoteConnector *connector, FieldAndValue *field, MessageProcessorInfo *info)
Definition MessageProcessors.cpp:52
void fieldUpdateJoinMsg(TagValueRemoteConnector *connector, FieldAndValue *field, MessageProcessorInfo *info)
Definition MessageProcessors.cpp:110
void fieldGetFormNames(TagValueRemoteConnector *connector, FieldAndValue *field, MessageProcessorInfo *info)
void fieldUpdateValueMsg(TagValueRemoteConnector *connector, FieldAndValue *field, MessageProcessorInfo *info)
Definition MessageProcessors.cpp:254
void fieldHandleFormRequest(TagValueRemoteConnector *connector, FieldAndValue *field, MessageProcessorInfo *info)
void fieldUpdateDialogMsg(TagValueRemoteConnector *connector, FieldAndValue *field, MessageProcessorInfo *info)
Definition MessageProcessors.cpp:69
Definition MessageProcessors.h:129
Definition MessageProcessors.h:35
Definition RemoteConnector.h:90
HeartbeatMode
Definition RemoteTypes.h:149
ApiPlatform
Definition RemoteTypes.h:139
ChangeType
Definition RemoteTypes.h:132
Definition MessageProcessors.h:146
void addCustomMsgHandler(uint16_t msgType, FieldUpdateFunction callback)
Definition MessageProcessors.h:207
void fieldUpdate(TagValueRemoteConnector *connector, FieldAndValue *field)
Definition MessageProcessors.cpp:41
void newMsg(uint16_t msgType)
Definition MessageProcessors.cpp:27
CombinedMessageProcessor()
Definition MessageProcessors.cpp:15
void initialise()
Definition MessageProcessors.cpp:19
Definition MenuItems.h:329
Definition MessageProcessors.h:76
Definition RemoteConnector.h:187
The menu manager is responsible for managing a set of menu items, and is configured with a renderer a...