remote.h 3.54 KB
Newer Older
1
/*
Klaus Schmidinger's avatar
Klaus Schmidinger committed
2
 * remote.h: General Remote Control handling
3
 *
Klaus Schmidinger's avatar
Klaus Schmidinger committed
4
 * See the main source file 'vdr.c' for copyright information and
5 6
 * how to reach the author.
 *
7
 * $Id: remote.h 4.0 2013/12/25 12:32:44 kls Exp $
8 9 10 11 12 13
 */

#ifndef __REMOTE_H
#define __REMOTE_H

#include <stdio.h>
Klaus Schmidinger's avatar
Klaus Schmidinger committed
14
#include <termios.h>
15
#include <time.h>
Klaus Schmidinger's avatar
Klaus Schmidinger committed
16
#include "keys.h"
Klaus Schmidinger's avatar
Klaus Schmidinger committed
17
#include "thread.h"
Klaus Schmidinger's avatar
Klaus Schmidinger committed
18
#include "tools.h"
19

Klaus Schmidinger's avatar
Klaus Schmidinger committed
20
class cRemote : public cListObject {
Klaus Schmidinger's avatar
Klaus Schmidinger committed
21
private:
Klaus Schmidinger's avatar
Klaus Schmidinger committed
22
  enum { MaxKeys = 2 * MAXKEYSINMACRO };
Klaus Schmidinger's avatar
Klaus Schmidinger committed
23 24 25
  static eKeys keys[MaxKeys];
  static int in;
  static int out;
Klaus Schmidinger's avatar
Klaus Schmidinger committed
26
  static cTimeMs repeatTimeout;
Klaus Schmidinger's avatar
Klaus Schmidinger committed
27
  static cRemote *learning;
Klaus Schmidinger's avatar
Klaus Schmidinger committed
28 29 30
  static char *unknownCode;
  static cMutex mutex;
  static cCondVar keyPressed;
Klaus Schmidinger's avatar
Klaus Schmidinger committed
31
  static time_t lastActivity;
Klaus Schmidinger's avatar
Klaus Schmidinger committed
32 33
  static const char *keyMacroPlugin;
  static const char *callPlugin;
Klaus Schmidinger's avatar
Klaus Schmidinger committed
34
  static bool enabled;
Klaus Schmidinger's avatar
Klaus Schmidinger committed
35 36 37 38 39
  char *name;
protected:
  cRemote(const char *Name);
  const char *GetSetup(void);
  void PutSetup(const char *Setup);
Klaus Schmidinger's avatar
Klaus Schmidinger committed
40
  bool Put(uint64_t Code, bool Repeat = false, bool Release = false);
Klaus Schmidinger's avatar
Klaus Schmidinger committed
41
  bool Put(const char *Code, bool Repeat = false, bool Release = false);
Klaus Schmidinger's avatar
Klaus Schmidinger committed
42
public:
Klaus Schmidinger's avatar
Klaus Schmidinger committed
43
  virtual ~cRemote();
Klaus Schmidinger's avatar
Klaus Schmidinger committed
44
  virtual bool Ready(void) { return true; }
Klaus Schmidinger's avatar
Klaus Schmidinger committed
45
  virtual bool Initialize(void);
Klaus Schmidinger's avatar
Klaus Schmidinger committed
46
  const char *Name(void) { return name; }
Klaus Schmidinger's avatar
Klaus Schmidinger committed
47
  static void SetLearning(cRemote *Learning) { learning = Learning; }
Klaus Schmidinger's avatar
Klaus Schmidinger committed
48
  static bool IsLearning() { return learning != NULL; }
Klaus Schmidinger's avatar
Klaus Schmidinger committed
49 50
  static bool Enabled(void) { return enabled; }
  static void SetEnabled(bool Enabled) { enabled = Enabled; }
Klaus Schmidinger's avatar
Klaus Schmidinger committed
51
  static void Clear(void);
Klaus Schmidinger's avatar
Klaus Schmidinger committed
52
  static bool Put(eKeys Key, bool AtFront = false);
Klaus Schmidinger's avatar
Klaus Schmidinger committed
53
  static bool PutMacro(eKeys Key);
Klaus Schmidinger's avatar
Klaus Schmidinger committed
54
  static bool CallPlugin(const char *Plugin);
Klaus Schmidinger's avatar
Klaus Schmidinger committed
55 56
      ///< Initiates calling the given plugin's main menu function.
      ///< The Plugin parameter is the name of the plugin, and must be
Klaus Schmidinger's avatar
Klaus Schmidinger committed
57 58 59 60 61 62 63
      ///< a static string. Returns true if the plugin call was successfully
      ///< initiated (the actual call to the plugin's main menu function
      ///< will take place some time later, during the next execution
      ///< of VDR's main loop). If there is already a plugin call pending
      ///< false will be returned and the caller should try again later.
  static const char *GetPlugin(void);
      ///< Returns the name of the plugin that was set with a previous
Klaus Schmidinger's avatar
Klaus Schmidinger committed
64
      ///< call to PutMacro() or CallPlugin(). The internally stored pointer to the
Klaus Schmidinger's avatar
Klaus Schmidinger committed
65
      ///< plugin name will be reset to NULL by this call.
Klaus Schmidinger's avatar
Klaus Schmidinger committed
66
  static bool HasKeys(void);
Klaus Schmidinger's avatar
Klaus Schmidinger committed
67
  static eKeys Get(int WaitMs = 1000, char **UnknownCode = NULL);
Klaus Schmidinger's avatar
Klaus Schmidinger committed
68 69
  static time_t LastActivity(void) { return lastActivity; }
      ///< Absolute time when last key was delivered by Get().
Klaus Schmidinger's avatar
Klaus Schmidinger committed
70 71 72
  static void TriggerLastActivity(void);
      ///< Simulates user activity, for instance to keep the current menu open
      ///< even if no remote control key has been pressed.
Klaus Schmidinger's avatar
Klaus Schmidinger committed
73 74
  };

