Kaleidoscope
Focus.h
Go to the documentation of this file.
1 /* -*- mode: c++ -*-
2  * Kaleidoscope-Focus -- Bidirectional communication plugin
3  * Copyright (C) 2017 Gergely Nagy
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #pragma once
20 
21 #include <Kaleidoscope.h>
22 
23 #if FOCUS_WITHOUT_DOCS
24 #define FOCUS_HOOK(n, d) ({ \
25  static kaleidoscope::Focus::HookNode _c = { \
26  &n, NULL, NULL}; \
27  &_c; \
28  })
29 #else
30 #define FOCUS_HOOK(n, d) ({ \
31  static kaleidoscope::Focus::HookNode _c = { \
32  &n, F(d), NULL}; \
33  &_c; \
34  })
35 #endif
36 
37 namespace kaleidoscope {
38 class Focus : public KaleidoscopePlugin {
39  public:
40  typedef bool (*Hook)(const char *command);
41  typedef struct HookNode {
43  const __FlashStringHelper *docs;
45  } HookNode;
46 
47  Focus(void);
48 
49  void begin(void) final;
50 
51  static void addHook(HookNode *new_node);
52 
53  /* Helpers */
54  static void printNumber(uint16_t number);
55  static void printSpace(void);
56  static void printColor(uint8_t r, uint8_t g, uint8_t b);
57  static void printSeparator(void);
58  static void printBool(bool b);
59 
60  /* Hooks */
61  static bool helpHook(const char *command);
62  static bool versionHook(const char *command);
63 
64  private:
65  static HookNode *root_node_;
66  static char command_[32];
67 
68  static void loopHook(bool is_post_clear);
69  static void drain(void);
70 };
71 };
72 
74 
75 #define FOCUS_HOOK_HELP FOCUS_HOOK(Focus.helpHook, "help")
76 #define FOCUS_HOOK_VERSION FOCUS_HOOK(Focus.versionHook, "version")
void begin(void) final
Definition: Focus.cpp:30
static void printSeparator(void)
Definition: Focus.cpp:102
Focus(void)
Definition: Focus.cpp:27
Definition: hid.cpp:4
Definition: Focus.h:41
HookNode * next
Definition: Focus.h:44
const __FlashStringHelper * docs
Definition: Focus.h:43
static void printSpace(void)
Definition: Focus.cpp:86
struct kaleidoscope::Focus::HookNode HookNode
static void printColor(uint8_t r, uint8_t g, uint8_t b)
Definition: Focus.cpp:94
Hook handler
Definition: Focus.h:42
bool(* Hook)(const char *command)
Definition: Focus.h:40
Definition: Kaleidoscope.h:40
static bool versionHook(const char *command)
Definition: Focus.cpp:124
static void printNumber(uint16_t number)
Definition: Focus.cpp:90
static void printBool(bool b)
Definition: Focus.cpp:106
static bool helpHook(const char *command)
Definition: Focus.cpp:110
static void addHook(HookNode *new_node)
Definition: Focus.cpp:40
Definition: Focus.h:38