2000-02-19 13:36:48 +01:00
|
|
|
/*
|
|
|
|
* interface.c: Abstract user interface layer
|
|
|
|
*
|
2000-04-24 09:46:05 +02:00
|
|
|
* See the main source file 'vdr.c' for copyright information and
|
2000-02-19 13:36:48 +01:00
|
|
|
* how to reach the author.
|
|
|
|
*
|
2000-09-19 17:48:42 +02:00
|
|
|
* $Id: interface.c 1.19 2000/09/19 17:41:23 kls Exp $
|
2000-02-19 13:36:48 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "interface.h"
|
|
|
|
#include <unistd.h>
|
2000-09-03 11:40:00 +02:00
|
|
|
#include "eit.h"
|
2000-02-19 13:36:48 +01:00
|
|
|
#include "remote.h"
|
|
|
|
|
2000-09-03 11:40:00 +02:00
|
|
|
cEIT EIT;
|
|
|
|
|
2000-07-15 12:39:20 +02:00
|
|
|
#if defined(REMOTE_RCU)
|
|
|
|
cRcIoRCU RcIo("/dev/ttyS1");
|
|
|
|
#elif defined(REMOTE_LIRC)
|
|
|
|
cRcIoLIRC RcIo("/dev/lircd");
|
|
|
|
#else
|
|
|
|
cRcIoKBD RcIo;
|
2000-02-19 13:36:48 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
cInterface Interface;
|
|
|
|
|
|
|
|
cInterface::cInterface(void)
|
|
|
|
{
|
|
|
|
open = 0;
|
|
|
|
cols[0] = 0;
|
2000-04-22 13:51:48 +02:00
|
|
|
keyFromWait = kNone;
|
2000-09-19 17:48:42 +02:00
|
|
|
SVDRP = NULL;
|
2000-02-19 13:36:48 +01:00
|
|
|
}
|
|
|
|
|
2000-09-19 17:48:42 +02:00
|
|
|
void cInterface::Init(int SVDRPport)
|
2000-02-19 13:36:48 +01:00
|
|
|
{
|
|
|
|
RcIo.SetCode(Keys.code, Keys.address);
|
2000-09-19 17:48:42 +02:00
|
|
|
if (SVDRPport)
|
|
|
|
SVDRP = new cSVDRP(SVDRPport);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cInterface::Cleanup(void)
|
|
|
|
{
|
|
|
|
delete SVDRP;
|
2000-02-19 13:36:48 +01:00
|
|
|
}
|
|
|
|
|
2000-04-23 15:38:16 +02:00
|
|
|
void cInterface::Open(int NumCols, int NumLines)
|
2000-02-19 13:36:48 +01:00
|
|
|
{
|
2000-03-11 11:22:37 +01:00
|
|
|
if (!open++)
|
2000-05-01 16:29:46 +02:00
|
|
|
cDvbApi::PrimaryDvbApi->Open(NumCols, NumLines);
|
2000-02-19 13:36:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void cInterface::Close(void)
|
|
|
|
{
|
2000-04-15 17:38:11 +02:00
|
|
|
if (open == 1)
|
|
|
|
Clear();
|
2000-03-11 11:22:37 +01:00
|
|
|
if (!--open)
|
2000-05-01 16:29:46 +02:00
|
|
|
cDvbApi::PrimaryDvbApi->Close();
|
2000-02-19 13:36:48 +01:00
|
|
|
}
|
|
|
|
|
2000-04-23 15:38:16 +02:00
|
|
|
unsigned int cInterface::GetCh(bool Wait)
|
2000-02-19 13:36:48 +01:00
|
|
|
{
|
2000-07-15 12:39:20 +02:00
|
|
|
if (RcIo.InputAvailable(Wait)) {
|
2000-04-23 15:38:16 +02:00
|
|
|
unsigned int Command;
|
|
|
|
return RcIo.GetCommand(&Command, NULL) ? Command : 0;
|
|
|
|
}
|
|
|
|
return 0;
|
2000-02-19 13:36:48 +01:00
|
|
|
}
|
|
|
|
|
2000-04-23 15:38:16 +02:00
|
|
|
eKeys cInterface::GetKey(bool Wait)
|
2000-02-19 13:36:48 +01:00
|
|
|
{
|
2000-09-19 17:48:42 +02:00
|
|
|
if (SVDRP)
|
|
|
|
SVDRP->Process();
|
2000-04-23 15:38:16 +02:00
|
|
|
eKeys Key = keyFromWait != kNone ? keyFromWait : Keys.Get(GetCh(Wait));
|
2000-04-22 13:51:48 +02:00
|
|
|
keyFromWait = kNone;
|
|
|
|
return Key;
|
2000-02-19 13:36:48 +01:00
|
|
|
}
|
|
|
|
|
2000-09-17 09:36:50 +02:00
|
|
|
void cInterface::PutKey(eKeys Key)
|
|
|
|
{
|
|
|
|
keyFromWait = Key;
|
|
|
|
}
|
|
|
|
|
2000-04-22 13:51:48 +02:00
|
|
|
eKeys cInterface::Wait(int Seconds, bool KeepChar)
|
2000-03-11 11:22:37 +01:00
|
|
|
{
|
2000-04-22 13:51:48 +02:00
|
|
|
eKeys Key = kNone;
|
2000-09-19 17:48:42 +02:00
|
|
|
RcIo.Flush(500);
|
2000-09-18 17:22:09 +02:00
|
|
|
if (cFile::AnyFileReady(-1, Seconds * 1000))
|
|
|
|
Key = GetKey();
|
2000-04-22 13:51:48 +02:00
|
|
|
if (KeepChar)
|
|
|
|
keyFromWait = Key;
|
|
|
|
return Key;
|
2000-03-11 11:22:37 +01:00
|
|
|
}
|
|
|
|
|
2000-02-19 13:36:48 +01:00
|
|
|
void cInterface::Clear(void)
|
|
|
|
{
|
2000-03-11 11:22:37 +01:00
|
|
|
if (open)
|
2000-05-01 16:29:46 +02:00
|
|
|
cDvbApi::PrimaryDvbApi->Clear();
|
2000-03-11 11:22:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void cInterface::ClearEol(int x, int y, eDvbColor Color)
|
|
|
|
{
|
|
|
|
if (open)
|
2000-05-01 16:29:46 +02:00
|
|
|
cDvbApi::PrimaryDvbApi->ClrEol(x, y, Color);
|
2000-02-19 13:36:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void cInterface::SetCols(int *c)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < MaxCols; i++) {
|
|
|
|
cols[i] = *c++;
|
|
|
|
if (cols[i] == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-03-11 11:22:37 +01:00
|
|
|
void cInterface::Write(int x, int y, const char *s, eDvbColor FgColor, eDvbColor BgColor)
|
2000-02-19 13:36:48 +01:00
|
|
|
{
|
2000-03-11 11:22:37 +01:00
|
|
|
if (open)
|
2000-05-01 16:29:46 +02:00
|
|
|
cDvbApi::PrimaryDvbApi->Text(x, y, s, FgColor, BgColor);
|
2000-02-19 13:36:48 +01:00
|
|
|
}
|
|
|
|
|
2000-09-09 14:57:43 +02:00
|
|
|
void cInterface::WriteText(int x, int y, const char *s, eDvbColor FgColor, eDvbColor BgColor)
|
2000-02-19 13:36:48 +01:00
|
|
|
{
|
|
|
|
if (open) {
|
2000-03-11 11:22:37 +01:00
|
|
|
ClearEol(x, y, BgColor);
|
2000-02-19 13:36:48 +01:00
|
|
|
int col = 0;
|
|
|
|
for (;;) {
|
2000-03-11 11:22:37 +01:00
|
|
|
const char *t = strchr(s, '\t');
|
|
|
|
const char *p = s;
|
2000-02-19 13:36:48 +01:00
|
|
|
char buf[1000];
|
|
|
|
if (t && col < MaxCols && cols[col] > 0) {
|
|
|
|
unsigned int n = t - s;
|
|
|
|
if (n >= sizeof(buf))
|
|
|
|
n = sizeof(buf) - 1;
|
|
|
|
strncpy(buf, s, n);
|
|
|
|
buf[n] = 0;
|
|
|
|
p = buf;
|
|
|
|
s = t + 1;
|
|
|
|
}
|
2000-03-11 11:22:37 +01:00
|
|
|
Write(x, y, p, FgColor, BgColor);
|
2000-02-19 13:36:48 +01:00
|
|
|
if (p == s)
|
|
|
|
break;
|
|
|
|
x += cols[col++];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-03-11 11:22:37 +01:00
|
|
|
void cInterface::Title(const char *s)
|
|
|
|
{
|
|
|
|
int x = (MenuColumns - strlen(s)) / 2;
|
|
|
|
if (x < 0)
|
|
|
|
x = 0;
|
|
|
|
ClearEol(0, 0, clrCyan);
|
|
|
|
Write(x, 0, s, clrBlack, clrCyan);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cInterface::Status(const char *s, eDvbColor FgColor, eDvbColor BgColor)
|
|
|
|
{
|
|
|
|
ClearEol(0, -3, s ? BgColor : clrBackground);
|
|
|
|
if (s)
|
|
|
|
Write(0, -3, s, FgColor, BgColor);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cInterface::Info(const char *s)
|
2000-02-19 13:36:48 +01:00
|
|
|
{
|
|
|
|
Open();
|
2000-03-11 11:22:37 +01:00
|
|
|
isyslog(LOG_INFO, s);
|
|
|
|
Status(s, clrWhite, clrGreen);
|
|
|
|
Wait();
|
|
|
|
Status(NULL);
|
2000-02-19 13:36:48 +01:00
|
|
|
Close();
|
|
|
|
}
|
|
|
|
|
2000-03-11 11:22:37 +01:00
|
|
|
void cInterface::Error(const char *s)
|
2000-02-19 13:36:48 +01:00
|
|
|
{
|
|
|
|
Open();
|
|
|
|
esyslog(LOG_ERR, s);
|
2000-03-11 11:22:37 +01:00
|
|
|
Status(s, clrWhite, clrRed);
|
|
|
|
Wait();
|
|
|
|
Status(NULL);
|
2000-02-19 13:36:48 +01:00
|
|
|
Close();
|
|
|
|
}
|
|
|
|
|
2000-03-11 11:22:37 +01:00
|
|
|
bool cInterface::Confirm(const char *s)
|
|
|
|
{
|
|
|
|
Open();
|
|
|
|
isyslog(LOG_INFO, "confirm: %s", s);
|
|
|
|
Status(s, clrBlack, clrGreen);
|
|
|
|
bool result = Wait(10) == kOk;
|
|
|
|
Status(NULL);
|
|
|
|
Close();
|
|
|
|
isyslog(LOG_INFO, "%sconfirmed", result ? "" : "not ");
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cInterface::HelpButton(int Index, const char *Text, eDvbColor FgColor, eDvbColor BgColor)
|
|
|
|
{
|
|
|
|
if (open && Text) {
|
|
|
|
const int w = MenuColumns / 4;
|
|
|
|
int l = (w - strlen(Text)) / 2;
|
|
|
|
if (l < 0)
|
|
|
|
l = 0;
|
2000-05-01 16:29:46 +02:00
|
|
|
cDvbApi::PrimaryDvbApi->Fill(Index * w, -1, w, 1, BgColor);
|
|
|
|
cDvbApi::PrimaryDvbApi->Text(Index * w + l, -1, Text, FgColor, BgColor);
|
2000-03-11 11:22:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void cInterface::Help(const char *Red, const char *Green, const char *Yellow, const char *Blue)
|
|
|
|
{
|
|
|
|
HelpButton(0, Red, clrBlack, clrRed);
|
|
|
|
HelpButton(1, Green, clrBlack, clrGreen);
|
|
|
|
HelpButton(2, Yellow, clrBlack, clrYellow);
|
|
|
|
HelpButton(3, Blue, clrWhite, clrBlue);
|
|
|
|
}
|
|
|
|
|
2000-02-19 13:36:48 +01:00
|
|
|
void cInterface::QueryKeys(void)
|
|
|
|
{
|
|
|
|
Keys.Clear();
|
|
|
|
WriteText(1, 1, "Learning Remote Control Keys");
|
|
|
|
WriteText(1, 3, "Phase 1: Detecting RC code type");
|
|
|
|
WriteText(1, 5, "Press any key on the RC unit");
|
2000-07-15 12:39:20 +02:00
|
|
|
#ifndef REMOTE_KBD
|
2000-02-19 13:36:48 +01:00
|
|
|
unsigned char Code = 0;
|
|
|
|
unsigned short Address;
|
|
|
|
#endif
|
|
|
|
for (;;) {
|
2000-07-15 12:39:20 +02:00
|
|
|
#ifdef REMOTE_KBD
|
2000-02-19 13:36:48 +01:00
|
|
|
if (GetCh())
|
|
|
|
break;
|
|
|
|
#else
|
|
|
|
//TODO on screen display...
|
|
|
|
if (RcIo.DetectCode(&Code, &Address)) {
|
|
|
|
Keys.code = Code;
|
|
|
|
Keys.address = Address;
|
|
|
|
WriteText(1, 5, "RC code detected!");
|
|
|
|
WriteText(1, 6, "Do not press any key...");
|
2000-09-19 17:48:42 +02:00
|
|
|
RcIo.Flush(3000);
|
2000-03-11 11:22:37 +01:00
|
|
|
ClearEol(0, 5);
|
|
|
|
ClearEol(0, 6);
|
2000-02-19 13:36:48 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
WriteText(1, 3, "Phase 2: Learning specific key codes");
|
|
|
|
tKey *k = Keys.keys;
|
|
|
|
while (k->type != kNone) {
|
|
|
|
char *Prompt;
|
|
|
|
asprintf(&Prompt, "Press key for '%s'", k->name);
|
|
|
|
WriteText(1, 5, Prompt);
|
|
|
|
delete Prompt;
|
|
|
|
for (;;) {
|
|
|
|
unsigned int ch = GetCh();
|
|
|
|
if (ch != 0) {
|
|
|
|
switch (Keys.Get(ch)) {
|
|
|
|
case kUp: if (k > Keys.keys) {
|
|
|
|
k--;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case kDown: if (k > Keys.keys + 1) {
|
|
|
|
WriteText(1, 5, "Press 'Up' to confirm");
|
|
|
|
WriteText(1, 6, "Press 'Down' to continue");
|
2000-03-11 11:22:37 +01:00
|
|
|
ClearEol(0, 7);
|
|
|
|
ClearEol(0, 8);
|
2000-02-19 13:36:48 +01:00
|
|
|
for (;;) {
|
|
|
|
eKeys key = GetKey();
|
|
|
|
if (key == kUp) {
|
|
|
|
Clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (key == kDown) {
|
2000-03-11 11:22:37 +01:00
|
|
|
ClearEol(0, 6);
|
2000-02-19 13:36:48 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case kNone: k->code = ch;
|
|
|
|
k++;
|
|
|
|
break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (k > Keys.keys)
|
|
|
|
WriteText(1, 7, "(press 'Up' to go back)");
|
|
|
|
else
|
2000-03-11 11:22:37 +01:00
|
|
|
ClearEol(0, 7);
|
2000-02-19 13:36:48 +01:00
|
|
|
if (k > Keys.keys + 1)
|
|
|
|
WriteText(1, 8, "(press 'Down' to end key definition)");
|
|
|
|
else
|
2000-03-11 11:22:37 +01:00
|
|
|
ClearEol(0, 8);
|
2000-02-19 13:36:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void cInterface::LearnKeys(void)
|
|
|
|
{
|
|
|
|
isyslog(LOG_INFO, "learning keys");
|
2000-03-11 11:22:37 +01:00
|
|
|
Open();
|
2000-02-19 13:36:48 +01:00
|
|
|
for (;;) {
|
|
|
|
Clear();
|
|
|
|
QueryKeys();
|
|
|
|
Clear();
|
|
|
|
WriteText(1, 1, "Learning Remote Control Keys");
|
|
|
|
WriteText(1, 3, "Phase 3: Saving key codes");
|
|
|
|
WriteText(1, 5, "Press 'Up' to save, 'Down' to cancel");
|
|
|
|
for (;;) {
|
|
|
|
eKeys key = GetKey();
|
|
|
|
if (key == kUp) {
|
|
|
|
Keys.Save();
|
2000-03-11 11:22:37 +01:00
|
|
|
Close();
|
2000-02-19 13:36:48 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (key == kDown) {
|
|
|
|
Keys.Load();
|
2000-03-11 11:22:37 +01:00
|
|
|
Close();
|
2000-02-19 13:36:48 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-09-10 10:51:58 +02:00
|
|
|
eKeys cInterface::DisplayChannel(int Number, const char *Name, bool WithInfo)
|
2000-02-19 13:36:48 +01:00
|
|
|
{
|
2000-09-09 14:57:43 +02:00
|
|
|
// Number = 0 is used for channel group display and no EIT
|
|
|
|
if (Number)
|
|
|
|
RcIo.Number(Number);
|
2000-05-06 15:24:18 +02:00
|
|
|
if (Name && !Recording()) {
|
2000-09-10 11:23:52 +02:00
|
|
|
char *RunningTitle = "", *RunningSubtitle = "", *NextTitle = "", *NextSubtitle = "";
|
|
|
|
int Lines = 0;
|
|
|
|
if (Number && WithInfo && EIT.IsValid()) {
|
|
|
|
if (*(RunningTitle = EIT.GetRunningTitle())) Lines++;
|
|
|
|
if (*(RunningSubtitle = EIT.GetRunningSubtitle())) Lines++;
|
|
|
|
if (*(NextTitle = EIT.GetNextTitle())) Lines++;
|
|
|
|
if (*(NextSubtitle = EIT.GetNextSubtitle())) Lines++;
|
|
|
|
}
|
|
|
|
Open(MenuColumns, Lines + 1);
|
2000-09-09 14:57:43 +02:00
|
|
|
int BufSize = MenuColumns + 1;
|
|
|
|
char buffer[BufSize];
|
|
|
|
if (Number)
|
|
|
|
snprintf(buffer, BufSize, "%d %s", Number, Name ? Name : "");
|
|
|
|
else
|
|
|
|
snprintf(buffer, BufSize, "%s", Name ? Name : "");
|
2000-04-22 13:51:48 +02:00
|
|
|
Write(0, 0, buffer);
|
|
|
|
time_t t = time(NULL);
|
|
|
|
struct tm *now = localtime(&t);
|
2000-09-09 14:57:43 +02:00
|
|
|
snprintf(buffer, BufSize, "%02d:%02d", now->tm_hour, now->tm_min);
|
2000-04-22 13:51:48 +02:00
|
|
|
Write(-5, 0, buffer);
|
2000-09-10 11:23:52 +02:00
|
|
|
if (Lines > 0) {
|
2000-09-09 14:57:43 +02:00
|
|
|
const int t = 6;
|
2000-09-03 11:40:00 +02:00
|
|
|
int w = MenuColumns - t;
|
2000-09-10 11:23:52 +02:00
|
|
|
int l = 1;
|
|
|
|
if (*RunningTitle) {
|
|
|
|
Write(0, l, EIT.GetRunningTime(), clrYellow, clrBackground);
|
|
|
|
snprintf(buffer, BufSize, "%.*s", w, RunningTitle); Write(t, l, buffer, clrCyan, clrBackground);
|
|
|
|
l++;
|
|
|
|
}
|
|
|
|
if (*RunningSubtitle) {
|
|
|
|
snprintf(buffer, BufSize, "%.*s", w, RunningSubtitle); Write(t, l, buffer, clrCyan, clrBackground);
|
|
|
|
l++;
|
|
|
|
}
|
|
|
|
if (*NextTitle) {
|
|
|
|
Write(0, l, EIT.GetNextTime(), clrYellow, clrBackground);
|
|
|
|
snprintf(buffer, BufSize, "%.*s", w, NextTitle); Write(t, l, buffer, clrCyan, clrBackground);
|
|
|
|
l++;
|
|
|
|
}
|
2000-09-10 15:00:00 +02:00
|
|
|
if (*NextSubtitle) {
|
2000-09-10 11:23:52 +02:00
|
|
|
snprintf(buffer, BufSize, "%.*s", w, NextSubtitle); Write(t, l, buffer, clrCyan, clrBackground);
|
2000-09-10 15:00:00 +02:00
|
|
|
}
|
2000-09-03 11:40:00 +02:00
|
|
|
}
|
2000-09-09 14:57:43 +02:00
|
|
|
eKeys Key = Wait(5, true);
|
|
|
|
if (Key == kOk)
|
2000-04-22 13:51:48 +02:00
|
|
|
GetKey();
|
|
|
|
Close();
|
2000-09-09 14:57:43 +02:00
|
|
|
return Key;
|
2000-04-22 13:51:48 +02:00
|
|
|
}
|
2000-09-09 14:57:43 +02:00
|
|
|
return kNone;
|
2000-02-19 13:36:48 +01:00
|
|
|
}
|
2000-05-01 16:29:46 +02:00
|
|
|
|
2000-05-07 09:28:39 +02:00
|
|
|
void cInterface::DisplayRecording(int Index, bool On)
|
|
|
|
{
|
|
|
|
RcIo.SetPoints(1 << Index, On);
|
|
|
|
}
|
|
|
|
|
2000-05-01 16:29:46 +02:00
|
|
|
bool cInterface::Recording(void)
|
|
|
|
{
|
|
|
|
// This is located here because the Interface has to do with the "PrimaryDvbApi" anyway
|
|
|
|
return cDvbApi::PrimaryDvbApi->Recording();
|
|
|
|
}
|