From d7db7c2670ae35f396461d1fedfbe6be51296a5d Mon Sep 17 00:00:00 2001 From: Michael Richters Date: Wed, 18 Nov 2020 09:57:40 -0600 Subject: [PATCH] Add `KeyAddr::none()` constant & `KeyAddr::clear()` method This is a convenience only, but it's much more straightforward than the expression `key_addr = KeyAddr(KeyAddr::invalide_state)` or the overly enigmatic `key_addr = KeyAddr()`. `KeyAddr::none()` is meant to be useful for initialization of variables: `KeyAddr my_addr = KeyAddr::none()` `KeyAddr::clear()` is meant to be the counterpart of the `isValid()` test, to set an existing variable to an invalid address: `my_addr.clear()` vs `if (my_addr.isValid()) ...` Signed-off-by: Michael Richters --- src/kaleidoscope/MatrixAddr.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/kaleidoscope/MatrixAddr.h b/src/kaleidoscope/MatrixAddr.h index 8e13ddbe..83fe58da 100644 --- a/src/kaleidoscope/MatrixAddr.h +++ b/src/kaleidoscope/MatrixAddr.h @@ -1,5 +1,5 @@ /* Kaleidoscope - Firmware for computer input devices - * Copyright (C) 2013-2019 Keyboard.io, Inc. + * Copyright (C) 2013-2020 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 @@ -74,6 +74,18 @@ class MatrixAddr { "Matrix type conversion failed. Source type must not have greater col size than target type"); } + // Get an invalid key address. Useful when initializing a state variable or + // function parameter that handles invalid addresses. + static constexpr ThisType none() { + return ThisType(invalid_state); + } + + // Invalidate the key address. Useful in plugins that need a state variable + // that is sometimes valid, and sometimes not. + void clear() { + offset_ = invalid_state; + } + constexpr uint8_t row() const { return offset_ / cols; }