spark: use LED display for time and volume

This is a first draft of code to display time and
volume percent on the 4 digit display on spark boxes.
This commit is contained in:
Stefan Seyfried
2012-03-28 20:20:15 +02:00
parent b8cf78a490
commit 9ab80482fa
6 changed files with 406 additions and 16 deletions

View File

@@ -29,9 +29,6 @@ endif
if BOXTYPE_TRIPLE if BOXTYPE_TRIPLE
SUBDIRS += lcddisplay SUBDIRS += lcddisplay
endif endif
if BOXTYPE_SPARK
SUBDIRS += lcddisplay
endif
if USE_TREMOR if USE_TREMOR
VORBISLIBS = @VORBISIDEC_LIBS@ VORBISLIBS = @VORBISIDEC_LIBS@
@@ -117,8 +114,11 @@ drivertool_SOURCES = drivertool.c
endif endif
if USE_STB_HAL if USE_STB_HAL
neutrino_LDADD += \ neutrino_LDADD += \
$(STB_HAL_LIB)/libstb-hal.a \ $(STB_HAL_LIB)/libstb-hal.a
if BOXTYPE_TRIPLE
neutrino_LDADD += \
$(top_builddir)/src/lcddisplay/liblcddisplay.a $(top_builddir)/src/lcddisplay/liblcddisplay.a
endif
else else
if BOXTYPE_TRIPLE if BOXTYPE_TRIPLE
neutrino_LDADD += \ neutrino_LDADD += \

View File

@@ -57,8 +57,7 @@ endif
if BOXTYPE_SPARK if BOXTYPE_SPARK
libneutrino_driver_a_SOURCES += \ libneutrino_driver_a_SOURCES += \
newclock.cpp \ spark_led.cpp
lcdd.cpp
endif endif
if USE_STB_HAL if USE_STB_HAL
INCLUDES += \ INCLUDES += \

View File

