aboutsummaryrefslogtreecommitdiffstats
path: root/lib/lufa/Projects/HIDReportViewer/HIDReportViewer.h
blob: 22224fe1a421c4665de40623971d92058ab89b52 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
             LUFA Library
     Copyright (C) Dean Camera, 2017.

  dean [at] fourwalledcubicle [dot] com
           www.lufa-lib.org
*/

/*
  Copyright 2017  Dean Camera (dean [at] fourwalledcubicle [dot] com)

  Permission to use, copy, modify, distribute, and sell this
  software and its documentation for any purpose is hereby granted
  without fee, provided that the above copyright notice appear in
  all copies and that both that the copyright notice and this
  permission notice and warranty disclaimer appear in supporting
  documentation, and that the name of the author not be used in
  advertising or publicity pertaining to distribution of the
  software without specific, written prior permission.

  The author disclaims all warranties with regard to this
  software, including all implied warranties of merchantability
  and fitness.  In no event shall the author be liable for any
  special, indirect or consequential damages or any damages
  whatsoever resulting from loss of use, data or profits, whether
  in an action of contract, negligence or other tortious action,
  arising out of or in connection with the use or performance of
  this software.
*/

/** \file
 *
 *  Header file for HIDReportViewer.c.
 */

#ifndef _HID_REPORT_VIEWER_H_
#define _HID_REPORT_VIEWER_H_

	/* Includes: */
		#include <avr/io.h>
		#include <avr/wdt.h>
		#include <avr/pgmspace.h>
		#include <avr/power.h>
		#include <avr/interrupt.h>
		#include <stdio.h>
		#include <inttypes.h>

		#include <LUFA/Drivers/Misc/TerminalCodes.h>
		#include <LUFA/Drivers/Peripheral/Serial.h>
		#include <LUFA/Drivers/Board/LEDs.h>
		#include <LUFA/Drivers/USB/USB.h>
		#include <LUFA/Platform/Platform.h>

	/* Macros: */
		/** LED mask for the library LED driver, to indicate that the USB interface is not ready. */
		#define LEDMASK_USB_NOTREADY      LEDS_LED1

		/** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */
		#define LEDMASK_USB_ENUMERATING  (LEDS_LED2 | LEDS_LED3)

		/** LED mask for the library LED driver, to indicate that the USB interface is ready. */
		#define LEDMASK_USB_READY        (LEDS_LED2 | LEDS_LED4)

		/** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */
		#define LEDMASK_USB_ERROR        (LEDS_LED1 | LEDS_LED3)

		/** LED mask for the library LED driver, to indicate that the USB interface is busy. */
		#define LEDMASK_USB_BUSY         (LEDS_LED1 | LEDS_LED3 | LEDS_LED4)

	/* Function Prototypes: */
		void SetupHardware(void);
		void RetrieveDeviceData(void);
		void OutputReportSizes(void);
		void OutputParsedReportItems(void);
		void OutputCollectionPath(const HID_CollectionPath_t* const CollectionPath);

		void EVENT_USB_Host_HostError(const uint8_t ErrorCode);
		void EVENT_USB_Host_DeviceAttached(void);
		void EVENT_USB_Host_DeviceUnattached(void);
		void EVENT_USB_Host_DeviceEnumerationFailed(const uint8_t ErrorCode,
		                                            const uint8_t SubErrorCode);
		void EVENT_USB_Host_DeviceEnumerationComplete(void);

		bool CALLBACK_HIDParser_FilterHIDReportItem(HID_ReportItem_t* const CurrentItem);

#endif
and we need to unlock it. In this case, we will // reset the state in our map and return false. When the user releases the // key, the up event will no longer be masked and the OS will observe the // released key. // 3. KC_LOCK was just pressed. In this case, we set up the state machine // to watch for the next key down event, and finish processing // 4. The keycode is below 0xFF, and we are watching for new keys. In this case, // we will send the key down event to the os, and set the key_state for that // key to mask the up event. // 5. The keycode is above 0xFF, and we're wathing for new keys. In this case, // the user pressed a key that we cannot "lock", as it's a series of keys, // or a macro invocation, or a layer transition, or a custom-defined key, or // or some other arbitrary code. In this case, we bail immediately, reset // our watch state, and return true. // // In the event of an up event, there are these possibilities: // 1. The key is not being locked. In this case, we return true and bail // immediately. This is the common case. // 2. The key is being locked. In this case, we will mask the up event // by returning false, so the OS never sees that the key was released // until the user pressed the key again. // We translate any OSM keycodes back to their original keycodes, so that if the key being // one-shot modded is a standard keycode, we can handle it. This is the only set of special // keys that we handle uint16_t translated_keycode = translate_keycode(*keycode); if (record->event.pressed) { // Non-standard keycode, reset and return if (!(IS_STANDARD_KEYCODE(translated_keycode) || translated_keycode == KC_LOCK)) { watching = false; return true; } // If we're already watching, turn off the watch. if (translated_keycode == KC_LOCK) { watching = !watching; return false; } if (IS_STANDARD_KEYCODE(translated_keycode)) { // We check watching first. This is so that in the following scenario, we continue to // hold the key: KC_LOCK, KC_F, KC_LOCK, KC_F // If we checked in reverse order, we'd end up holding the key pressed after the second // KC_F press is registered, when the user likely meant to hold F if (watching) { watching = false; SET_KEY_STATE(translated_keycode); // We need to set the keycode passed in to be the translated keycode, in case we // translated a OSM back to the original keycode. *keycode = translated_keycode; // Let the standard keymap send the keycode down event. The up event will be masked. return true; } if (KEY_STATE(translated_keycode)) { UNSET_KEY_STATE(translated_keycode); // The key is already held, stop this process. The up event will be sent when the user // releases the key. return false; } } // Either the key isn't a standard key, or we need to send the down event. Continue standard // processing return true; } else { // Stop processing if it's a standard key and we're masking up. return !(IS_STANDARD_KEYCODE(translated_keycode) && KEY_STATE(translated_keycode)); } }