Klaus Schmidinger's avatar
Klaus Schmidinger committed
75
class cRemotes : public cList<cRemote> {};
Klaus Schmidinger's avatar
Klaus Schmidinger committed
76

Klaus Schmidinger's avatar
Klaus Schmidinger committed
77
extern cRemotes Remotes;
Klaus Schmidinger's avatar
Klaus Schmidinger committed
78

Klaus Schmidinger's avatar
Klaus Schmidinger committed
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
enum eKbdFunc {
  kfNone,
  kfF1 = 0x100,
  kfF2,
  kfF3,
  kfF4,
  kfF5,
  kfF6,
  kfF7,
  kfF8,
  kfF9,
  kfF10,
  kfF11,
  kfF12,
  kfUp,
  kfDown,
  kfLeft,
  kfRight,
  kfHome,
  kfEnd,
  kfPgUp,
  kfPgDown,
  kfIns,
  kfDel,
  };

Klaus Schmidinger's avatar
Klaus Schmidinger committed
105
class cKbdRemote : public cRemote, private cThread {
Klaus Schmidinger's avatar
Klaus Schmidinger committed
106
private:
Klaus Schmidinger's avatar
Klaus Schmidinger committed
107 108
  static bool kbdAvailable;
  static bool rawMode;
etobi's avatar
etobi committed
109
  bool systemIsUtf8;
Klaus Schmidinger's avatar
Klaus Schmidinger committed
110
  struct termios savedTm;
Klaus Schmidinger's avatar
Klaus Schmidinger committed
111
  virtual void Action(void);
Klaus Schmidinger's avatar
Klaus Schmidinger committed
112
  int ReadKey(void);
Klaus Schmidinger's avatar
Klaus Schmidinger committed
113 114
  uint64_t ReadKeySequence(void);
  int MapCodeToFunc(uint64_t Code);
Klaus Schmidinger's avatar
Klaus Schmidinger committed
115
  void PutKey(uint64_t Code, bool Repeat = false, bool Release = false);
Klaus Schmidinger's avatar
Klaus Schmidinger committed
116
public:
Klaus Schmidinger's avatar
Klaus Schmidinger committed
117 118
  cKbdRemote(void);
  virtual ~cKbdRemote();
Klaus Schmidinger's avatar
Klaus Schmidinger committed
119
  static bool KbdAvailable(void) { return kbdAvailable; }
Klaus Schmidinger's avatar
Klaus Schmidinger committed
120
  static uint64_t MapFuncToCode(int Func);
Klaus Schmidinger's avatar
Klaus Schmidinger committed
121
  static void SetRawMode(bool RawMode);
122 123 124
  };

#endif //__REMOTE_H