Merge pull request #7 from keyboardio/f/onFocusEvent

Migrate to use the new onFocusEvent APIs
pull/389/head
Jesse Vincent 6 years ago committed by GitHub
commit e6f7072288
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,6 +1,6 @@
/* -*- mode: c++ -*- /* -*- mode: c++ -*-
* Kaleidoscope-HostOS -- Host OS detection and tracking for Kaleidoscope * 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 * 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 * the terms of the GNU General Public License as published by the Free Software
@ -18,4 +18,5 @@
#pragma once #pragma once
#include <Kaleidoscope/HostOS-Base.h> #include <Kaleidoscope/HostOS-Base.h>
#include <Kaleidoscope/HostOS-Focus.h>
#include <Kaleidoscope/HostOS-Guesser.h> #include <Kaleidoscope/HostOS-Guesser.h>

@ -55,20 +55,5 @@ void Base::os(Type new_os) {
EEPROM.update(eeprom_slice_, 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); Type os(void);
void os(Type new_os); void os(Type new_os);
static bool focusHook(const char *command);
protected: protected:
virtual void autoDetect(void) {} virtual void autoDetect(void) {}
Type os_; Type os_;
@ -53,5 +51,3 @@ class Base : public kaleidoscope::Plugin {
} }
extern kaleidoscope::hostos::Base HostOS; 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