File indexing completed on 2024-05-12 04:53:40

0001 /*
0002     mediactrl.c -- Jog Shuttle device support
0003     SPDX-FileCopyrightText: 2001-2007 Dan Dennedy <dan@dennedy.org>
0004 
0005     SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0006 */
0007 
0008 #pragma once
0009 
0010 #include <linux/input.h>
0011 #include <sys/time.h>
0012 
0013 // just to make the code more readable
0014 #define KEY_RELEASE 0x00
0015 #define KEY_PRESS 0x01
0016 
0017 // not used yet
0018 #define MEDIA_ST_ACTIVE 0x02
0019 #define MEDIA_ST_INACTIVE 0x01
0020 
0021 // media ctrl event types
0022 #define MEDIA_CTRL_EVENT_NONE 0x00
0023 #define MEDIA_CTRL_EVENT_KEY 0x01
0024 #define MEDIA_CTRL_EVENT_JOG 0x02
0025 #define MEDIA_CTRL_EVENT_SHUTTLE 0x03
0026 #define MEDIA_CTRL_EVENT_STICK 0x04
0027 
0028 // the disconnect event - not used yet
0029 #define MEDIA_CTRL_DISCONNECT 0x01
0030 
0031 #define MEDIA_CTRL_SHIFT 0x01
0032 
0033 #define MEDIA_CTRL_PLAY 0x10
0034 #define MEDIA_CTRL_PLAY_FWD 0x10
0035 #define MEDIA_CTRL_REVERSE 0x11
0036 #define MEDIA_CTRL_PLAY_REV 0x11
0037 #define MEDIA_CTRL_STOP 0x12
0038 #define MEDIA_CTRL_PAUSE 0x13
0039 #define MEDIA_CTRL_NEXT 0x14
0040 #define MEDIA_CTRL_PREV 0x15
0041 #define MEDIA_CTRL_RECORD 0x16
0042 #define MEDIA_CTRL_FAST_FORWARD 0x17
0043 #define MEDIA_CTRL_REWIND 0x18
0044 
0045 #define MEDIA_CTRL_STICK_LEFT 0x20
0046 #define MEDIA_CTRL_STICK_RIGHT 0x21
0047 #define MEDIA_CTRL_STICK_UP 0x22
0048 #define MEDIA_CTRL_STICK_DOWN 0x23
0049 
0050 /* function keys, usually at top of device */
0051 #define MEDIA_CTRL_F1 0x100
0052 #define MEDIA_CTRL_F2 0x101
0053 #define MEDIA_CTRL_F3 0x102
0054 #define MEDIA_CTRL_F4 0x103
0055 #define MEDIA_CTRL_F5 0x104
0056 #define MEDIA_CTRL_F6 0x105
0057 #define MEDIA_CTRL_F7 0x106
0058 #define MEDIA_CTRL_F8 0x107
0059 #define MEDIA_CTRL_F9 0x108
0060 #define MEDIA_CTRL_F10 0x109
0061 #define MEDIA_CTRL_F11 0x10a
0062 #define MEDIA_CTRL_F12 0x10b
0063 #define MEDIA_CTRL_F13 0x10c
0064 #define MEDIA_CTRL_F14 0x10d
0065 #define MEDIA_CTRL_F15 0x10e
0066 #define MEDIA_CTRL_F16 0x10f
0067 
0068 #define MEDIA_CTRL_B1 0x110
0069 #define MEDIA_CTRL_B2 0x111
0070 #define MEDIA_CTRL_B3 0x112
0071 #define MEDIA_CTRL_B4 0x113
0072 #define MEDIA_CTRL_B5 0x114
0073 #define MEDIA_CTRL_B6 0x115
0074 #define MEDIA_CTRL_B7 0x116
0075 #define MEDIA_CTRL_B8 0x117
0076 #define MEDIA_CTRL_B9 0x118
0077 #define MEDIA_CTRL_B10 0x119
0078 #define MEDIA_CTRL_B11 0x11a
0079 #define MEDIA_CTRL_B12 0x11b
0080 #define MEDIA_CTRL_B13 0x11c
0081 #define MEDIA_CTRL_B14 0x11d
0082 #define MEDIA_CTRL_B15 0x11e
0083 #define MEDIA_CTRL_B16 0x11f
0084 
0085 #ifdef __cplusplus
0086 extern "C" {
0087 #endif
0088 
0089 struct media_ctrl_device;
0090 
0091 struct media_ctrl_key
0092 {
0093     int key; // internal keycode - do not use
0094     const char *name;
0095     int code; // eventcode
0096     //  int action;
0097 };
0098 
0099 struct media_ctrl_event
0100 {
0101     struct timeval time;
0102     unsigned short type;
0103     unsigned short code;
0104     char *name;
0105     int value;
0106     unsigned short index;
0107 };
0108 
0109 struct media_ctrl
0110 {
0111 
0112     int fd;
0113     int eventno;
0114 
0115     int status;
0116 
0117     struct media_ctrl_device *device;
0118 
0119     long jogpos;
0120     int shuttlepos;
0121 
0122     int lastval;
0123     int lastshu;
0124 
0125     int jogrel;                  // accumulate relative values if events come too fast
0126     unsigned long last_jog_time; // last jog event
0127 };
0128 
0129 struct media_ctrl_device
0130 {
0131     int vendor;
0132     int product;
0133     const char *name;
0134     struct media_ctrl_key *keys;
0135     void (*translate)(struct media_ctrl *ctrl, struct input_event *ev, struct media_ctrl_event *me);
0136 };
0137 
0138 void media_ctrl_open_dev(struct media_ctrl *, const char *devname);
0139 void media_ctrl_close(struct media_ctrl *);
0140 void media_ctrl_read_event(struct media_ctrl *, struct media_ctrl_event *);
0141 
0142 struct media_ctrl_key *media_ctrl_get_keys(struct media_ctrl *);
0143 int media_ctrl_get_keys_count(struct media_ctrl *);
0144 
0145 #ifdef __cplusplus
0146 }
0147 #endif