The Pedigree Project 0.1
HidUtils.h
1/*
2 * Copyright (c) 2008-2014, Pedigree Developers
3 *
4 * Please see the CONTRIB file in the root of the source tree for a full
5 * list of contributors.
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
20#ifndef HIDUTILS_H
21#define HIDUTILS_H
22
23#include "pedigree/kernel/Spinlock.h"
24#include "pedigree/kernel/processor/types.h"
25
27enum HidDeviceType { Keyboard, Mouse, Joystick, UnknownDevice = ~0 };
28
30namespace HidUtils {
33 public:
34 InputState();
36 InputState(const InputState&) = delete;
37 InputState& operator=(const InputState&) = delete;
38
39 private:
40 friend void sendInputToManager(HidDeviceType deviceType, uint16_t nUsagePage, uint16_t nUsage,
41 int64_t nRelativeValue, InputState& state);
42 static uint32_t buttons(HidDeviceType deviceType);
43 static Spinlock m_Lock;
44 static InputState* m_pInputs;
45 InputState* m_pNext;
46 uint64_t m_Keys[4];
47 uint32_t m_MouseButtons;
48 uint32_t m_JoystickButtons;
49};
50
52uint64_t getBufferField(uint8_t* pBuffer, size_t nStart, size_t nLength);
53
55void fixNegativeMinimum(int64_t& nMin, int64_t nMax);
56
58void fixNegativeValue(int64_t nMin, int64_t nMax, int64_t& nValue);
59
61void sendInputToManager(HidDeviceType deviceType, uint16_t nUsagePage, uint16_t nUsage,
62 int64_t nRelativeValue, InputState& state);
63}; // namespace HidUtils
64
65#endif
Held input belongs to a report instance and is retired with that instance.
Definition HidUtils.h:32
friend void sendInputToManager(HidDeviceType deviceType, uint16_t nUsagePage, uint16_t nUsage, int64_t nRelativeValue, InputState &state)
Sends the input to the right handler in HidInputManager or InputManager.
Various utility functions used in HID.
Definition HidUtils.h:30
void fixNegativeMinimum(int64_t &nMin, int64_t nMax)
Converts.
Definition HidUtils.cc:74
uint64_t getBufferField(uint8_t *pBuffer, size_t nStart, size_t nLength)
Retrieves a field in a buffer.
Definition HidUtils.cc:65
void fixNegativeValue(int64_t nMin, int64_t nMax, int64_t &nValue)
Converts.
Definition HidUtils.cc:90
void sendInputToManager(HidDeviceType deviceType, uint16_t nUsagePage, uint16_t nUsage, int64_t nRelativeValue, InputState &state)
Sends the input to the right handler in HidInputManager or InputManager.
Definition HidUtils.cc:108