1
0
mirror of https://github.com/TomHarte/CLK.git synced 2025-01-26 15:32:04 +00:00

Implements register 2 listen.

This commit is contained in:
Thomas Harte 2021-02-15 15:05:46 -05:00
parent 99c21925f4
commit e773b331cd
2 changed files with 16 additions and 0 deletions

View File

@ -51,10 +51,25 @@ void Keyboard::perform_command(const Command &command) {
}
break;
case Command::Type::Listen:
// If a listen is incoming for register 2, prepare to capture LED statuses.
if(command.reg == 2) {
receive_bytes(2);
}
break;
default: break;
}
}
void Keyboard::did_receive_data(const Command &, const std::vector<uint8_t> &data) {
// This must be a register 2 listen; update the LED statuses.
// TODO: and possibly display these.
modifiers_ = (modifiers_ & 0xfff8) | (data[1] & 7);
}
bool Keyboard::set_key_pressed(Key key, bool is_pressed) {
// ADB keyboard events: low 7 bits are a key code; bit 7 is either 0 for pressed or 1 for released.
std::lock_guard lock_guard(keys_mutex_);

View File

@ -104,6 +104,7 @@ class Keyboard: public ReactiveDevice {
private:
void perform_command(const Command &command) override;
void did_receive_data(const Command &, const std::vector<uint8_t> &) override;
std::mutex keys_mutex_;
std::array<bool, 128> pressed_keys_;