Migrate to use the new onFocusEvent APIs

Signed-off-by: Gergely Nagy <algernon@keyboard.io>
pull/389/head
Gergely Nagy 6 years ago
parent 755e94a98e
commit e07007c5aa

@ -1,6 +1,6 @@
/* -*- mode: c++ -*-
* Kaleidoscope-HostOS -- Host OS detection and tracking for Kaleidoscope
* Copyright (C) 2016, 2017 Keyboard.io, Inc
* Copyright (C) 2016, 2017, 2018 Keyboard.io, Inc
*
* 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
@ -18,4 +18,5 @@
#pragma once
#include <Kaleidoscope/HostOS-Base.h>
#include <Kaleidoscope/HostOS-Focus.h>
#include <Kaleidoscope/HostOS-Guesser.h>

@ -55,20 +55,5 @@ void Base::os(Type new_os) {
EEPROM.update(eeprom_slice_, os_);
}
bool Base::focusHook(const char *command) {
if (strcmp_P(command, PSTR("hostos.type")) != 0)
return false;
if (Serial.peek() == '\n') {
Serial.println(::HostOS.os());
} else {
uint8_t new_os = Serial.parseInt();
::HostOS.os((Type) new_os);
}
Serial.read();
return true;
}
}
}

@ -38,8 +38,6 @@ class Base : public kaleidoscope::Plugin {
Type os(void);
void os(Type new_os);
static bool focusHook(const char *command);
protected:
virtual void autoDetect(void) {}
Type os_;
@ -53,5 +51,3 @@ class Base : public kaleidoscope::Plugin {
}
extern kaleidoscope::hostos::Base HostOS;
#define FOCUS_HOOK_HOSTOS FOCUS_HOOK(HostOS.focusHook, "hostos.type")

@ -0,0 +1,46 @@
/* -*- mode: c++ -*-
* Kaleidoscope-HostOS -- Host OS detection and tracking for Kaleidoscope
* Copyright (C) 2016, 2017, 2018 Keyboard.io, Inc
*
* 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-HostOS.h>
#include <Kaleidoscope-FocusSerial.h>
namespace kaleidoscope {
namespace hostos {
EventHandlerResult FocusHostOSCommand::onFocusEvent(const char *command) {
const char *cmd = PSTR("hostos.type");
if (::Focus.handleHelp(command, cmd))
return EventHandlerResult::OK;
if (strcmp_P(command, cmd) != 0)
return EventHandlerResult::OK;
if (Serial.peek() == '\n') {
Serial.println(::HostOS.os());
} else {
uint8_t new_os = Serial.parseInt();
::HostOS.os((Type) new_os);
}
Serial.read();
return EventHandlerResult::EVENT_CONSUMED;
}
}
}
kaleidoscope::hostos::FocusHostOSCommand FocusHostOSCommand;

@ -0,0 +1,34 @@
/* -*- mode: c++ -*-
* Kaleidoscope-HostOS -- Host OS detection and tracking for Kaleidoscope
* Copyright (C) 2016, 2017, 2018 Keyboard.io, Inc
*
* 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.h>
namespace kaleidoscope {
namespace hostos {
class FocusHostOSCommand : public kaleidoscope::Plugin {
public:
FocusHostOSCommand() {}
EventHandlerResult onFocusEvent(const char *command);
};
}
}
extern kaleidoscope::hostos::FocusHostOSCommand FocusHostOSCommand;
Loading…
Cancel
Save