commit
579cd56f57
@ -0,0 +1,46 @@
|
|||||||
|
# LayerFocus
|
||||||
|
|
||||||
|
The `LayerFocus` plugin exposes a number of layer-related commands via
|
||||||
|
[Focus][plugin:focus], to allow controlling layers from the host side.
|
||||||
|
|
||||||
|
[plugin:focus]: FocusSerial.md
|
||||||
|
|
||||||
|
## Using the plugin
|
||||||
|
|
||||||
|
To use the plugin, we need to include the header, and let the firmware know we
|
||||||
|
want to use it:
|
||||||
|
|
||||||
|
```c++
|
||||||
|
#include <Kaleidoscope.h>
|
||||||
|
#include <Kaleidoscope-FocusSerial.h>
|
||||||
|
#include <Kaleidoscope-LayerFocus.h>
|
||||||
|
|
||||||
|
KALEIDOSCOPE_INIT_PLUGINS(
|
||||||
|
Focus,
|
||||||
|
LayerFocus
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
## Focus commands
|
||||||
|
|
||||||
|
The plugin provides the following Focus commands:
|
||||||
|
|
||||||
|
### `layer.activate N` / `layer.deactivate N` / `layer.isActive N`
|
||||||
|
|
||||||
|
> Activates, deactivates, or queries the state of layer `N`.
|
||||||
|
|
||||||
|
### `layer.moveTo N`
|
||||||
|
|
||||||
|
> Moves to layer `N`, deactivating all other layers in the process.
|
||||||
|
|
||||||
|
### `layer.state [STATE...]`
|
||||||
|
|
||||||
|
> Without arguments, display the state of all layers, from lower to higher. Each
|
||||||
|
> active layer will be represented by `1`, while inactive layers will be
|
||||||
|
> represented by `0`.
|
||||||
|
>
|
||||||
|
> With arguments, override the state of layers with the `STATE` given.
|
||||||
|
|
||||||
|
## Dependencies
|
||||||
|
|
||||||
|
* [Kaleidoscope-FocusSerial](FocusSerial.md)
|
@ -0,0 +1,21 @@
|
|||||||
|
/* -*- mode: c++ -*-
|
||||||
|
* Kaleidoscope-LayerFocus -- Focus commands to work with layers
|
||||||
|
* Copyright (C) 2020 Keyboard.io, Inc
|
||||||
|
* Copyright (C) 2020 DygmaLab, SE.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it under
|
||||||
|
* the terms of the GNU General Public License as published by the Free Software
|
||||||
|
* Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
* details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with
|
||||||
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <kaleidoscope/plugin/LayerFocus.h>
|
@ -0,0 +1,83 @@
|
|||||||
|
/* -*- mode: c++ -*-
|
||||||
|
* Kaleidoscope-LayerFocus -- Focus commands to work with layers
|
||||||
|
* Copyright (C) 2020 Keyboard.io, Inc
|
||||||
|
* Copyright (C) 2020 DygmaLab, SE.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it under
|
||||||
|
* the terms of the GNU General Public License as published by the Free Software
|
||||||
|
* Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
* details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with
|
||||||
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Kaleidoscope-LayerFocus.h"
|
||||||
|
#include "Kaleidoscope-FocusSerial.h"
|
||||||
|
|
||||||
|
#include "kaleidoscope/layers.h"
|
||||||
|
|
||||||
|
namespace kaleidoscope {
|
||||||
|
namespace plugin {
|
||||||
|
|
||||||
|
EventHandlerResult LayerFocus::onFocusEvent(const char *command) {
|
||||||
|
if (::Focus.handleHelp(command, PSTR("layer.activate\nlayer.deactivate\nlayer.isActive"
|
||||||
|
"\nlayer.moveTo\nlayer.state")))
|
||||||
|
return EventHandlerResult::OK;
|
||||||
|
|
||||||
|
if (strncmp_P(command, PSTR("layer."), 6) != 0)
|
||||||
|
return EventHandlerResult::OK;
|
||||||
|
|
||||||
|
if (strcmp_P(command + 6, PSTR("activate")) == 0) {
|
||||||
|
if (!::Focus.isEOL()) {
|
||||||
|
uint8_t layer;
|
||||||
|
::Focus.read(layer);
|
||||||
|
::Layer.activate(layer);
|
||||||
|
}
|
||||||
|
} else if (strcmp_P(command + 6, PSTR("deactivate")) == 0) {
|
||||||
|
if (!::Focus.isEOL()) {
|
||||||
|
uint8_t layer;
|
||||||
|
::Focus.read(layer);
|
||||||
|
::Layer.deactivate(layer);
|
||||||
|
}
|
||||||
|
} else if (strcmp_P(command + 6, PSTR("isActive")) == 0) {
|
||||||
|
if (!::Focus.isEOL()) {
|
||||||
|
uint8_t layer;
|
||||||
|
::Focus.read(layer);
|
||||||
|
::Focus.send(::Layer.isActive(layer));
|
||||||
|
}
|
||||||
|
} else if (strcmp_P(command + 6, PSTR("moveTo")) == 0) {
|
||||||
|
if (!::Focus.isEOL()) {
|
||||||
|
uint8_t layer;
|
||||||
|
::Focus.read(layer);
|
||||||
|
::Layer.move(layer);
|
||||||
|
}
|
||||||
|
} else if (strcmp_P(command + 6, PSTR("state")) == 0) {
|
||||||
|
if (::Focus.isEOL()) {
|
||||||
|
for (uint8_t i = 0; i < 32; i++) {
|
||||||
|
::Focus.send(::Layer.isActive(i) ? 1 : 0);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
::Layer.move(0);
|
||||||
|
::Layer.deactivate(0);
|
||||||
|
|
||||||
|
for (uint8_t i = 0; i < 32 && !::Focus.isEOL(); i++) {
|
||||||
|
uint8_t b;
|
||||||
|
::Focus.read(b);
|
||||||
|
if (b)
|
||||||
|
::Layer.activate(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return EventHandlerResult::EVENT_CONSUMED;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
kaleidoscope::plugin::LayerFocus LayerFocus;
|
@ -0,0 +1,36 @@
|
|||||||
|
/* -*- mode: c++ -*-
|
||||||
|
* Kaleidoscope-LayerFocus -- Focus commands to work with layers
|
||||||
|
* Copyright (C) 2020 Keyboard.io, Inc
|
||||||
|
* Copyright (C) 2020 DygmaLab, SE.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it under
|
||||||
|
* the terms of the GNU General Public License as published by the Free Software
|
||||||
|
* Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
* details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with
|
||||||
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "kaleidoscope/Runtime.h"
|
||||||
|
|
||||||
|
namespace kaleidoscope {
|
||||||
|
namespace plugin {
|
||||||
|
|
||||||
|
class LayerFocus: public kaleidoscope::Plugin {
|
||||||
|
public:
|
||||||
|
LayerFocus() {}
|
||||||
|
|
||||||
|
EventHandlerResult onFocusEvent(const char *command);
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extern kaleidoscope::plugin::LayerFocus LayerFocus;
|
Loading…
Reference in new issue