@@ -28,10 +28,6 @@
#ifndef __lcdd__ #ifndef __lcdd__
#define __lcdd__ #define __lcdd__
#ifndef LCD_UPDATE
#define LCD_UPDATE 1
#endif
#define LCDDIR_VAR "/var/share/tuxbox/neutrino/lcdd" #define LCDDIR_VAR "/var/share/tuxbox/neutrino/lcdd"
typedef enum typedef enum
@@ -83,14 +79,13 @@ typedef enum
#include <configfile.h> #include <configfile.h>
#include <pthread.h> #include <pthread.h>
#if HAVE_SPARK_HARDWARE #ifndef HAVE_SPARK_HARDWARE
#define HAVE_GENERIC_HARDWARE 1
#endif
#include <lcddisplay/fontrenderer.h> #include <lcddisplay/fontrenderer.h>
class CLCDPainter; class CLCDPainter;
class LcdFontRenderClass; class LcdFontRenderClass;
#endif
class CLCD class CLCD
{ {
public: public:
@@ -122,7 +117,7 @@ class CLCD
private: private:
#ifndef HAVE_SPARK_HARDWARE
class FontsDef class FontsDef
{ {
public: public:
@@ -170,7 +165,14 @@ class CLCD
void setlcdparameter(int dimm, int contrast, int power, int inverse, int bias); void setlcdparameter(int dimm, int contrast, int power, int inverse, int bias);
void displayUpdate(); void displayUpdate();
void showTextScreen(const std::string & big, const std::string & small, int showmode, bool perform_wakeup, bool centered = false); void showTextScreen(const std::string & big, const std::string & small, int showmode, bool perform_wakeup, bool centered = false);
#else
CLCD();
std::string menutitle;
MODES mode;
void setled(int red, int green);
static void *TimeThread(void *);
pthread_t thrTime;
#endif
public: public:
bool has_lcd; bool has_lcd;
void wake_up(); void wake_up();

328
src/driver/spark_led.cpp Normal file
View File

@@ -0,0 +1,328 @@
/*
Routines to drive the SPARK boxes' 4 digit LED display
(C) 2012 Stefan Seyfried
License: GPL
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <driver/lcdd.h>
#include <global.h>
#include <neutrino.h>
#include <fcntl.h>
#include <time.h>
#include <unistd.h>
//#include <math.h>
#include <sys/stat.h>
#include "spark_led.h"
static char volume = 0;
//static char percent = 0;
static bool power = true;
static bool muted = false;
static bool showclock = true;
static time_t last_display = 0;
static inline int dev_open()
{
int fd = open("/dev/vfd", O_RDWR);
if (fd < 0)
fprintf(stderr, "[neutrino] spark_led: open /dev/vfd: %m\n");
return fd;
}
static void display(const char *s, bool update_timestamp = true)
{
int fd = dev_open();
if (fd < 0)
return;
printf("spark_led:%s '%s'\n", __func__, s);
write(fd, s, strlen(s));
close(fd);
if (update_timestamp)
last_display = time(NULL);
}
CLCD::CLCD()
{
/* do not show menu in neutrino... */
has_lcd = false;
}
CLCD* CLCD::getInstance()
{
static CLCD* lcdd = NULL;
if (lcdd == NULL)
lcdd = new CLCD();
return lcdd;
}
void CLCD::wake_up()
{
}
void* CLCD::TimeThread(void *)
{
while(1) {
sleep(1);
CLCD::getInstance()->showTime();
}
return NULL;
}
void CLCD::init(const char *, const char *, const char *, const char *, const char *, const char *)
{
setMode(MODE_TVRADIO);
if (pthread_create (&thrTime, NULL, TimeThread, NULL) != 0 ) {
perror("[neutino] CLCD::init pthread_create(TimeThread)");
return ;
}
}
void CLCD::setlcdparameter(void)
{
}
void CLCD::showServicename(std::string, bool)
{
}
void CLCD::setled(int red, int green)
{
struct aotom_ioctl_data d;
int leds[2] = { red, green };
int i;
int fd = dev_open();
if (fd < 0)
return;
printf("spark_led:%s red:%d green:%d\n", __func__, red, green);
for (i = 0; i < 2; i++)
{
if (leds[i] == -1)
continue;
d.u.led.led_nr = i;
d.u.led.on = leds[i];
if (ioctl(fd, VFDSETLED, &d) < 0)
fprintf(stderr, "[neutrino] spark_led setled VFDSETLED: %m\n");
}
close(fd);
}
void CLCD::showTime()
{
static bool redled = false;
if (mode == MODE_SHUTDOWN)
{
setled(1, 1);
return;
}
time_t now = time(NULL);
if (power && showclock && (now - last_display) > 4)
{
char timestr[5];
struct tm *t;
static int hour = 0, minute = 0;
t = localtime(&now);
if (last_display || (hour != t->tm_hour) || (minute != t->tm_min)) {
hour = t->tm_hour;
minute = t->tm_min;
sprintf(timestr, "%02d%02d", hour, minute);
display(timestr, false);
last_display = 0;
}
}
if (CNeutrinoApp::getInstance()->recordingstatus)
{
redled = !redled;
setled(redled, -1);
}
else if (redled)
{
redled = false;
setled(redled, -1);
}
}
void CLCD::showRCLock(int)
{
}
/* update is default true, the mute code sets it to false
* to force an update => inverted logic! */
void CLCD::showVolume(const char vol, const bool update)
{
char s[5];
if (vol == volume && update)
return;
volume = vol;
/* char is unsigned, so vol is never < 0 */
if (volume > 100)
volume = 100;
if (muted)
strcpy(s, "mute");
else
sprintf(s, "%4d", volume);
display(s);
}
void CLCD::showPercentOver(const unsigned char perc, const bool /*perform_update*/, const MODES)
{
}
void CLCD::showMenuText(const int, const char *, const int, const bool)
{
if (mode != MODE_MENU_UTF8)
return;
// ShowText(ptext);
}
void CLCD::showAudioTrack(const std::string &, const std::string & title, const std::string &)
{
if (mode != MODE_AUDIO)
return;
// ShowText(title.c_str());
}
void CLCD::showAudioPlayMode(AUDIOMODES)
{
}
void CLCD::showAudioProgress(const char, bool)
{
}
void CLCD::setMode(const MODES m, const char * const)
{
mode = m;
printf("spark_led:%s %d\n", __func__, (int)m);
switch (m) {
case MODE_TVRADIO:
setled(0, 0);
showclock = true;
power = true;
showTime();
break;
case MODE_SHUTDOWN:
showclock = false;
Clear();
break;
case MODE_STANDBY:
setled(0, 1);
showclock = true;
last_display = 0;
showTime();
break;
default:
showclock = true;
showTime();
}
printf("spark_led:%s %d end\n", __func__, (int)m);
}
void CLCD::setBrightness(int)
{
}
int CLCD::getBrightness()
{
return 0;
}
void CLCD::setBrightnessStandby(int)
{
}
int CLCD::getBrightnessStandby()
{
return 0;
}
void CLCD::setPower(int)
{
}
int CLCD::getPower()
{
return 0;
}
void CLCD::togglePower(void)
{
power = !power;
if (!power)
Clear();
}
void CLCD::setMuted(bool mu)
{
printf("spark_led:%s %d\n", __func__, mu);
muted = mu;
showVolume(volume, false);
}
void CLCD::resume()
{
}
void CLCD::pause()
{
}
void CLCD::Lock()
{
}
void CLCD::Unlock()
{
}
void CLCD::Clear()
{
int fd = dev_open();
if (fd < 0)
return;
int ret = ioctl(fd, VFDDISPLAYCLR);
if(ret < 0)
perror("[neutrino] spark_led Clear() VFDDISPLAYCLR");
close(fd);
printf("spark_led:%s\n", __func__);
}
void CLCD::ShowIcon(vfd_icon, bool)
{
}
void CLCD::setEPGTitle(const std::string)
{
}

61
src/driver/spark_led.h Normal file
View File

@@ -0,0 +1,61 @@
/* ugly: this is copied from frontcontroller utility, but the driver
* does not seem to provide userspace headers... :-( */
/* this setups the mode temporarily (for one ioctl)
* to the desired mode. currently the "normal" mode
* is the compatible vfd mode
*/
struct set_mode_s {
int compat; /* 0 = compatibility mode to vfd driver; 1 = nuvoton mode */
};
struct set_brightness_s {
int level;
};
struct set_icon_s {
int icon_nr;
int on;
};
struct set_led_s {
int led_nr;
int on;
};
/* time must be given as follows:
* time[0] & time[1] = mjd ???
* time[2] = hour
* time[3] = min
* time[4] = sec
*/
struct set_standby_s {
char time[5];
};
struct set_time_s {
char time[5];
};
struct aotom_ioctl_data {
union
{
struct set_icon_s icon;
struct set_led_s led;
struct set_brightness_s brightness;
struct set_mode_s mode;
struct set_standby_s standby;
struct set_time_s time;
} u;
};
/* a strange way of defining ioctls... but anyway... */
#define VFDGETTIME 0xc0425afa
#define VFDSETTIME 0xc0425afb
#define VFDSTANDBY 0xc0425afc
#define VFDSETLED 0xc0425afe
#define VFDDISPLAYCHARS 0xc0425a00
#define VFDDISPLAYCLR 0xc0425b00
#define VFDSETMODE 0xc0425aff

View File

@@ -27,7 +27,7 @@
*/ */
#ifdef HAVE_SPARK_HARDWARE #ifdef HAVE_SPARK_HARDWARE
#define HAVE_GENERIC_HARDWARE 1 #error src/lcddisplay/lcddisplay.h must not be included on SPARK
#endif #endif
#ifdef HAVE_GENERIC_HARDWARE #ifdef HAVE_GENERIC_HARDWARE
// dummy // dummy