├── .cvsignore ├── AUTHORS ├── COPYING ├── CREDITS ├── ChangeLog ├── CodingStyle ├── INSTALL ├── Makefile.am ├── Makefile.in ├── NEWS ├── README ├── TODO ├── aclocal.m4 ├── ax_python_devel.m4 ├── bootstrap ├── cfg.c ├── cfg.h ├── config.guess ├── config.h.in ├── config.rpath ├── config.sub ├── configure ├── configure.ac ├── contrib └── picoLCD │ ├── lcd4linux.conf │ ├── lcd4linux.conf.mrtg │ ├── lcd4linux.conf.rss │ ├── lcd4linux.conf.rss.timers │ ├── mrtg.py │ └── rsstimer.py ├── curses.m4 ├── debug.c ├── debug.h ├── depcomp ├── drivers.m4 ├── drv.c ├── drv.h ├── drv_ASTUSB.c ├── drv_BWCT.c ├── drv_BeckmannEgle.c ├── drv_Crystalfontz.c ├── drv_Curses.c ├── drv_Cwlinux.c ├── drv_D4D.c ├── drv_EA232graphic.c ├── drv_EFN.c ├── drv_FW8888.c ├── drv_FutabaVFD.c ├── drv_G15.c ├── drv_GLCD2USB.c ├── drv_HD44780.c ├── drv_IRLCD.c ├── drv_Image.c ├── drv_LCD2USB.c ├── drv_LCDLinux.c ├── drv_LCDTerm.c ├── drv_LEDMatrix.c ├── drv_LPH7508.c ├── drv_LUIse.c ├── drv_LW_ABP.c ├── drv_M50530.c ├── drv_MatrixOrbital.c ├── drv_MatrixOrbitalGX.c ├── drv_MilfordInstruments.c ├── drv_NULL.c ├── drv_Newhaven.c ├── drv_Noritake.c ├── drv_PHAnderson.c ├── drv_PICGraphic.c ├── drv_Pertelian.c ├── drv_RouterBoard.c ├── drv_Sample.c ├── drv_SamsungSPF.c ├── drv_ShuttleVFD.c ├── drv_SimpleLCD.c ├── drv_T6963.c ├── drv_TeakLCM.c ├── drv_Trefon.c ├── drv_USBHUB.c ├── drv_USBLCD.c ├── drv_WincorNixdorf.c ├── drv_X11.c ├── drv_dpf.c ├── drv_generic.c ├── drv_generic.h ├── drv_generic_gpio.c ├── drv_generic_gpio.h ├── drv_generic_graphic.c ├── drv_generic_graphic.h ├── drv_generic_i2c.c ├── drv_generic_i2c.h ├── drv_generic_keypad.c ├── drv_generic_keypad.h ├── drv_generic_parport.c ├── drv_generic_parport.h ├── drv_generic_serial.c ├── drv_generic_serial.h ├── drv_generic_text.c ├── drv_generic_text.h ├── drv_mdm166a.c ├── drv_picoLCD.c ├── drv_picoLCDGraphic.c ├── drv_serdisplib.c ├── drv_st2205.c ├── drv_ula200.c ├── drv_vnc.c ├── evaluator.c ├── evaluator.h ├── event.c ├── event.h ├── font_6x8.h ├── font_6x8_bold.h ├── glcd2usb.h ├── hash.c ├── hash.h ├── indent.sh ├── install-sh ├── layout.c ├── layout.h ├── lcd4kde.conf ├── lcd4linux.c ├── lcd4linux.conf.sample ├── lcd4linux.kdelnk ├── lcd4linux.lsm ├── lcd4linux.xpm ├── lcd4linux_i2c.h ├── missing ├── mkinstalldirs ├── nph-png ├── pid.c ├── pid.h ├── plugin.c ├── plugin.h ├── plugin_apm.c ├── plugin_asterisk.c ├── plugin_button_exec.c ├── plugin_cfg.c ├── plugin_cpuinfo.c ├── plugin_dbus.c ├── plugin_diskstats.c ├── plugin_dvb.c ├── plugin_event.c ├── plugin_exec.c ├── plugin_fifo.c ├── plugin_file.c ├── plugin_gps.c ├── plugin_hddtemp.c ├── plugin_huawei.c ├── plugin_i2c_sensors.c ├── plugin_iconv.c ├── plugin_imon.c ├── plugin_isdn.c ├── plugin_kvv.c ├── plugin_loadavg.c ├── plugin_math.c ├── plugin_meminfo.c ├── plugin_mpd.c ├── plugin_mpris_dbus.c ├── plugin_mysql.c ├── plugin_netdev.c ├── plugin_netinfo.c ├── plugin_pop3.c ├── plugin_ppp.c ├── plugin_proc_stat.c ├── plugin_python.c ├── plugin_qnaplog.c ├── plugin_raspi.c ├── plugin_sample.c ├── plugin_seti.c ├── plugin_statfs.c ├── plugin_string.c ├── plugin_test.c ├── plugin_time.c ├── plugin_uname.c ├── plugin_uptime.c ├── plugin_w1retap.c ├── plugin_wireless.c ├── plugin_xmms.c ├── plugins.m4 ├── png.html ├── property.c ├── property.h ├── qprintf.c ├── qprintf.h ├── rgb.c ├── rgb.h ├── smoketest.sh ├── svn_version.h ├── svn_version.sh ├── thread.c ├── thread.h ├── timer.c ├── timer.h ├── timer_group.c ├── timer_group.h ├── tux.png ├── udelay.c ├── udelay.h ├── usbhub.conf ├── widget.c ├── widget.h ├── widget_bar.c ├── widget_bar.h ├── widget_gpo.c ├── widget_gpo.h ├── widget_icon.c ├── widget_icon.h ├── widget_image.c ├── widget_image.h ├── widget_keypad.c ├── widget_keypad.h ├── widget_text.c ├── widget_text.h ├── widget_timer.c └── widget_timer.h /.cvsignore: -------------------------------------------------------------------------------- 1 | Makefile 2 | .deps 3 | autom4te.cache 4 | config.h 5 | config.log 6 | config.status 7 | lcd4linux 8 | stamp-h1 9 | smoketest.log 10 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | # $Id$ 2 | # $URL$ 3 | 4 | Sorry, there is no AUTHORS anymore. 5 | Go to http://lcd4linux.bulix.org for a list of developers an contributors. 6 | -------------------------------------------------------------------------------- /CREDITS: -------------------------------------------------------------------------------- 1 | $Id$ 2 | $URL$ 3 | 4 | see http://lcd4linux.bulix.org for an up-to-date list of contributors! 5 | -------------------------------------------------------------------------------- /CodingStyle: -------------------------------------------------------------------------------- 1 | $Id$ 2 | $URL$ 3 | 4 | 5 | LCD4Linux Coding Style 6 | 7 | We decided to use a common coding style to make patches and diffs 8 | easier to read and apply. 9 | 10 | The style we use is based on Kernighan & Ritchie and the coding style 11 | of the linux kernel (see /usr/src/linux/Documentation/CodingStyle), 12 | with some differences: 13 | 14 | - we use a indentation level of 4 spaces (Linus prefers 8) 15 | - we allow lines up to 150 chars (Linus uses 80) 16 | 17 | The resulting indent command is: 18 | indent -kr -l150 19 | 20 | There's a script called 'indent.sh' that comes with the LCD4Linux 21 | source package; all it does is call indent with all .c and .h files. 22 | 23 | It is always a good idea to call 'indent.sh' before any SVN operation, 24 | this ensures that diffs and updates won't get mixed up because of 25 | cosmetic changes. 26 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- 1 | # $Id$ 2 | # $URL$ 3 | 4 | Sorry, there is no NEWS anymore. 5 | Go to http://lcd4linux.bulix.org for all the documentation. 6 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | # $Id$ 2 | # $URL$ 3 | 4 | Sorry, there is no README anymore. 5 | Go to http://lcd4linux.bulix.org for all the documentation. 6 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | # $Id$ 2 | # $URL$ 3 | 4 | Sorry, there is no TODO anymore. 5 | Go to http://lcd4linux.bulix.org for all the documentation. 6 | -------------------------------------------------------------------------------- /bootstrap: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # $Id$ 4 | # $URL$ 5 | 6 | # exit on errors 7 | set -e 8 | 9 | # set nicer prompt for tracing 10 | PS4="$0:\$LINENO> " 11 | set -x 12 | 13 | aclocal 14 | libtoolize --copy --force 15 | autoheader 16 | automake --add-missing --copy --foreign 17 | autoconf 18 | 19 | -------------------------------------------------------------------------------- /cfg.h: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * config file stuff 5 | * 6 | * Copyright (C) 1999, 2000 Michael Reinelt 7 | * Copyright (C) 2004, 2009 The LCD4Linux Team 8 | * 9 | * This file is part of LCD4Linux. 10 | * 11 | * LCD4Linux is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2, or (at your option) 14 | * any later version. 15 | * 16 | * LCD4Linux is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | #ifndef _CFG_H_ 28 | #define _CFG_H_ 29 | 30 | int cfg_init(const char *file); 31 | char *cfg_source(void); 32 | int cfg_cmd(const char *arg); 33 | char *cfg_list(const char *section); 34 | int cfg_rename(const char *section, const char *old, const char *new); 35 | char *cfg_get_raw(const char *section, const char *key, const char *defval); 36 | char *cfg_get(const char *section, const char *key, const char *defval); 37 | int cfg_number(const char *section, const char *key, const int defval, const int min, const int max, int *value); 38 | int cfg_exit(void); 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /contrib/picoLCD/lcd4linux.conf.mrtg: -------------------------------------------------------------------------------- 1 | Display picoLCD { 2 | Driver 'picoLCDGraphic' 3 | Size '256x64' 4 | Update 200 5 | Contrast 230 6 | Backlight 1 7 | Inverted 1 8 | Icons 1 9 | } 10 | 11 | 12 | Variables { 13 | n 0 14 | nkey 0 15 | currentImage 'http://192.168.12.113/mrtg/127.0.0.1_2-month.png' 16 | mrtgDayImageURL 'http://192.168.12.113/mrtg/127.0.0.1_2-day.png' 17 | mrtgWeekImageURL 'http://192.168.12.113/mrtg/127.0.0.1_2-week.png' 18 | #currentFile '/tmp/127.0.0.1_2-day.png' 19 | currentFile ' ' 20 | tick 500 21 | tack 100 22 | minute 60000 23 | } 24 | 25 | Widget TimerW { 26 | class 'Timer' 27 | expression n=LCD::GPI(1);nkey=n!=0?n:nkey 28 | active 1 29 | update 100 30 | } 31 | 32 | 33 | # export PYTHONPATH which should point to the scripts usually /etc/picoLCDGraphic/Scripts 34 | Widget MRTGMinute { 35 | class 'Text' 36 | expression currentFile=python::exec('mrtg', 'saveimage', currentImage) 37 | width 42 38 | #update minute 39 | update 100 40 | } 41 | 42 | Widget test { 43 | class 'Text' 44 | expression currentFile 45 | width 42 46 | #update minute 47 | update 100 48 | } 49 | 50 | # Python script will save the filename as taken from the URL above in the /etc/picoLCDGraphic/Images path 51 | # Modify mrtg.py to save in another path and also change file tag below 52 | Widget BandwidthImage { 53 | class 'Image' 54 | file currentFile 55 | visible 1 56 | inverted 0 57 | reload 1 58 | #update minute 59 | update 100 60 | #update tick 61 | } 62 | 63 | Widget GPO_kup { 64 | class 'GPO' 65 | expression currentImage=nkey==5?mrtgDayImageURL:currentImage;nkey==5?1:0 66 | update 300 67 | } 68 | 69 | Widget GPO_kdown { 70 | class 'GPO' 71 | expression currentImage=nkey==7?mrtgWeekImageURL:currentImage;nkey==7?1:0 72 | update 300 73 | } 74 | 75 | 76 | Layout picoLCD { 77 | Row1 { 78 | Col1 'MRTGMinute' 79 | } 80 | 81 | Layer 1 { 82 | X0.Y0 'BandwidthImage' 83 | } 84 | 85 | Timer1 'TimerW' 86 | GPO2 'GPO_kup' 87 | GPO3 'GPO_kdown' 88 | 89 | } 90 | 91 | Display 'picoLCD' 92 | Layout 'picoLCD' 93 | -------------------------------------------------------------------------------- /contrib/picoLCD/lcd4linux.conf.rss: -------------------------------------------------------------------------------- 1 | Display picoLCD { 2 | Driver 'picoLCDGraphic' 3 | Size '256x64' 4 | Update 200 5 | Contrast 230 6 | Backlight 1 7 | Inverted 1 8 | Icons 1 9 | } 10 | 11 | 12 | Variables { 13 | n 0 14 | nkey 0 15 | page 0 16 | title 0 17 | rss1 'http://slashdot.org/slashdot.rdf' 18 | rss2 'http://www.engadget.com/rss.xml' 19 | rss 'http://www.linuxsecurity.com/static-content/debian.rss' 20 | tick 500 21 | tack 100 22 | minute 60000 23 | } 24 | 25 | Widget TimerW { 26 | class 'Timer' 27 | expression n=LCD::GPI(1);nkey=n 28 | active 1 29 | update 100 30 | } 31 | 32 | 33 | # export PYTHONPATH which should point to the scripts usually /etc/picoLCDGraphic/Scripts 34 | 35 | Widget RSSFeedInfo { 36 | class 'Text' 37 | #expression title=1+page;param='!'.title;python::exec('rsstimer', 'getfeed', rss.param) 38 | expression rss.' page:'.page 39 | width 42 40 | align 'L' 41 | style 'bold' 42 | #update minute 43 | update 500 44 | } 45 | 46 | Widget RSSFeedTitle1 { 47 | class 'Text' 48 | expression title=1+page;param='!'.title;python::exec('rsstimer', 'getfeed', rss.param) 49 | width 42 50 | prefix '>' 51 | align 'L' 52 | #update minute 53 | update 500 54 | } 55 | 56 | 57 | 58 | Widget RSSFeedTitle2 { 59 | class 'Text' 60 | expression title=2+page;param='!'.title;python::exec('rsstimer', 'getfeed', rss.param) 61 | width 42 62 | prefix '>' 63 | align 'L' 64 | #update minute 65 | update 500 66 | } 67 | 68 | 69 | Widget RSSFeedTitle3 { 70 | class 'Text' 71 | expression title=3+page;param='!'.title;python::exec('rsstimer', 'getfeed', rss.param) 72 | width 42 73 | prefix '>' 74 | align 'L' 75 | #update minute 76 | update 500 77 | } 78 | 79 | Widget RSSFeedTitle4 { 80 | class 'Text' 81 | expression title=4+page;param='!'.title;python::exec('rsstimer', 'getfeed', rss.param) 82 | width 42 83 | prefix '>' 84 | align 'L' 85 | #update minute 86 | update 500 87 | } 88 | 89 | 90 | Widget GPO_kback { 91 | class 'GPO' 92 | expression rss=nkey==1?rss1:rss 93 | update 100 94 | } 95 | 96 | Widget GPO_khome { 97 | class 'GPO' 98 | expression rss=nkey==2?rss2:rss 99 | update 100 100 | } 101 | 102 | 103 | Widget GPO_kup { 104 | class 'GPO' 105 | expression page=nkey==5?page-1:page#;nkey==5?1:0 106 | update 100 107 | } 108 | 109 | Widget GPO_kdown { 110 | class 'GPO' 111 | expression page=nkey==7?page+1:page#;nkey==7?1:0 112 | update 100 113 | } 114 | 115 | 116 | Layout picoLCD { 117 | Row1 { 118 | Col1 'RSSFeedInfo' 119 | } 120 | Row2 { 121 | Col1 'RSSFeedTitle1' 122 | } 123 | Row4 { 124 | Col1 'RSSFeedTitle2' 125 | } 126 | Row6 { 127 | Col1 'RSSFeedTitle3' 128 | } 129 | Row8 { 130 | Col1 'RSSFeedTitle4' 131 | } 132 | 133 | Timer1 'TimerW' 134 | 135 | GPO1 'GPO_kback' 136 | GPO2 'GPO_khome' 137 | GPO3 'GPO_kup' 138 | GPO4 'GPO_kdown' 139 | 140 | } 141 | 142 | Display 'picoLCD' 143 | Layout 'picoLCD' 144 | -------------------------------------------------------------------------------- /contrib/picoLCD/lcd4linux.conf.rss.timers: -------------------------------------------------------------------------------- 1 | Display picoLCD { 2 | Driver 'picoLCDGraphic' 3 | Size '256x64' 4 | Update 200 5 | Contrast 230 6 | Backlight 1 7 | Inverted 1 8 | Icons 1 9 | } 10 | 11 | 12 | Variables { 13 | n 0 14 | nkey 0 15 | page 0 16 | t 0 17 | p ' ' 18 | r1 ' ' 19 | r2 ' ' 20 | r3 ' ' 21 | r4 ' ' 22 | rss 'http://slashdot.org/slashdot.rdf' 23 | 24 | tick 500 25 | tack 100 26 | minute 60000 27 | #rssRefresh minute 28 | rssRefresh 1000 29 | } 30 | 31 | Widget TimerW { 32 | class 'Timer' 33 | expression n=LCD::GPI(1);nkey=n!=0?n:nkey 34 | active 1 35 | update 100 36 | } 37 | 38 | Widget TimerRSS { 39 | class 'Timer' 40 | expression t=1+page;p='!'.t;r1=python::exec('rss', 'pf', rss.p);t=2+page;p='!'.t;r2=python::exec('rss', 'pf', rss.p);t=3+page;p='!'.t;r3=python::exec('rss', 'pf', rss.p);t=4+page;p='!'.t;r4=python::exec('rss', 'pf', rss.p);rssRefresh=1000 41 | active 1 42 | update rssRefresh 43 | } 44 | 45 | 46 | # export PYTHONPATH which should point to the scripts usually /etc/picoLCDGraphic/Scripts 47 | Widget RSSFeedTitle1 { 48 | class 'Text' 49 | #expression title=1+page;param='!'.title;python::exec('rss', 'parsefeed', slashdotRSS.param) 50 | expression r1 51 | width 42 52 | prefix '- ' 53 | align 'L' 54 | #update minute 55 | update 300 56 | } 57 | 58 | 59 | 60 | Widget RSSFeedTitle2 { 61 | class 'Text' 62 | expression r2 63 | width 42 64 | prefix '- ' 65 | align 'L' 66 | #update minute 67 | update 300 68 | } 69 | 70 | 71 | Widget RSSFeedTitle3 { 72 | class 'Text' 73 | expression r3 74 | width 42 75 | prefix '- ' 76 | align 'L' 77 | #update minute 78 | update 300 79 | } 80 | 81 | Widget RSSFeedTitle4 { 82 | class 'Text' 83 | expression r4 84 | width 42 85 | prefix '- ' 86 | align 'L' 87 | #update minute 88 | update 300 89 | } 90 | 91 | 92 | Widget GPO_kup { 93 | class 'GPO' 94 | expression page=nkey==5?0:page;nkey==5?1:0#;rssRefresh=nkey==5?100:rssRefresh 95 | update 100 96 | } 97 | 98 | Widget GPO_kdown { 99 | class 'GPO' 100 | expression page=nkey==7?4:page;nkey==7?1:0#;rssRefresh=nkey==7?100:rssRefresh 101 | update 100 102 | } 103 | 104 | 105 | Layout picoLCD { 106 | Row1 { 107 | Col1 'RSSFeedTitle1' 108 | } 109 | Row3 { 110 | Col1 'RSSFeedTitle2' 111 | } 112 | Row5 { 113 | Col1 'RSSFeedTitle3' 114 | } 115 | Row7 { 116 | Col1 'RSSFeedTitle4' 117 | } 118 | 119 | Timer1 'TimerW' 120 | Timer2 'TimerRSS' 121 | 122 | GPO2 'GPO_kup' 123 | GPO3 'GPO_kdown' 124 | 125 | } 126 | 127 | Display 'picoLCD' 128 | Layout 'picoLCD' 129 | -------------------------------------------------------------------------------- /contrib/picoLCD/mrtg.py: -------------------------------------------------------------------------------- 1 | import urllib 2 | import shutil 3 | 4 | download_path = "/tmp/" 5 | 6 | def saveimage(imageurl): 7 | filename = imageurl.split('/')[-1] 8 | tmpname = filename + ".tmp" 9 | try: 10 | urllib.urlretrieve(imageurl, download_path + tmpname) 11 | except IOError: 12 | return "Error downloading file" 13 | else: 14 | shutil.move(download_path + tmpname, download_path + filename) 15 | return download_path + filename 16 | 17 | 18 | #saveimage("http://www.switch.ch/network/operation/statistics/geant2-day.png") 19 | #saveimage("http://192.168.12.113/mrtg/127.0.0.1_2-day.png") 20 | 21 | 22 | -------------------------------------------------------------------------------- /contrib/picoLCD/rsstimer.py: -------------------------------------------------------------------------------- 1 | import feedparser 2 | import time 3 | import datetime 4 | import tempfile 5 | import linecache 6 | 7 | # temporary file used to store rss entries 8 | filename = "/tmp/rsstimer.tmp" 9 | # interval in seconds between rss updates 10 | updateinterval = 60 11 | 12 | # lcd4linux permits only 1 parameter passed to the function 13 | # we send the rss title id with the ! spacer 14 | def getfeed(rssfeed): 15 | print rssfeed 16 | idx = 0 17 | feed = rssfeed.split('!')[0] 18 | idx = int(rssfeed.split('!')[-1]) 19 | if (idx <= 0): idx = 1; 20 | 21 | oldfeed = fgetfeed() 22 | 23 | if (oldfeed != feed): 24 | lastupdate = 0 25 | print "Feed changed refresing" 26 | else: 27 | lastupdate = fgetseconds() 28 | 29 | if (lastupdate <= 0): 30 | saverss(feed) 31 | else: 32 | now = getseconds() 33 | delta = now - lastupdate 34 | if (delta > updateinterval): 35 | print "Last update: " + str(delta) + " seconds ago. Updating the rss entries." 36 | saverss(feed) 37 | # first line in the file is the timestamp second is the feed url 38 | output = linecache.getline(filename, idx + 2) 39 | print output 40 | return output 41 | 42 | def getseconds(): 43 | ts = datetime.datetime.now() 44 | return time.mktime(ts.timetuple()) 45 | 46 | def fgetseconds(): 47 | try: 48 | f = open(filename, "r") 49 | except IOError: 50 | print "Cannot get timestamp from file" 51 | return 0 52 | else: 53 | return float(f.readline()) 54 | 55 | def fgetfeed(): 56 | try: 57 | f = open(filename, "r") 58 | except IOError: 59 | print "Cannot get feed from file" 60 | return ' ' 61 | else: 62 | # skip first line 63 | f.readline() 64 | return f.readline().rstrip("\n") 65 | 66 | 67 | def saverss(rssfeed): 68 | linecache.clearcache() 69 | f = open(filename, "w") 70 | # save timestamp 71 | f.write(str(getseconds())) 72 | f.write("\n") 73 | # save feed url 74 | f.write(rssfeed) 75 | f.write("\n") 76 | print "Downloading the rss feed from: " + rssfeed 77 | feed = feedparser.parse(rssfeed) 78 | for entry in feed.entries: 79 | f.write(entry.title) 80 | f.write("\n") 81 | f.close 82 | print "Done" 83 | 84 | def printrss(): 85 | f = open(filename, "r") 86 | f.readline() 87 | for line in f: 88 | print line 89 | 90 | #print getfeed("http://slashdot.org/slashdot.rdf!5") 91 | print getfeed("http://www.linux.com/feed?theme=rss!1") 92 | 93 | -------------------------------------------------------------------------------- /debug.c: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * debug() and error() functions 5 | * 6 | * Copyright (C) 1999, 2000 Michael Reinelt 7 | * Copyright (C) 2004 The LCD4Linux Team 8 | * 9 | * This file is part of LCD4Linux. 10 | * 11 | * LCD4Linux is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2, or (at your option) 14 | * any later version. 15 | * 16 | * LCD4Linux is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | /* 28 | * exported functions: 29 | * 30 | * message (level, format, ...) 31 | * passes the arguments to vsprintf() and 32 | * writes the resulting string either to stdout 33 | * or syslog. 34 | * this function should not be called directly, 35 | * but the macros info(), debug() and error() 36 | * 37 | */ 38 | 39 | #include "config.h" 40 | 41 | #include 42 | #include 43 | #include 44 | #include 45 | 46 | #include "debug.h" 47 | 48 | int running_foreground = 0; 49 | int running_background = 0; 50 | 51 | int verbose_level = 0; 52 | 53 | void message(const int level, const char *format, ...) 54 | { 55 | va_list ap; 56 | char buffer[256]; 57 | static int log_open = 0; 58 | 59 | if (level > verbose_level) 60 | return; 61 | 62 | va_start(ap, format); 63 | vsnprintf(buffer, sizeof(buffer), format, ap); 64 | va_end(ap); 65 | 66 | if (!running_background) { 67 | 68 | #ifdef WITH_CURSES 69 | extern int curses_error(char *); 70 | if (!curses_error(buffer)) 71 | #endif 72 | fprintf(level ? stdout : stderr, "%s\n", buffer); 73 | } 74 | 75 | if (running_foreground) 76 | return; 77 | 78 | if (!log_open) { 79 | openlog("LCD4Linux", LOG_PID, LOG_USER); 80 | log_open = 1; 81 | } 82 | 83 | switch (level) { 84 | case 0: 85 | syslog(LOG_ERR, "%s", buffer); 86 | break; 87 | case 1: 88 | syslog(LOG_INFO, "%s", buffer); 89 | break; 90 | default: 91 | syslog(LOG_DEBUG, "%s", buffer); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /debug.h: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * debug messages 5 | * 6 | * Copyright (C) 1999, 2000 Michael Reinelt 7 | * Copyright (C) 2004 The LCD4Linux Team 8 | * 9 | * This file is part of LCD4Linux. 10 | * 11 | * LCD4Linux is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2, or (at your option) 14 | * any later version. 15 | * 16 | * LCD4Linux is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | #ifndef _DEBUG_H_ 28 | #define _DEBUG_H_ 29 | 30 | extern int running_foreground; 31 | extern int running_background; 32 | extern int verbose_level; 33 | 34 | void message(const int level, const char *format, ...) __attribute__ ((format(__printf__, 2, 3))); 35 | 36 | #define debug(args...) message (2, __FILE__ ": " args) 37 | #define info(args...) message (1, args) 38 | #define error(args...) message (0, args) 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /drv.h: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * new framework for display drivers 5 | * 6 | * Copyright (C) 1999-2003 Michael Reinelt 7 | * Copyright (C) 2004 The LCD4Linux Team 8 | * 9 | * This file is part of LCD4Linux. 10 | * 11 | * LCD4Linux is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2, or (at your option) 14 | * any later version. 15 | * 16 | * LCD4Linux is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | #ifndef _DRV_H_ 28 | #define _DRV_H_ 29 | 30 | typedef struct DRIVER { 31 | char *name; 32 | int (*list) (void); 33 | int (*init) (const char *section, const int quiet); 34 | int (*quit) (const int quiet); 35 | } DRIVER; 36 | 37 | 38 | /* output file for Raster driver 39 | * has to be defined here because it's referenced 40 | * even if the raster driver is not included! 41 | */ 42 | extern char *output; 43 | 44 | #ifdef WITH_X11 45 | /* function to handle special X11 command line parameters 46 | * has to be defined here because it's referenced 47 | * in main before dealing with normal parameters. 48 | */ 49 | void drv_X11_parseArgs(int *argc, char *arvg[]); 50 | #endif 51 | 52 | int drv_list(void); 53 | int drv_init(const char *section, const char *driver, const int quiet); 54 | int drv_quit(const int quiet); 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /drv_D4D.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jmccrohan/lcd4linux/cb69a93a4501b2a58e1f991c953b3c58d6ceeb67/drv_D4D.c -------------------------------------------------------------------------------- /drv_NULL.c: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * NULL driver (for testing) 5 | * 6 | * Copyright (C) 2004 Michael Reinelt 7 | * Copyright (C) 2004 The LCD4Linux Team 8 | * 9 | * This file is part of LCD4Linux. 10 | * 11 | * LCD4Linux is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2, or (at your option) 14 | * any later version. 15 | * 16 | * LCD4Linux is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | /* 28 | * 29 | * exported fuctions: 30 | * 31 | * struct DRIVER drv_NULL 32 | * 33 | */ 34 | 35 | #include "config.h" 36 | 37 | #include 38 | #include 39 | #include 40 | 41 | #include "debug.h" 42 | #include "cfg.h" 43 | #include "plugin.h" 44 | #include "widget.h" 45 | #include "widget_text.h" 46 | #include "widget_bar.h" 47 | #include "drv.h" 48 | #include "drv_generic_text.h" 49 | 50 | 51 | static char Name[] = "NULL"; 52 | 53 | 54 | /****************************************/ 55 | /*** hardware dependant functions ***/ 56 | /****************************************/ 57 | 58 | static void drv_NULL_write(const __attribute__ ((unused)) 59 | int row, const __attribute__ ((unused)) 60 | int col, const __attribute__ ((unused)) 61 | char *data, const __attribute__ ((unused)) 62 | int len) 63 | { 64 | /* empty */ 65 | } 66 | 67 | 68 | static void drv_NULL_defchar(const __attribute__ ((unused)) 69 | int ascii, const __attribute__ ((unused)) 70 | unsigned char *matrix) 71 | { 72 | /* empty */ 73 | } 74 | 75 | 76 | static int drv_NULL_start(const char *section) 77 | { 78 | char *s; 79 | 80 | s = cfg_get(section, "Size", "20x4"); 81 | if (s == NULL || *s == '\0') { 82 | error("%s: no '%s.Size' entry from %s", Name, section, cfg_source()); 83 | free(s); 84 | return -1; 85 | } 86 | if (sscanf(s, "%dx%d", &DCOLS, &DROWS) != 2 || DROWS < 1 || DCOLS < 1) { 87 | error("%s: bad %s.Size '%s' from %s", Name, section, s, cfg_source()); 88 | free(s); 89 | return -1; 90 | } 91 | free(s); 92 | 93 | return 0; 94 | } 95 | 96 | 97 | /****************************************/ 98 | /*** plugins ***/ 99 | /****************************************/ 100 | 101 | /* none at the moment... */ 102 | 103 | 104 | /****************************************/ 105 | /*** widget callbacks ***/ 106 | /****************************************/ 107 | 108 | /* using drv_generic_text_draw(W) */ 109 | /* using drv_generic_text_bar_draw(W) */ 110 | 111 | 112 | /****************************************/ 113 | /*** exported functions ***/ 114 | /****************************************/ 115 | 116 | 117 | /* list models */ 118 | int drv_NULL_list(void) 119 | { 120 | printf("NULL driver for testing purposes"); 121 | return 0; 122 | } 123 | 124 | 125 | /* initialize driver & display */ 126 | int drv_NULL_init(const char *section, const __attribute__ ((unused)) 127 | int quiet) 128 | { 129 | WIDGET_CLASS wc; 130 | int ret; 131 | 132 | info("%s: %s", Name, "$Rev$"); 133 | 134 | /* display preferences */ 135 | XRES = 6; /* pixel width of one char */ 136 | YRES = 8; /* pixel height of one char */ 137 | CHARS = 8; /* number of user-defineable characters */ 138 | CHAR0 = 0; /* ASCII of first user-defineable char */ 139 | GOTO_COST = 2; /* number of bytes a goto command requires */ 140 | 141 | /* real worker functions */ 142 | drv_generic_text_real_write = drv_NULL_write; 143 | drv_generic_text_real_defchar = drv_NULL_defchar; 144 | 145 | /* start display */ 146 | if ((ret = drv_NULL_start(section)) != 0) 147 | return ret; 148 | 149 | /* initialize generic text driver */ 150 | if ((ret = drv_generic_text_init(section, Name)) != 0) 151 | return ret; 152 | 153 | /* initialize generic bar driver */ 154 | if ((ret = drv_generic_text_bar_init(1)) != 0) 155 | return ret; 156 | 157 | /* add fixed chars to the bar driver */ 158 | drv_generic_text_bar_add_segment(0, 0, 255, 32); /* ASCII 32 = blank */ 159 | drv_generic_text_bar_add_segment(255, 255, 255, '*'); /* asterisk */ 160 | 161 | /* register text widget */ 162 | wc = Widget_Text; 163 | wc.draw = drv_generic_text_draw; 164 | widget_register(&wc); 165 | 166 | /* register bar widget */ 167 | wc = Widget_Bar; 168 | wc.draw = drv_generic_text_bar_draw; 169 | widget_register(&wc); 170 | 171 | /* register plugins */ 172 | /* none at the moment... */ 173 | 174 | return 0; 175 | } 176 | 177 | 178 | /* close driver & display */ 179 | int drv_NULL_quit(const __attribute__ ((unused)) 180 | int quiet) 181 | { 182 | 183 | info("%s: shutting down.", Name); 184 | drv_generic_text_quit(); 185 | 186 | return (0); 187 | } 188 | 189 | 190 | DRIVER drv_NULL = { 191 | .name = Name, 192 | .list = drv_NULL_list, 193 | .init = drv_NULL_init, 194 | .quit = drv_NULL_quit, 195 | }; 196 | -------------------------------------------------------------------------------- /drv_generic.c: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * generic driver helper 5 | * 6 | * Copyright (C) 2006 Michael Reinelt 7 | * Copyright (C) 2006 The LCD4Linux Team 8 | * 9 | * This file is part of LCD4Linux. 10 | * 11 | * LCD4Linux is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2, or (at your option) 14 | * any later version. 15 | * 16 | * LCD4Linux is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | /* 28 | * 29 | * exported functions: 30 | * 31 | * drv_generic_init (void) 32 | * initializes generic stuff and registers plugins 33 | * 34 | */ 35 | 36 | 37 | #include "config.h" 38 | 39 | #include 40 | #include 41 | #include 42 | 43 | #include "debug.h" 44 | #include "plugin.h" 45 | #include "drv_generic.h" 46 | 47 | #ifdef WITH_DMALLOC 48 | #include 49 | #endif 50 | 51 | /* these values are chars (text displays) or pixels (graphic displays) */ 52 | 53 | int LROWS = 0; /* layout size: rows */ 54 | int LCOLS = 0; /* layout size: columns */ 55 | 56 | int DROWS = 4; /* display size: rows */ 57 | int DCOLS = 20; /* display size: columns */ 58 | 59 | int XRES = 6; /* pixel widtht of one char */ 60 | int YRES = 8; /* pixel height of one char */ 61 | 62 | 63 | void (*drv_generic_blit) () = NULL; 64 | 65 | 66 | static void my_drows(RESULT * result) 67 | { 68 | double value = DROWS; 69 | SetResult(&result, R_NUMBER, &value); 70 | } 71 | 72 | static void my_dcols(RESULT * result) 73 | { 74 | double value = DCOLS; 75 | SetResult(&result, R_NUMBER, &value); 76 | } 77 | 78 | static void my_xres(RESULT * result) 79 | { 80 | double value = XRES; 81 | SetResult(&result, R_NUMBER, &value); 82 | } 83 | 84 | static void my_yres(RESULT * result) 85 | { 86 | double value = YRES; 87 | SetResult(&result, R_NUMBER, &value); 88 | } 89 | 90 | static void my_lrows(RESULT * result) 91 | { 92 | double value = LROWS; 93 | SetResult(&result, R_NUMBER, &value); 94 | } 95 | 96 | static void my_lcols(RESULT * result) 97 | { 98 | double value = LCOLS; 99 | SetResult(&result, R_NUMBER, &value); 100 | } 101 | 102 | int drv_generic_init(void) 103 | { 104 | 105 | AddFunction("LCD::height", 0, my_drows); 106 | AddFunction("LCD::width", 0, my_dcols); 107 | 108 | AddFunction("LCD::xres", 0, my_xres); 109 | AddFunction("LCD::yres", 0, my_yres); 110 | 111 | AddFunction("Layout::height", 0, my_lrows); 112 | AddFunction("Layout::width", 0, my_lcols); 113 | 114 | return 0; 115 | } 116 | -------------------------------------------------------------------------------- /drv_generic.h: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * generic driver helper 5 | * 6 | * Copyright (C) 2006 Michael Reinelt 7 | * Copyright (C) 2006 The LCD4Linux Team 8 | * 9 | * This file is part of LCD4Linux. 10 | * 11 | * LCD4Linux is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2, or (at your option) 14 | * any later version. 15 | * 16 | * LCD4Linux is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | 28 | #ifndef _DRV_GENERIC_H_ 29 | #define _DRV_GENERIC_H_ 30 | 31 | /* these values are chars (text displays) or pixels (graphic displays) */ 32 | 33 | extern int LROWS, LCOLS; /* layout size */ 34 | extern int DROWS, DCOLS; /* display size */ 35 | 36 | extern int XRES, YRES; /* pixel width/height of one char */ 37 | 38 | /* these function must be implemented by the generic driver */ 39 | extern void (*drv_generic_blit) (const int row, const int col, const int height, const int width); 40 | 41 | int drv_generic_init(void); 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /drv_generic_gpio.h: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * generic driver helper for GPIO's 5 | * 6 | * Copyright (C) 2005 Michael Reinelt 7 | * Copyright (C) 2005 The LCD4Linux Team 8 | * 9 | * This file is part of LCD4Linux. 10 | * 11 | * LCD4Linux is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2, or (at your option) 14 | * any later version. 15 | * 16 | * LCD4Linux is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | 28 | #ifndef _DRV_GENERIC_GPO_H_ 29 | #define _DRV_GENERIC_GPO_H_ 30 | 31 | #include "widget.h" 32 | 33 | extern int GPIS; /* number of GPI's */ 34 | extern int GPOS; /* number of GPO's */ 35 | 36 | /* these function must be implemented by the real driver */ 37 | extern int (*drv_generic_gpio_real_set) (const int num, const int val); 38 | extern int (*drv_generic_gpio_real_get) (const int num); 39 | 40 | /* generic functions and widget callbacks */ 41 | int drv_generic_gpio_init(const char *section, const char *driver); 42 | int drv_generic_gpio_clear(void); 43 | int drv_generic_gpio_get(const int num); 44 | int drv_generic_gpio_draw(WIDGET * W); 45 | int drv_generic_gpio_quit(void); 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /drv_generic_graphic.h: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * generic driver helper for graphic displays 5 | * 6 | * Copyright (C) 1999, 2000 Michael Reinelt 7 | * Copyright (C) 2004 The LCD4Linux Team 8 | * 9 | * This file is part of LCD4Linux. 10 | * 11 | * LCD4Linux is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2, or (at your option) 14 | * any later version. 15 | * 16 | * LCD4Linux is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | 28 | #ifndef _DRV_GENERIC_GRAPHIC_H_ 29 | #define _DRV_GENERIC_GRAPHIC_H_ 30 | 31 | #include "drv_generic.h" 32 | #include "widget.h" 33 | #include "rgb.h" 34 | 35 | extern RGBA FG_COL; /* foreground color */ 36 | extern RGBA BG_COL; /* background color */ 37 | extern RGBA BL_COL; /* backlight color */ 38 | extern RGBA NO_COL; /* no color (completely transparent) */ 39 | 40 | /* these functions must be implemented by the real driver */ 41 | extern void (*drv_generic_graphic_real_blit) (const int row, const int col, const int height, const int width); 42 | 43 | /* helper function to get pixel color or gray value */ 44 | extern RGBA drv_generic_graphic_rgb(const int row, const int col); 45 | extern unsigned char drv_generic_graphic_gray(const int row, const int col); 46 | extern unsigned char drv_generic_graphic_black(const int row, const int col); 47 | 48 | 49 | /* generic functions and widget callbacks */ 50 | int drv_generic_graphic_init(const char *section, const char *driver); 51 | int drv_generic_graphic_clear(void); 52 | int drv_generic_graphic_greet(const char *msg1, const char *msg2); 53 | int drv_generic_graphic_draw(WIDGET * W); 54 | int drv_generic_graphic_icon_draw(WIDGET * W); 55 | int drv_generic_graphic_bar_draw(WIDGET * W); 56 | int drv_generic_graphic_quit(void); 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /drv_generic_i2c.h: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * generic driver helper for i2c displays 5 | * 6 | * Copyright (C) 2005 Luis Correia 7 | * Copyright (C) 2005 The LCD4Linux Team 8 | * 9 | * This file is part of LCD4Linux. 10 | * 11 | * LCD4Linux is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2, or (at your option) 14 | * any later version. 15 | * 16 | * LCD4Linux is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | /* 28 | * 29 | * exported fuctions: 30 | * 31 | * int drv_generic_i2c_open (void) 32 | * reads 'Port' entry from config and opens 33 | * the i2c port 34 | * returns 0 if ok, -1 on failure 35 | * 36 | * int drv_generic_i2c_close (void) 37 | * closes i2c port 38 | * returns 0 if ok, -1 on failure 39 | * 40 | * unsigned char drv_generic_i2c_wire (char *name, char *deflt) 41 | * reads wiring for one data signal from config 42 | * returns 1< 7 | * Copyright (C) 2006 The LCD4Linux Team 8 | * 9 | * This file is part of LCD4Linux. 10 | * 11 | * LCD4Linux is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2, or (at your option) 14 | * any later version. 15 | * 16 | * LCD4Linux is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | 28 | #include "config.h" 29 | 30 | #include 31 | 32 | #include "debug.h" 33 | #include "widget.h" 34 | #include "widget_keypad.h" 35 | 36 | #include "drv_generic_keypad.h" 37 | 38 | static char *Section = NULL; 39 | static char *Driver = NULL; 40 | 41 | int (*drv_generic_keypad_real_press) () = NULL; 42 | 43 | int drv_generic_keypad_init(const char *section, const char *driver) 44 | { 45 | WIDGET_CLASS wc; 46 | 47 | Section = (char *) section; 48 | Driver = (char *) driver; 49 | 50 | /* register keypad widget */ 51 | wc = Widget_Keypad; 52 | widget_register(&wc); 53 | 54 | return 0; 55 | } 56 | 57 | int drv_generic_keypad_press(const int num) 58 | { 59 | WIDGET *w; 60 | int val = 0; 61 | 62 | if (drv_generic_keypad_real_press) 63 | val = drv_generic_keypad_real_press(num); 64 | 65 | w = widget_find(WIDGET_TYPE_KEYPAD, &val); 66 | 67 | if (w && w->class->draw) 68 | w->class->draw(w); 69 | 70 | return val; 71 | } 72 | 73 | int drv_generic_keypad_quit(void) 74 | { 75 | return 0; 76 | } 77 | -------------------------------------------------------------------------------- /drv_generic_keypad.h: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * generic driver helper for keypads 5 | * 6 | * Copyright (C) 2006 Chris Maj 7 | * Copyright (C) 2006 The LCD4Linux Team 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2, or (at your option) 12 | * any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 | * 23 | */ 24 | 25 | #ifndef _DRV_GENERIC_KEYPAD_H_ 26 | #define _DRV_GENERIC_KEYPAD_H_ 27 | 28 | #include "widget.h" 29 | 30 | /* these functions must be implemented by the real driver */ 31 | extern int (*drv_generic_keypad_real_press) (const int num); 32 | 33 | /* generic functions and widget callbacks */ 34 | int drv_generic_keypad_init(const char *section, const char *driver); 35 | int drv_generic_keypad_press(const int num); 36 | int drv_generic_keypad_quit(void); 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /drv_generic_parport.h: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * generic driver helper for parallel port displays 5 | * 6 | * Copyright (C) 1999, 2000 Michael Reinelt 7 | * Copyright (C) 2004 The LCD4Linux Team 8 | * 9 | * This file is part of LCD4Linux. 10 | * 11 | * LCD4Linux is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2, or (at your option) 14 | * any later version. 15 | * 16 | * LCD4Linux is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | /* 28 | * 29 | * exported fuctions: 30 | * 31 | * int drv_generic_parport_open (void) 32 | * reads 'Port' entry from config and opens 33 | * the parallel port 34 | * returns 0 if ok, -1 on failure 35 | * 36 | * int drv_generic_parport_close (void) 37 | * closes parallel port 38 | * returns 0 if ok, -1 on failure 39 | * 40 | * unsigned char drv_generic_parport_wire_ctrl (char *name, char *deflt) 41 | * reads wiring for one control signal from config 42 | * returns DRV_GENERIC_PARPORT_CONTROL_* or 255 on error 43 | * 44 | * unsigned char drv_generic_parport_hardwire_ctrl (char *name) 45 | * returns hardwiring for one control signal 46 | * same as above, but does not read from config, 47 | * but checks the config and emits a warning that the config 48 | * entry will be ignored 49 | * returns DRV_GENERIC_PARPORT_CONTROL_* or 255 on error 50 | * 51 | * unsigned char drv_generic_parport_wire_status (char *name, char *deflt) 52 | * reads wiring for one status signal from config 53 | * returns DRV_GENERIC_PARPORT_STATUS_* or 255 on error 54 | * 55 | * unsigned char drv_generic_parport_wire_data (char *name, char *deflt) 56 | * reads wiring for one data signal from config 57 | * returns 1< to for nanoseconds 71 | * 72 | * void drv_generic_parport_data (unsigned char value) 73 | * put data bits on DB1..DB8 74 | * 75 | * unsigned char drv_generic_parport_read (void) 76 | * reads a byte from the parallel port 77 | * 78 | * void drv_generic_parport_debug(void) 79 | * prints status of control lines 80 | * 81 | */ 82 | 83 | #ifndef _DRV_GENERIC_PARPORT_H_ 84 | #define _DRV_GENERIC_PARPORT_H_ 85 | 86 | int drv_generic_parport_open(const char *section, const char *driver); 87 | int drv_generic_parport_close(void); 88 | unsigned char drv_generic_parport_wire_ctrl(const char *name, const char *deflt); 89 | unsigned char drv_generic_parport_hardwire_ctrl(const char *name, const char *deflt); 90 | unsigned char drv_generic_parport_wire_status(const char *name, const char *deflt); 91 | unsigned char drv_generic_parport_wire_data(const char *name, const char *deflt); 92 | void drv_generic_parport_direction(const int direction); 93 | unsigned char drv_generic_parport_status(void); 94 | void drv_generic_parport_control(const unsigned char mask, const unsigned char value); 95 | void drv_generic_parport_toggle(const unsigned char bit, const int level, const unsigned long delay); 96 | void drv_generic_parport_data(const unsigned char data); 97 | unsigned char drv_generic_parport_read(void); 98 | void drv_generic_parport_debug(void); 99 | 100 | #endif 101 | -------------------------------------------------------------------------------- /drv_generic_serial.h: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * generic driver helper for serial and usbserial displays 5 | * 6 | * Copyright (C) 1999, 2000 Michael Reinelt 7 | * Copyright (C) 2004 The LCD4Linux Team 8 | * 9 | * This file is part of LCD4Linux. 10 | * 11 | * LCD4Linux is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2, or (at your option) 14 | * any later version. 15 | * 16 | * LCD4Linux is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | 28 | #ifndef _DRV_GENERIC_SERIAL_H_ 29 | #define _DRV_GENERIC_SERIAL_H_ 30 | 31 | int drv_generic_serial_open(const char *section, const char *driver, const unsigned int flags); 32 | int drv_generic_serial_open_handshake(const char *section, const char *driver, const unsigned int flags); 33 | int drv_generic_serial_poll(char *string, const int len); 34 | int drv_generic_serial_read(char *string, const int len); 35 | void drv_generic_serial_write(const char *string, const int len); 36 | void drv_generic_serial_write_rts(const char *string, const int len); 37 | int drv_generic_serial_close(void); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /drv_generic_text.h: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * generic driver helper for text-based displays 5 | * 6 | * Copyright (C) 1999, 2000 Michael Reinelt 7 | * Copyright (C) 2004 The LCD4Linux Team 8 | * 9 | * This file is part of LCD4Linux. 10 | * 11 | * LCD4Linux is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2, or (at your option) 14 | * any later version. 15 | * 16 | * LCD4Linux is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | 28 | #ifndef _DRV_GENERIC_TEXT_H_ 29 | #define _DRV_GENERIC_TEXT_H_ 30 | 31 | 32 | #include "drv_generic.h" 33 | #include "widget.h" 34 | #include "widget_bar.h" 35 | 36 | extern int CHARS, CHAR0; /* number of user-defineable characters, ASCII of first char */ 37 | extern int ICONS; /* number of user-defineable characters reserved for icons */ 38 | extern int GOTO_COST; /* number of bytes a goto command requires */ 39 | extern int INVALIDATE; /* re-send a modified userdefined char? */ 40 | 41 | /* these functions must be implemented by the real driver */ 42 | extern void (*drv_generic_text_real_write) (const int row, const int col, const char *data, const int len); 43 | extern void (*drv_generic_text_real_defchar) (const int ascii, const unsigned char *matrix); 44 | 45 | /* generic functions and widget callbacks */ 46 | int drv_generic_text_init(const char *section, const char *driver); 47 | int drv_generic_text_greet(const char *msg1, const char *msg2); 48 | int drv_generic_text_draw(WIDGET * W); 49 | int drv_generic_text_icon_init(void); 50 | int drv_generic_text_icon_draw(WIDGET * W); 51 | int drv_generic_text_bar_init(const int single_segments); 52 | void drv_generic_text_bar_add_segment(const int val1, const int val2, const DIRECTION dir, const int ascii); 53 | int drv_generic_text_bar_draw(WIDGET * W); 54 | int drv_generic_text_quit(void); 55 | 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /evaluator.h: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * expression evaluation 5 | * 6 | * Copyright (C) 2003 Michael Reinelt 7 | * Copyright (C) 2004 The LCD4Linux Team 8 | * 9 | * This file is part of LCD4Linux. 10 | * 11 | * LCD4Linux is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2, or (at your option) 14 | * any later version. 15 | * 16 | * LCD4Linux is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | 28 | #ifndef _EVALUATOR_H_ 29 | #define _EVALUATOR_H_ 30 | 31 | 32 | /* RESULT bitmask */ 33 | #define R_NUMBER 1 34 | #define R_STRING 2 35 | 36 | typedef struct { 37 | int type; 38 | int size; 39 | double number; 40 | char *string; 41 | } RESULT; 42 | 43 | /* strndup() may be not available on several platforms */ 44 | #ifndef HAVE_STRNDUP 45 | #include 46 | char *strndup(const char *source, size_t len); 47 | #endif 48 | 49 | int SetVariable(const char *name, RESULT * value); 50 | int SetVariableNumeric(const char *name, const double value); 51 | int SetVariableString(const char *name, const char *value); 52 | 53 | int AddFunction(const char *name, const int argc, void (*func) ()); 54 | 55 | void DeleteVariables(void); 56 | void DeleteFunctions(void); 57 | 58 | void DelResult(RESULT * result); 59 | RESULT *SetResult(RESULT ** result, const int type, const void *value); 60 | RESULT *CopyResult(RESULT ** result, RESULT * value); 61 | 62 | double R2N(RESULT * result); 63 | char *R2S(RESULT * result); 64 | 65 | int Compile(const char *expression, void **tree); 66 | int Eval(void *tree, RESULT * result); 67 | void DelTree(void *tree); 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /event.h: -------------------------------------------------------------------------------- 1 | /* $Id: event.h 840 2007-09-09 12:17:42Z michael $ 2 | * $URL: https://ssl.bulix.org/svn/lcd4linux/trunk/event.h $ 3 | * 4 | * generic timer handling 5 | * 6 | * Copyright (C) 2009 Ed Martin 7 | * Copyright (C) 2009 The LCD4Linux Team 8 | * 9 | * This file is part of LCD4Linux. 10 | * 11 | * LCD4Linux is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2, or (at your option) 14 | * any later version. 15 | * 16 | * LCD4Linux is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | 28 | #ifndef _EVENT_H_ 29 | #define _EVENT_H_ 30 | 31 | #include 32 | 33 | //events are identified by their file descriptor only 34 | 35 | /* 36 | * these functions allow plugins to add event hooks 37 | * (and thus break out of the main loop when sleeping) 38 | * these callbacks than then trigger named events to propagate 39 | * the event to the screen 40 | */ 41 | 42 | typedef enum { 43 | EVENT_READ = 1, 44 | EVENT_WRITE = 2, 45 | EVENT_HUP = 4, 46 | EVENT_ERR = 8 47 | } event_flags_t; 48 | 49 | 50 | int event_add(void (*callback) (event_flags_t flags, void *data), void *data, const int fd, const int read, 51 | const int write, const int active); 52 | int event_del(const int fd); 53 | int event_modify(const int fd, const int read, const int write, const int active); 54 | int event_process(const struct timespec *timeout); 55 | void event_exit(void); 56 | 57 | /* 58 | * These fuctions keep a list of the events to trigger on allowing multiple 59 | * things to trigger an event and multiple things to receive the event 60 | */ 61 | 62 | //add an event to be triggered 63 | int named_event_add(char *event, void (*callback) (void *data), void *data); 64 | //remove an event from the list of events 65 | int named_event_del(char *event, void (*callback) (void *data), void *data); 66 | int named_event_trigger(char *event); //call all calbacks for this event 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /glcd2usb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * glcd2usb.h - glcd2usb interface definitions 3 | */ 4 | 5 | #ifndef GLCD2USB_H 6 | #define GLCD2USB_H 7 | 8 | #define FLAG_SIX_BIT (1<<0) 9 | #define FLAG_VERTICAL_UNITS (1<<1) 10 | #define FLAG_BOTTOM_START (1<<2) 11 | #define FLAG_VERTICAL_INC (1<<3) 12 | #define FLAG_BACKLIGHT (1<<4) 13 | 14 | #define GLCD2USB_RID_GET_INFO 1 /* get display info */ 15 | #define GLCD2USB_RID_SET_ALLOC 2 /* allocate/free display */ 16 | #define GLCD2USB_RID_GET_BUTTONS 3 /* get state of the four buttons */ 17 | #define GLCD2USB_RID_SET_BL 4 /* set backlight brightness */ 18 | #define GLCD2USB_RID_GET_IR 5 /* get last ir message */ 19 | #define GLCD2USB_RID_WRITE 8 /* write some bitmap data to the display */ 20 | #define GLCD2USB_RID_WRITE_4 (GLCD2USB_RID_WRITE+0) 21 | #define GLCD2USB_RID_WRITE_8 (GLCD2USB_RID_WRITE+1) 22 | #define GLCD2USB_RID_WRITE_16 (GLCD2USB_RID_WRITE+2) 23 | #define GLCD2USB_RID_WRITE_32 (GLCD2USB_RID_WRITE+3) 24 | #define GLCD2USB_RID_WRITE_64 (GLCD2USB_RID_WRITE+4) 25 | #define GLCD2USB_RID_WRITE_128 (GLCD2USB_RID_WRITE+5) 26 | 27 | typedef struct { 28 | unsigned char report_id; 29 | char name[32]; 30 | unsigned short width, height; 31 | unsigned char flags; 32 | } __attribute__ ((packed)) display_info_t; 33 | 34 | #endif // GLCD2USB_H 35 | -------------------------------------------------------------------------------- /hash.h: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * hashes (associative arrays) 5 | * 6 | * Copyright (C) 2003 Michael Reinelt 7 | * Copyright (C) 2004 The LCD4Linux Team 8 | * 9 | * This file is part of LCD4Linux. 10 | * 11 | * LCD4Linux is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2, or (at your option) 14 | * any later version. 15 | * 16 | * LCD4Linux is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | #ifndef _HASH_H_ 28 | #define _HASH_H_ 29 | 30 | /* struct timeval */ 31 | #include 32 | 33 | 34 | typedef struct { 35 | int size; 36 | char *value; 37 | struct timeval timestamp; 38 | } HASH_SLOT; 39 | 40 | 41 | typedef struct { 42 | char *key; 43 | int val; 44 | } HASH_COLUMN; 45 | 46 | typedef struct { 47 | char *key; 48 | int index; 49 | int nSlot; 50 | HASH_SLOT *Slot; 51 | } HASH_ITEM; 52 | 53 | 54 | typedef struct { 55 | int sorted; 56 | struct timeval timestamp; 57 | int nItems; 58 | HASH_ITEM *Items; 59 | int nColumns; 60 | HASH_COLUMN *Columns; 61 | char *delimiter; 62 | } HASH; 63 | 64 | 65 | 66 | void hash_create(HASH * Hash); 67 | 68 | int hash_age(HASH * Hash, const char *key); 69 | 70 | void hash_set_column(HASH * Hash, const int number, const char *column); 71 | void hash_set_delimiter(HASH * Hash, const char *delimiter); 72 | 73 | char *hash_get(HASH * Hash, const char *key, const char *column); 74 | double hash_get_delta(HASH * Hash, const char *key, const char *column, const int delay); 75 | double hash_get_regex(HASH * Hash, const char *key, const char *column, const int delay); 76 | 77 | void hash_put(HASH * Hash, const char *key, const char *value); 78 | void hash_put_delta(HASH * Hash, const char *key, const char *value); 79 | 80 | void hash_destroy(HASH * Hash); 81 | 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /indent.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | # $Id$ 4 | # $URL$ 5 | 6 | 7 | # -kr Use Kernighan & Ritchie coding style. 8 | # -l120 Set maximum line length for non-comment lines to 150. 9 | # -npro Do not read ‘.indent.pro’ files. 10 | 11 | rm *.c~ *.h~ 2>/dev/null # trash "no such file or directory" warning messages 12 | indent -kr -l120 -npro *.c *.h 13 | 14 | for i in *.c *.h; do 15 | if !(diff -q $i $i~); then 16 | rm $i~ 17 | else 18 | mv $i~ $i 19 | fi 20 | done 21 | -------------------------------------------------------------------------------- /layout.h: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * new layouter framework 5 | * 6 | * Copyright (C) 2003 Michael Reinelt 7 | * Copyright (C) 2004 The LCD4Linux Team 8 | * 9 | * This file is part of LCD4Linux. 10 | * 11 | * LCD4Linux is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2, or (at your option) 14 | * any later version. 15 | * 16 | * LCD4Linux is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | #ifndef _LAYOUT_H_ 28 | #define _LAYOUT_H_ 29 | 30 | /* number of layers */ 31 | #define LAYERS 3 32 | 33 | int layout_init(const char *section); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /lcd4kde.conf: -------------------------------------------------------------------------------- 1 | Display X11 2 | size 6x5 3 | font 6x8 4 | pixel 1+0 5 | gap 1x0 6 | border 3 7 | foreground \#102000 8 | halfground \#90c000 9 | background \#a0d000 10 | 11 | Row1 "$u5l1$u5cb$u5cs$u5dr+dw$u5nr+nw$u5ii+io" 12 | Row2 "" 13 | Row3 "" 14 | Row4 "" 15 | Row5 "" 16 | 17 | Tick 100 18 | Tack 400 19 | Tau 500 20 | -------------------------------------------------------------------------------- /lcd4linux.kdelnk: -------------------------------------------------------------------------------- 1 | # KDE Config File 2 | [KDE Desktop Entry] 3 | Comment[C]=LCD4Linux 4 | SwallowExec=lcd4linux -f /etc/lcd4kde.conf 5 | SwallowTitle=XLCD4Linux 6 | BinaryPattern= 7 | Name=LCD4Linux 8 | Name[C]=LCD4Linux 9 | MimeType= 10 | Comment=LCD4Linux 11 | Exec=lcd4linux -f /etc/lcd4X11.conf 12 | Icon=lcd4linux.xpm 13 | Type=Application 14 | Terminal=0 15 | -------------------------------------------------------------------------------- /lcd4linux.lsm: -------------------------------------------------------------------------------- 1 | Begin4 2 | Title: lcd4linux 3 | Version: 0.95 4 | Entered-date: 2000-03-28 5 | Description: system and ISDN information is shown on 6 | an external display or in a X11 window. 7 | Keywords: LCD 8 | Author: michael@reinelt.co.at (Michael Reinelt) 9 | Maintained-by: michael@reinelt.co.at (Michael Reinelt) 10 | Primary-site: download.sourceforge.net /pub/sourceforge/lcd4linux 11 | 54k lcd4linux-0.95.tar.gz 12 | Alternate-site: http://lcd4linux.sourceforge.net 13 | Original-site: 14 | Platforms: 15 | Copying-policy: GPL 16 | End 17 | -------------------------------------------------------------------------------- /lcd4linux.xpm: -------------------------------------------------------------------------------- 1 | /* XPM */ 2 | 3 | /* 4 | * Copyright 1999 Michael Reinelt 5 | * Copyright 2004 The LCD4Linux Team 6 | * 7 | * This file is part of LCD4Linux. 8 | * 9 | * LCD4Linux is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2, or (at your option) 12 | * any later version. 13 | * 14 | * LCD4Linux is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 | * 23 | */ 24 | 25 | static char *lcd4linux[] = { 26 | "38 32 3 1", 27 | " c None", 28 | "# c #102000", 29 | ". c #a0d000", 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 | -------------------------------------------------------------------------------- /lcd4linux_i2c.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jmccrohan/lcd4linux/cb69a93a4501b2a58e1f991c953b3c58d6ceeb67/lcd4linux_i2c.h -------------------------------------------------------------------------------- /mkinstalldirs: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # mkinstalldirs --- make directory hierarchy 3 | 4 | scriptversion=2006-05-11.19 5 | 6 | # Original author: Noah Friedman 7 | # Created: 1993-05-16 8 | # Public domain. 9 | # 10 | # This file is maintained in Automake, please report 11 | # bugs to or send patches to 12 | # . 13 | 14 | nl=' 15 | ' 16 | IFS=" "" $nl" 17 | errstatus=0 18 | dirmode= 19 | 20 | usage="\ 21 | Usage: mkinstalldirs [-h] [--help] [--version] [-m MODE] DIR ... 22 | 23 | Create each directory DIR (with mode MODE, if specified), including all 24 | leading file name components. 25 | 26 | Report bugs to ." 27 | 28 | # process command line arguments 29 | while test $# -gt 0 ; do 30 | case $1 in 31 | -h | --help | --h*) # -h for help 32 | echo "$usage" 33 | exit $? 34 | ;; 35 | -m) # -m PERM arg 36 | shift 37 | test $# -eq 0 && { echo "$usage" 1>&2; exit 1; } 38 | dirmode=$1 39 | shift 40 | ;; 41 | --version) 42 | echo "$0 $scriptversion" 43 | exit $? 44 | ;; 45 | --) # stop option processing 46 | shift 47 | break 48 | ;; 49 | -*) # unknown option 50 | echo "$usage" 1>&2 51 | exit 1 52 | ;; 53 | *) # first non-opt arg 54 | break 55 | ;; 56 | esac 57 | done 58 | 59 | for file 60 | do 61 | if test -d "$file"; then 62 | shift 63 | else 64 | break 65 | fi 66 | done 67 | 68 | case $# in 69 | 0) exit 0 ;; 70 | esac 71 | 72 | # Solaris 8's mkdir -p isn't thread-safe. If you mkdir -p a/b and 73 | # mkdir -p a/c at the same time, both will detect that a is missing, 74 | # one will create a, then the other will try to create a and die with 75 | # a "File exists" error. This is a problem when calling mkinstalldirs 76 | # from a parallel make. We use --version in the probe to restrict 77 | # ourselves to GNU mkdir, which is thread-safe. 78 | case $dirmode in 79 | '') 80 | if mkdir -p --version . >/dev/null 2>&1 && test ! -d ./--version; then 81 | echo "mkdir -p -- $*" 82 | exec mkdir -p -- "$@" 83 | else 84 | # On NextStep and OpenStep, the `mkdir' command does not 85 | # recognize any option. It will interpret all options as 86 | # directories to create, and then abort because `.' already 87 | # exists. 88 | test -d ./-p && rmdir ./-p 89 | test -d ./--version && rmdir ./--version 90 | fi 91 | ;; 92 | *) 93 | if mkdir -m "$dirmode" -p --version . >/dev/null 2>&1 && 94 | test ! -d ./--version; then 95 | echo "mkdir -m $dirmode -p -- $*" 96 | exec mkdir -m "$dirmode" -p -- "$@" 97 | else 98 | # Clean up after NextStep and OpenStep mkdir. 99 | for d in ./-m ./-p ./--version "./$dirmode"; 100 | do 101 | test -d $d && rmdir $d 102 | done 103 | fi 104 | ;; 105 | esac 106 | 107 | for file 108 | do 109 | case $file in 110 | /*) pathcomp=/ ;; 111 | *) pathcomp= ;; 112 | esac 113 | oIFS=$IFS 114 | IFS=/ 115 | set fnord $file 116 | shift 117 | IFS=$oIFS 118 | 119 | for d 120 | do 121 | test "x$d" = x && continue 122 | 123 | pathcomp=$pathcomp$d 124 | case $pathcomp in 125 | -*) pathcomp=./$pathcomp ;; 126 | esac 127 | 128 | if test ! -d "$pathcomp"; then 129 | echo "mkdir $pathcomp" 130 | 131 | mkdir "$pathcomp" || lasterr=$? 132 | 133 | if test ! -d "$pathcomp"; then 134 | errstatus=$lasterr 135 | else 136 | if test ! -z "$dirmode"; then 137 | echo "chmod $dirmode $pathcomp" 138 | lasterr= 139 | chmod "$dirmode" "$pathcomp" || lasterr=$? 140 | 141 | if test ! -z "$lasterr"; then 142 | errstatus=$lasterr 143 | fi 144 | fi 145 | fi 146 | fi 147 | 148 | pathcomp=$pathcomp/ 149 | done 150 | done 151 | 152 | exit $errstatus 153 | 154 | # Local Variables: 155 | # mode: shell-script 156 | # sh-indentation: 2 157 | # eval: (add-hook 'write-file-hooks 'time-stamp) 158 | # time-stamp-start: "scriptversion=" 159 | # time-stamp-format: "%:y-%02m-%02d.%02H" 160 | # time-stamp-end: "$" 161 | # End: 162 | -------------------------------------------------------------------------------- /nph-png: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | use strict; 4 | use vars qw ($file $DELAY); 5 | ########## CONFIG 6 | $file = "lcd4linux"; # .png is appended 7 | $DELAY = 0; # delay in seconds 8 | # if delay is zero, file is sent when modified. 9 | ################# 10 | 11 | use CGI qw/:push -nph/; 12 | $| = 1; 13 | my ($mtime, $nmtime, $size, $nsize); 14 | (undef, undef, undef, undef, undef, undef, undef, $size, undef, 15 | $mtime) = stat "$file.png"; 16 | print multipart_init(-boundary=>'----------------here we go!'); 17 | while (1) { 18 | print multipart_start(-type=>'image/png'); 19 | undef $/; 20 | open(IN, "$file.png") or die("Can't read '$file.png'"); 21 | $_ = ; 22 | print $_; 23 | close(IN); 24 | print multipart_end; 25 | if ($DELAY) { 26 | sleep $DELAY; 27 | } 28 | else { 29 | W: while (1) { 30 | # sleep(1); 31 | (undef, undef, undef, undef, undef, undef, undef, $nsize, undef, 32 | $nmtime) = stat "$file.png"; 33 | if($mtime != $nmtime || $size != $nsize) { 34 | $mtime = $nmtime; 35 | $size = $nsize; 36 | last W; 37 | } 38 | } 39 | } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /pid.c: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * PID file handling 5 | * 6 | * Copyright (C) 1999, 2000 Michael Reinelt 7 | * 8 | * This file is part of LCD4Linux. 9 | * 10 | * LCD4Linux is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2, or (at your option) 13 | * any later version. 14 | * 15 | * LCD4Linux is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 23 | * 24 | */ 25 | 26 | /* 27 | * exported functions: 28 | * 29 | * int pid_init (const char *pidfile) 30 | * returns 0 if PID file could be successfully created 31 | * returns PID of an already running process 32 | * returns -1 in case of an error 33 | 34 | * int pid_exit (const char *pidfile) 35 | * returns 0 if PID file could be successfully deleted 36 | * otherwise returns error from unlink() call 37 | * 38 | */ 39 | 40 | 41 | #include "config.h" 42 | 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | 53 | #include "debug.h" 54 | #include "pid.h" 55 | #include "qprintf.h" 56 | 57 | #ifdef WITH_DMALLOC 58 | #include 59 | #endif 60 | 61 | 62 | int pid_init(const char *pidfile) 63 | { 64 | char tmpfile[256]; 65 | char buffer[16]; 66 | int fd, len, pid; 67 | 68 | qprintf(tmpfile, sizeof(tmpfile), "%s.%s", pidfile, "XXXXXX"); 69 | 70 | if ((fd = mkstemp(tmpfile)) == -1) { 71 | error("mkstemp(%s) failed: %s", tmpfile, strerror(errno)); 72 | return -1; 73 | } 74 | 75 | if (fchmod(fd, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) == -1) { 76 | error("fchmod(%s) failed: %s", tmpfile, strerror(errno)); 77 | close(fd); 78 | unlink(tmpfile); 79 | return -1; 80 | } 81 | 82 | qprintf(buffer, sizeof(buffer), "%d\n", (int) getpid()); 83 | len = strlen(buffer); 84 | if (write(fd, buffer, len) != len) { 85 | error("write(%s) failed: %s", tmpfile, strerror(errno)); 86 | close(fd); 87 | unlink(tmpfile); 88 | return -1; 89 | } 90 | close(fd); 91 | 92 | 93 | while (link(tmpfile, pidfile) == -1) { 94 | 95 | if (errno != EEXIST) { 96 | error("link(%s, %s) failed: %s", tmpfile, pidfile, strerror(errno)); 97 | unlink(tmpfile); 98 | return -1; 99 | } 100 | 101 | if ((fd = open(pidfile, O_RDONLY)) == -1) { 102 | if (errno == ENOENT) 103 | continue; /* pidfile disappared */ 104 | error("open(%s) failed: %s", pidfile, strerror(errno)); 105 | unlink(tmpfile); 106 | return -1; 107 | } 108 | 109 | len = read(fd, buffer, sizeof(buffer) - 1); 110 | if (len < 0) { 111 | error("read(%s) failed: %s", pidfile, strerror(errno)); 112 | unlink(tmpfile); 113 | return -1; 114 | } 115 | 116 | buffer[len] = '\0'; 117 | if (sscanf(buffer, "%d", &pid) != 1 || pid == 0) { 118 | error("scan(%s) failed.", pidfile); 119 | unlink(tmpfile); 120 | return -1; 121 | } 122 | 123 | if (pid == getpid()) { 124 | error("%s already locked by us. uh-oh...", pidfile); 125 | unlink(tmpfile); 126 | return 0; 127 | } 128 | 129 | if ((kill(pid, 0) == -1) && errno == ESRCH) { 130 | error("removing stale PID file %s", pidfile); 131 | if (unlink(pidfile) == -1 && errno != ENOENT) { 132 | error("unlink(%s) failed: %s", pidfile, strerror(errno)); 133 | unlink(tmpfile); 134 | return pid; 135 | } 136 | continue; 137 | } 138 | unlink(tmpfile); 139 | return pid; 140 | } 141 | 142 | unlink(tmpfile); 143 | return 0; 144 | } 145 | 146 | 147 | int pid_exit(const char *pidfile) 148 | { 149 | return unlink(pidfile); 150 | } 151 | -------------------------------------------------------------------------------- /pid.h: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * PID file handling 5 | * 6 | * Copyright (C) 2003 Michael Reinelt 7 | * Copyright (C) 2004 The LCD4Linux Team 8 | * 9 | * This file is part of LCD4Linux. 10 | * 11 | * LCD4Linux is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2, or (at your option) 14 | * any later version. 15 | * 16 | * LCD4Linux is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | #ifndef _PID_H_ 28 | #define _PID_H_ 29 | 30 | int pid_init(const char *pidfile); 31 | int pid_exit(const char *pidfile); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /plugin.h: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * plugin handler for the Evaluator 5 | * 6 | * Copyright (C) 2003 Michael Reinelt 7 | * Copyright (C) 2004 The LCD4Linux Team 8 | * 9 | * This file is part of LCD4Linux. 10 | * 11 | * LCD4Linux is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2, or (at your option) 14 | * any later version. 15 | * 16 | * LCD4Linux is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | #include "config.h" 28 | #include "evaluator.h" 29 | 30 | #ifndef _PLUGIN_H_ 31 | #define _PLUGIN_H_ 32 | 33 | int plugin_list(void); 34 | int plugin_init(void); 35 | void plugin_exit(void); 36 | #endif 37 | -------------------------------------------------------------------------------- /plugin_apm.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jmccrohan/lcd4linux/cb69a93a4501b2a58e1f991c953b3c58d6ceeb67/plugin_apm.c -------------------------------------------------------------------------------- /plugin_button_exec.c: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * plugin that forks and exec's once a key is pressed. the difference to the exec plugin is: this can also only be done once! 5 | * 6 | * Copyright (C) 2008, Wolfgang Henerbichler 7 | * 8 | * This file is part of LCD4Linux. 9 | * 10 | * LCD4Linux is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2, or (at your option) 13 | * any later version. 14 | * 15 | * LCD4Linux is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 23 | * 24 | */ 25 | 26 | /* 27 | * exported functions: 28 | * 29 | * int plugin_init_button_exec(void) 30 | * adds various functions 31 | * 32 | */ 33 | 34 | 35 | /* define the include files you need */ 36 | #include "config.h" 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | /* these should always be included */ 46 | #include "debug.h" 47 | #include "plugin.h" 48 | 49 | #ifdef WITH_DMALLOC 50 | #include 51 | #endif 52 | 53 | 54 | 55 | /* sample function 'button_exec' */ 56 | /* takes as many arguments as you want, first arguemnt is the command that will be called via exec, all the following are parameters you want to add to your command - you won't know what has happened after forking - no return codes available */ 57 | /* Note: all local functions should be declared 'static' */ 58 | 59 | static void my_button_exec(RESULT * result, int argc, RESULT * argv[]) 60 | { 61 | int pid; 62 | int i; 63 | int errsv; 64 | char *args[argc + 1]; 65 | char *arg; 66 | char *prog; 67 | 68 | signal(SIGCHLD, SIG_IGN); 69 | prog = R2S(argv[0]); 70 | info("%s", prog); 71 | for (i = 1; i < argc; i++) { 72 | arg = R2S(argv[i]); 73 | args[i] = arg; 74 | info("%s", arg); 75 | } 76 | args[0] = prog; 77 | args[i] = (char *) 0; 78 | pid = fork(); 79 | if (pid == 0) { /* child-process */ 80 | /* char *args[] = {"-r", "-t", "-l", (char *) 0 }; */ 81 | info("executing program"); 82 | execvp(prog, args); 83 | errsv = errno; 84 | info("executing program failed"); 85 | info("%s", strerror(errsv)); 86 | exit(0); 87 | } else if (pid == -1) { 88 | info("weird error has occurred. couldn't fork."); 89 | } else { 90 | SetResult(&result, R_STRING, "0"); 91 | } 92 | } 93 | 94 | 95 | /* plugin initialization */ 96 | /* MUST NOT be declared 'static'! */ 97 | int plugin_init_button_exec(void) 98 | { 99 | 100 | /* register all our cool functions */ 101 | /* the second parameter is the number of arguments */ 102 | /* -1 stands for variable argument list */ 103 | AddFunction("button_exec", -1, my_button_exec); 104 | return 0; 105 | } 106 | 107 | void plugin_exit_button_exec(void) 108 | { 109 | /* free any allocated memory */ 110 | /* close filedescriptors */ 111 | } 112 | -------------------------------------------------------------------------------- /plugin_cfg.c: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * plugin for config file access 5 | * 6 | * Copyright (C) 2003, 2004 Michael Reinelt 7 | * Copyright (C) 2004 The LCD4Linux Team 8 | * 9 | * This file is part of LCD4Linux. 10 | * 11 | * LCD4Linux is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2, or (at your option) 14 | * any later version. 15 | * 16 | * LCD4Linux is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | /* 28 | * exported functions: 29 | * 30 | * int plugin_init_cfg (void) 31 | * adds cfg() function for config access 32 | * initializes variables from the config file 33 | * 34 | */ 35 | 36 | 37 | #include "config.h" 38 | 39 | #include 40 | #include 41 | #include 42 | 43 | #include "debug.h" 44 | #include "evaluator.h" 45 | #include "plugin.h" 46 | #include "cfg.h" 47 | 48 | #ifdef WITH_DMALLOC 49 | #include 50 | #endif 51 | 52 | 53 | static void load_variables(void) 54 | { 55 | char *section = "Variables"; 56 | char *list, *l, *p; 57 | char *expression; 58 | void *tree; 59 | RESULT result = { 0, 0, 0, NULL }; 60 | 61 | list = cfg_list(section); 62 | l = list; 63 | while (l != NULL) { 64 | while (*l == '|') 65 | l++; 66 | if ((p = strchr(l, '|')) != NULL) 67 | *p = '\0'; 68 | if (strchr(l, '.') != NULL || strchr(l, ':') != 0) { 69 | error("ignoring variable '%s' from %s: structures not allowed", l, cfg_source()); 70 | } else { 71 | expression = cfg_get_raw(section, l, ""); 72 | if (expression != NULL && *expression != '\0') { 73 | tree = NULL; 74 | if (Compile(expression, &tree) == 0 && Eval(tree, &result) == 0) { 75 | SetVariable(l, &result); 76 | debug("Variable %s = '%s' (%g)", l, R2S(&result), R2N(&result)); 77 | DelResult(&result); 78 | } else { 79 | error("error evaluating variable '%s' from %s", list, cfg_source()); 80 | } 81 | DelTree(tree); 82 | } 83 | } 84 | l = p ? p + 1 : NULL; 85 | } 86 | free(list); 87 | 88 | } 89 | 90 | 91 | static void my_cfg(RESULT * result, const int argc, RESULT * argv[]) 92 | { 93 | int i, len; 94 | char *value; 95 | char *buffer; 96 | 97 | /* calculate key length */ 98 | len = 0; 99 | for (i = 0; i < argc; i++) { 100 | len += strlen(R2S(argv[i])) + 1; 101 | } 102 | 103 | /* allocate key buffer */ 104 | buffer = malloc(len + 1); 105 | 106 | /* prepare key buffer */ 107 | *buffer = '\0'; 108 | for (i = 0; i < argc; i++) { 109 | strcat(buffer, "."); 110 | strcat(buffer, R2S(argv[i])); 111 | } 112 | 113 | /* buffer starts with '.', so cut off first char */ 114 | value = cfg_get("", buffer + 1, ""); 115 | 116 | /* store result */ 117 | SetResult(&result, R_STRING, value); 118 | 119 | /* free buffer again */ 120 | free(buffer); 121 | 122 | free(value); 123 | } 124 | 125 | 126 | int plugin_init_cfg(void) 127 | { 128 | /* load "Variables" section from cfg */ 129 | load_variables(); 130 | 131 | /* register plugin */ 132 | AddFunction("cfg", -1, my_cfg); 133 | 134 | return 0; 135 | } 136 | 137 | void plugin_exit_cfg(void) 138 | { 139 | /* empty */ 140 | } 141 | -------------------------------------------------------------------------------- /plugin_cpuinfo.c: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * plugin for /proc/cpuinfo parsing 5 | * 6 | * Copyright (C) 2003 Michael Reinelt 7 | * Copyright (C) 2004 The LCD4Linux Team 8 | * 9 | * This file is part of LCD4Linux. 10 | * 11 | * LCD4Linux is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2, or (at your option) 14 | * any later version. 15 | * 16 | * LCD4Linux is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | /* 28 | * exported functions: 29 | * 30 | * int plugin_init_cpuinfo (void) 31 | * adds functions to access /proc/cpuinfo 32 | * 33 | */ 34 | 35 | 36 | #include "config.h" 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | 44 | #include "debug.h" 45 | #include "plugin.h" 46 | #include "hash.h" 47 | 48 | #ifdef __MAC_OS_X_VERSION_10_3 49 | #include 50 | #include 51 | #endif 52 | 53 | static HASH CPUinfo; 54 | static FILE *stream = NULL; 55 | 56 | static int parse_cpuinfo(char __attribute__ ((unused)) * oid) 57 | { 58 | int age; 59 | 60 | /* reread every second only */ 61 | age = hash_age(&CPUinfo, NULL); 62 | if (age > 0 && age <= 1000) 63 | return 0; 64 | 65 | #ifndef __MAC_OS_X_VERSION_10_3 66 | 67 | /* Linux Kernel, /proc-filesystem */ 68 | 69 | if (stream == NULL) 70 | stream = fopen("/proc/cpuinfo", "r"); 71 | if (stream == NULL) { 72 | error("fopen(/proc/cpuinfo) failed: %s", strerror(errno)); 73 | return -1; 74 | } 75 | rewind(stream); 76 | while (!feof(stream)) { 77 | char buffer[256]; 78 | char *c, *key, *val; 79 | fgets(buffer, sizeof(buffer), stream); 80 | c = strchr(buffer, ':'); 81 | if (c == NULL) 82 | continue; 83 | key = buffer; 84 | val = c + 1; 85 | /* strip leading blanks from key */ 86 | while (isspace(*key)) 87 | *key++ = '\0'; 88 | /* strip trailing blanks from key */ 89 | do 90 | *c = '\0'; 91 | while (isspace(*--c)); 92 | /* strip leading blanks from value */ 93 | while (isspace(*val)) 94 | *val++ = '\0'; 95 | /* strip trailing blanks from value */ 96 | for (c = val; *c != '\0'; c++); 97 | while (isspace(*--c)) 98 | *c = '\0'; 99 | 100 | /* add entry to hash table */ 101 | hash_put(&CPUinfo, key, val); 102 | 103 | } 104 | 105 | #else 106 | 107 | /* MACH Kernel, MacOS X */ 108 | 109 | char val_ret[256]; 110 | int *val; 111 | size_t val_len; 112 | 113 | if (sysctlbyname(oid, NULL, &val_len, NULL, 0) != 0) { 114 | error("Error %d by sysctl(%s): %s", errno, oid, strerror(errno)); 115 | return -1; 116 | } 117 | if (val_len > sizeof(val_ret)) { 118 | error("Error: Result of sysctl(%s) too big (%zd > %zd)!", oid, val_len, sizeof(val_ret)); 119 | return -1; 120 | } 121 | sysctlbyname(oid, &val_ret, &val_len, NULL, 0); 122 | if (val_len == sizeof(int)) { 123 | /* we got an integer instead of a string */ 124 | val = (int *) val_ret; 125 | snprintf(val_ret, sizeof(val_ret), "%d", *val); 126 | } 127 | hash_put(&CPUinfo, oid, val_ret); 128 | #endif 129 | 130 | return 0; 131 | } 132 | 133 | 134 | static void my_cpuinfo(RESULT * result, RESULT * arg1) 135 | { 136 | char *key, *val; 137 | 138 | key = R2S(arg1); 139 | if (parse_cpuinfo(key) < 0) { 140 | SetResult(&result, R_STRING, ""); 141 | return; 142 | } 143 | 144 | val = hash_get(&CPUinfo, key, NULL); 145 | if (val == NULL) 146 | val = ""; 147 | 148 | SetResult(&result, R_STRING, val); 149 | } 150 | 151 | 152 | int plugin_init_cpuinfo(void) 153 | { 154 | hash_create(&CPUinfo); 155 | AddFunction("cpuinfo", 1, my_cpuinfo); 156 | return 0; 157 | } 158 | 159 | void plugin_exit_cpuinfo(void) 160 | { 161 | if (stream != NULL) { 162 | fclose(stream); 163 | stream = NULL; 164 | } 165 | hash_destroy(&CPUinfo); 166 | } 167 | -------------------------------------------------------------------------------- /plugin_diskstats.c: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * plugin for /proc/diskstats parsing 5 | * 6 | * Copyright (C) 2003 Michael Reinelt 7 | * Copyright (C) 2004 The LCD4Linux Team 8 | * 9 | * This file is part of LCD4Linux. 10 | * 11 | * LCD4Linux is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2, or (at your option) 14 | * any later version. 15 | * 16 | * LCD4Linux is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | /* 28 | * exported functions: 29 | * 30 | * int plugin_init_diskstats (void) 31 | * adds functions to access /proc/stat 32 | * 33 | */ 34 | 35 | 36 | #include "config.h" 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | 44 | #include "debug.h" 45 | #include "plugin.h" 46 | #include "hash.h" 47 | 48 | 49 | static HASH DISKSTATS; 50 | static FILE *stream = NULL; 51 | 52 | 53 | static int parse_diskstats(void) 54 | { 55 | int age; 56 | 57 | /* reread every 10 msec only */ 58 | age = hash_age(&DISKSTATS, NULL); 59 | if (age > 0 && age <= 10) 60 | return 0; 61 | 62 | if (stream == NULL) 63 | stream = fopen("/proc/diskstats", "r"); 64 | if (stream == NULL) { 65 | error("fopen(/proc/diskstats) failed: %s", strerror(errno)); 66 | return -1; 67 | } 68 | 69 | rewind(stream); 70 | 71 | while (!feof(stream)) { 72 | char buffer[1024]; 73 | char dev[64]; 74 | char *beg, *end; 75 | unsigned int num, len; 76 | 77 | if (fgets(buffer, sizeof(buffer), stream) == NULL) 78 | break; 79 | 80 | /* fetch device name (3rd column) as key */ 81 | num = 0; 82 | beg = buffer; 83 | end = beg; 84 | while (*beg) { 85 | while (*beg == ' ') 86 | beg++; 87 | end = beg + 1; 88 | while (*end && *end != ' ') 89 | end++; 90 | if (num++ == 2) 91 | break; 92 | beg = end ? end + 1 : NULL; 93 | } 94 | len = end ? (unsigned) (end - beg) : strlen(beg); 95 | 96 | if (len >= sizeof(dev)) 97 | len = sizeof(dev) - 1; 98 | strncpy(dev, beg, len); 99 | dev[len] = '\0'; 100 | 101 | hash_put_delta(&DISKSTATS, dev, buffer); 102 | 103 | } 104 | return 0; 105 | } 106 | 107 | 108 | static void my_diskstats(RESULT * result, RESULT * arg1, RESULT * arg2, RESULT * arg3) 109 | { 110 | char *dev, *key; 111 | int delay; 112 | double value; 113 | 114 | if (parse_diskstats() < 0) { 115 | SetResult(&result, R_STRING, ""); 116 | return; 117 | } 118 | 119 | dev = R2S(arg1); 120 | key = R2S(arg2); 121 | delay = R2N(arg3); 122 | 123 | value = hash_get_regex(&DISKSTATS, dev, key, delay); 124 | 125 | SetResult(&result, R_NUMBER, &value); 126 | } 127 | 128 | 129 | int plugin_init_diskstats(void) 130 | { 131 | int i; 132 | char *header[] = { "major", "minor", "name", 133 | "reads", "read_merges", "read_sectors", "read_ticks", 134 | "writes", "write_merges", "write_sectors", "write_ticks", 135 | "in_flight", "io_ticks", "time_in_queue", "" 136 | }; 137 | 138 | hash_create(&DISKSTATS); 139 | hash_set_delimiter(&DISKSTATS, " \n"); 140 | for (i = 0; *header[i] != '\0'; i++) { 141 | hash_set_column(&DISKSTATS, i, header[i]); 142 | } 143 | 144 | AddFunction("diskstats", 3, my_diskstats); 145 | return 0; 146 | } 147 | 148 | void plugin_exit_diskstats(void) 149 | { 150 | if (stream != NULL) { 151 | fclose(stream); 152 | stream = NULL; 153 | } 154 | hash_destroy(&DISKSTATS); 155 | } 156 | -------------------------------------------------------------------------------- /plugin_dvb.c: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * plugin for DVB status 5 | * 6 | * Copyright (C) 2003 Michael Reinelt 7 | * Copyright (C) 2004 The LCD4Linux Team 8 | * 9 | * This file is part of LCD4Linux. 10 | * 11 | * LCD4Linux is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2, or (at your option) 14 | * any later version. 15 | * 16 | * LCD4Linux is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | /* 28 | * exported functions: 29 | * 30 | * int plugin_init_dvb (void) 31 | * adds dvb() function 32 | * 33 | */ 34 | 35 | #include "config.h" 36 | 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | 47 | #ifdef HAVE_LINUX_DVB_FRONTEND_H 48 | #include 49 | #else 50 | #warning linux/dvb/frontend.h not found: using hardcoded ioctl definitions 51 | #define FE_READ_BER _IOR('o', 70, __u32) 52 | #define FE_READ_SIGNAL_STRENGTH _IOR('o', 71, __u16) 53 | #define FE_READ_SNR _IOR('o', 72, __u16) 54 | #define FE_READ_UNCORRECTED_BLOCKS _IOR('o', 73, __u32) 55 | #endif 56 | 57 | #include "debug.h" 58 | #include "plugin.h" 59 | #include "hash.h" 60 | 61 | static char *frontend = "/dev/dvb/adapter0/frontend0"; 62 | 63 | static HASH DVB; 64 | 65 | static int get_dvb_stats(void) 66 | { 67 | static int ioc_disable = 0; 68 | 69 | int age; 70 | int fd; 71 | unsigned short snr, sig; 72 | unsigned long ber, ucb; 73 | char val[16]; 74 | 75 | /* reread every 1000 msec only */ 76 | age = hash_age(&DVB, NULL); 77 | if (age > 0 && age <= 1000) 78 | return 0; 79 | 80 | /* open frontend */ 81 | fd = open(frontend, O_RDONLY); 82 | if (fd == -1) { 83 | error("open(%s) failed: %s", frontend, strerror(errno)); 84 | return -1; 85 | } 86 | 87 | sig = 0; 88 | if ((ioc_disable & 0x01) == 0 && ioctl(fd, FE_READ_SIGNAL_STRENGTH, &sig) != 0) { 89 | error("ioctl(FE_READ_SIGNAL_STRENGTH) failed: %s", strerror(errno)); 90 | if (errno == ENOSYS) { 91 | ioc_disable |= 0x01; 92 | error("ioctl(FE_READ_SIGNAL_STRENGTH) disabled."); 93 | } 94 | } 95 | 96 | snr = 0; 97 | if ((ioc_disable & 0x02) == 0 && ioctl(fd, FE_READ_SNR, &snr) != 0) { 98 | error("ioctl(FE_READ_SNR) failed: %s", strerror(errno)); 99 | if (errno == ENOSYS) { 100 | ioc_disable |= 0x02; 101 | error("ioctl(FE_READ_SNR) disabled."); 102 | } 103 | } 104 | 105 | ber = 0; 106 | if ((ioc_disable & 0x04) == 0 && ioctl(fd, FE_READ_BER, &ber) != 0) { 107 | error("ioctl(FE_READ_BER) failed: %s", strerror(errno)); 108 | if (errno == ENOSYS) { 109 | ioc_disable |= 0x04; 110 | error("ioctl(FE_READ_BER) disabled."); 111 | } 112 | } 113 | 114 | ucb = 0; 115 | if ((ioc_disable & 0x08) == 0 && ioctl(fd, FE_READ_UNCORRECTED_BLOCKS, &ucb) != 0) { 116 | error("ioctl(FE_READ_UNCORRECTED_BLOCKS) failed: %s", strerror(errno)); 117 | if (errno == ENOSYS) { 118 | ioc_disable |= 0x08; 119 | error("ioctl(FE_READ_UNCORRECTED_BLOCKS) disabled."); 120 | } 121 | } 122 | 123 | close(fd); 124 | 125 | snprintf(val, sizeof(val), "%f", sig / 65535.0); 126 | hash_put(&DVB, "signal_strength", val); 127 | 128 | snprintf(val, sizeof(val), "%f", snr / 65535.0); 129 | hash_put(&DVB, "snr", val); 130 | 131 | snprintf(val, sizeof(val), "%lu", ber); 132 | hash_put(&DVB, "ber", val); 133 | 134 | snprintf(val, sizeof(val), "%lu", ucb); 135 | hash_put(&DVB, "uncorrected_blocks", val); 136 | 137 | return 0; 138 | } 139 | 140 | 141 | static void my_dvb(RESULT * result, RESULT * arg1) 142 | { 143 | char *val; 144 | 145 | if (get_dvb_stats() < 0) { 146 | SetResult(&result, R_STRING, ""); 147 | return; 148 | } 149 | 150 | val = hash_get(&DVB, R2S(arg1), NULL); 151 | if (val == NULL) 152 | val = ""; 153 | 154 | SetResult(&result, R_STRING, val); 155 | } 156 | 157 | 158 | int plugin_init_dvb(void) 159 | { 160 | hash_create(&DVB); 161 | AddFunction("dvb", 1, my_dvb); 162 | return 0; 163 | } 164 | 165 | 166 | void plugin_exit_dvb(void) 167 | { 168 | hash_destroy(&DVB); 169 | } 170 | -------------------------------------------------------------------------------- /plugin_event.c: -------------------------------------------------------------------------------- 1 | /* $Id: plugin_event.c -1 $ 2 | * $URL: https://ssl.bulix.org/svn/lcd4linux/trunk/plugin_event.c $ 3 | * 4 | * plugin template 5 | * 6 | * Copyright (C) 2003 Ed Martin 7 | * Copyright (C) 2004, 2005, 2006, 2007, 2008 The LCD4Linux Team 8 | * 9 | * This file is part of LCD4Linux. 10 | * 11 | * LCD4Linux is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2, or (at your option) 14 | * any later version. 15 | * 16 | * LCD4Linux is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | /* 28 | * exported functions: 29 | * 30 | * int plugin_init_event (void) 31 | * adds various functions 32 | * 33 | */ 34 | 35 | 36 | /* define the include files you need */ 37 | #include "config.h" 38 | 39 | #include 40 | #include 41 | #include 42 | 43 | /* these should always be included */ 44 | #include "debug.h" 45 | #include "plugin.h" 46 | #include "event.h" 47 | 48 | #ifdef WITH_DMALLOC 49 | #include 50 | #endif 51 | 52 | 53 | 54 | /* function 'trigger' */ 55 | /* takes one argument, a string */ 56 | /* triggers the event */ 57 | 58 | static void my_trigger(RESULT * result, RESULT * arg1) 59 | { 60 | char *param; 61 | 62 | /* Get Parameter */ 63 | /* R2N stands for 'Result to Number' */ 64 | param = R2S(arg1); 65 | named_event_trigger(param); 66 | 67 | char *value = ""; 68 | 69 | /* store result */ 70 | /* when called with R_NUMBER, it assumes the */ 71 | /* next parameter to be a pointer to double */ 72 | SetResult(&result, R_NUMBER, &value); 73 | } 74 | 75 | 76 | /* plugin initialization */ 77 | /* MUST NOT be declared 'static'! */ 78 | int plugin_init_event(void) 79 | { 80 | 81 | /* register all our cool functions */ 82 | /* the second parameter is the number of arguments */ 83 | /* -1 stands for variable argument list */ 84 | AddFunction("event::trigger", 1, my_trigger); 85 | 86 | 87 | return 0; 88 | } 89 | 90 | void plugin_exit_event(void) 91 | { 92 | /* free any allocated memory */ 93 | /* close filedescriptors */ 94 | } 95 | -------------------------------------------------------------------------------- /plugin_exec.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jmccrohan/lcd4linux/cb69a93a4501b2a58e1f991c953b3c58d6ceeb67/plugin_exec.c -------------------------------------------------------------------------------- /plugin_file.c: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * plugin to perform simple file operations 5 | * 6 | * Copyright (C) 2006 Chris Maj 7 | * Copyright (C) 2006 The LCD4Linux Team 8 | * 9 | * This file is part of LCD4Linux. 10 | * 11 | * LCD4Linux is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2, or (at your option) 14 | * any later version. 15 | * 16 | * LCD4Linux is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | /* 28 | * exported functions: 29 | * 30 | * int plugin_init_file (void) 31 | * adds various functions 32 | * 33 | */ 34 | 35 | 36 | /* define the include files you need */ 37 | #include "config.h" 38 | 39 | #include 40 | #include 41 | 42 | /* these should always be included */ 43 | #include "debug.h" 44 | #include "plugin.h" 45 | 46 | #ifdef WITH_DMALLOC 47 | #include 48 | #endif 49 | 50 | 51 | /* function 'readline' */ 52 | /* takes two arguments, file name and line number */ 53 | /* returns text of that line */ 54 | 55 | static void my_readline(RESULT * result, RESULT * arg1, RESULT * arg2) 56 | { 57 | char value[80], val2[80]; 58 | FILE *fp; 59 | int reqline, i, size; 60 | 61 | reqline = R2N(arg2); 62 | fp = fopen(R2S(arg1), "r"); 63 | if (!fp) { 64 | info("readline couldn't open file '%s'", R2S(arg1)); 65 | value[0] = '\0'; 66 | } else { 67 | i = 0; 68 | while (!feof(fp) && i++ < reqline) { 69 | fgets(val2, sizeof(val2), fp); 70 | size = strcspn(val2, "\r\n"); 71 | strncpy(value, val2, size); 72 | value[size] = '\0'; 73 | /* more than 80 chars, chew up rest of line */ 74 | while (!feof(fp) && strchr(val2, '\n') == NULL) { 75 | fgets(val2, sizeof(val2), fp); 76 | } 77 | } 78 | fclose(fp); 79 | if (i <= reqline) { 80 | info("readline requested line %d but file only had %d lines", reqline, i - 1); 81 | value[0] = '\0'; 82 | } 83 | } 84 | 85 | /* store result */ 86 | SetResult(&result, R_STRING, &value); 87 | } 88 | 89 | /* plugin initialization */ 90 | /* MUST NOT be declared 'static'! */ 91 | int plugin_init_file(void) 92 | { 93 | 94 | /* register all our cool functions */ 95 | /* the second parameter is the number of arguments */ 96 | /* -1 stands for variable argument list */ 97 | AddFunction("file::readline", 2, my_readline); 98 | 99 | return 0; 100 | } 101 | 102 | void plugin_exit_file(void) 103 | { 104 | /* free any allocated memory */ 105 | /* close filedescriptors */ 106 | } 107 | -------------------------------------------------------------------------------- /plugin_iconv.c: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * iconv charset conversion plugin 5 | * 6 | * Copyright (C) 2006 Ernst Bachmann 7 | * Copyright (C) 2006 The LCD4Linux Team 8 | * 9 | * This file is part of LCD4Linux. 10 | * 11 | * LCD4Linux is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2, or (at your option) 14 | * any later version. 15 | * 16 | * LCD4Linux is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | /* 28 | * exported functions: 29 | * 30 | * int plugin_init_iconv (void) 31 | * int plugin_exit_iconv (void) 32 | * 33 | */ 34 | 35 | 36 | #include "config.h" 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | 44 | /* these should always be included */ 45 | #include "debug.h" 46 | #include "plugin.h" 47 | 48 | #ifdef WITH_DMALLOC 49 | #include 50 | #endif 51 | 52 | 53 | 54 | /* iconv function, convert charsets */ 55 | /* valid "to" and "from" charsets can be listed by running "iconv --list" from a shell */ 56 | /* utf16 & utf32 encodings won't work, as they contain null bytes, confusing strlen */ 57 | static void my_iconv(RESULT * result, RESULT * charset_from, RESULT * charset_to, RESULT * arg) 58 | { 59 | char *source; 60 | size_t source_left; 61 | char *dest; 62 | char *dest_pos; 63 | size_t dest_left; 64 | iconv_t cd; 65 | 66 | source = R2S(arg); 67 | source_left = strlen(source); 68 | 69 | /* use twice the memory needed in best case, but save lots of reallocs in worst case */ 70 | /* increase to 4 if most conversions are to utf32 (quite unlikely) */ 71 | /* also alloc a "safety byte" so we can always zero-terminate the string. */ 72 | 73 | dest_left = 2 * source_left; 74 | dest = malloc(dest_left + 1); 75 | dest_pos = dest; 76 | 77 | cd = iconv_open(R2S(charset_to), R2S(charset_from)); 78 | if (cd != (iconv_t) (-1)) { 79 | 80 | do { 81 | 82 | /* quite spammy: debug("plugin_iconv: calling iconv with %ld,[%s]/%ld,%ld", cd, source, source_left, dest_left); */ 83 | if (iconv(cd, &source, &source_left, &dest_pos, &dest_left) == (size_t) (-1)) { 84 | switch (errno) { 85 | case EILSEQ: 86 | /* illegal bytes in input sequence */ 87 | /* try to fix by skipping a byte */ 88 | info("plugin_iconv: illegal character in input string: %c", *source); 89 | source_left--; 90 | source++; 91 | break; 92 | case EINVAL: 93 | /* input string ends during a multibyte sequence */ 94 | /* try to fix by simply ignoring */ 95 | info("plugin_iconv: illegal character at end of input"); 96 | source_left = 0; 97 | break; 98 | case E2BIG: 99 | /* not enough bytes in outbuf. */ 100 | /* TODO: Realloc output buffer, probably doubling its size? */ 101 | /* for now, just bail out. For lcd4linux 99% of all conversions will go to ascii or latin1 anyways */ 102 | error 103 | ("plugin_iconv: out of memory in destination buffer. Seems like Ernst was too lazy, complain to him!"); 104 | source_left = 0; 105 | break; 106 | default: 107 | error("plugin_iconv: strange errno state (%d) occurred", errno); 108 | source_left = 0; 109 | } 110 | } 111 | } while (source_left > 0); /* don't check for == 0, could be negative in EILSEQ case */ 112 | 113 | /* terminate the string, we're sure to have that byte left, see above */ 114 | *dest_pos = 0; 115 | dest_pos++; 116 | 117 | iconv_close(cd); 118 | } else { 119 | error("plugin_iconv: could not open conversion descriptor. Check if your charsets are supported!"); 120 | /* guaranteed to fit. */ 121 | strcpy(dest, source); 122 | } 123 | 124 | SetResult(&result, R_STRING, dest); 125 | 126 | free(dest); 127 | } 128 | 129 | 130 | /* plugin initialization */ 131 | int plugin_init_iconv(void) 132 | { 133 | 134 | AddFunction("iconv", 3, my_iconv); 135 | 136 | return 0; 137 | } 138 | 139 | void plugin_exit_iconv(void) 140 | { 141 | /* nothing to clean */ 142 | } 143 | -------------------------------------------------------------------------------- /plugin_loadavg.c: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * plugin for load average 5 | * 6 | * Copyright (C) 2003 Michael Reinelt 7 | * Copyright (C) 2004 The LCD4Linux Team 8 | * 9 | * This file is part of LCD4Linux. 10 | * 11 | * LCD4Linux is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2, or (at your option) 14 | * any later version. 15 | * 16 | * LCD4Linux is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | /* 28 | * exported functions: 29 | * 30 | * int plugin_init_loadavg (void) 31 | * adds functions for load average 32 | * 33 | */ 34 | 35 | 36 | #include "config.h" 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | 48 | #include "debug.h" 49 | #include "plugin.h" 50 | 51 | #ifndef HAVE_GETLOADAVG 52 | static int fd = -2; 53 | 54 | int getloadavg(double loadavg[], int nelem) 55 | { 56 | char buf[65], *p; 57 | ssize_t nread; 58 | int i; 59 | 60 | if (fd == -2) 61 | fd = open("/proc/loadavg", O_RDONLY); 62 | if (fd < 0) 63 | return -1; 64 | 65 | lseek(fd, 0, SEEK_SET); 66 | nread = read(fd, buf, sizeof buf - 1); 67 | 68 | if (nread < 0) 69 | return -1; 70 | buf[nread - 1] = '\0'; 71 | 72 | if (nelem > 3) 73 | nelem = 3; 74 | p = buf; 75 | for (i = 0; i < nelem; ++i) { 76 | char *endp; 77 | loadavg[i] = strtod(p, &endp); 78 | if (endp == NULL || endp == p) 79 | /* This should not happen. The format of /proc/loadavg 80 | must have changed. Don't return with what we have, 81 | signal an error. */ 82 | return -1; 83 | p = endp; 84 | } 85 | 86 | return i; 87 | } 88 | 89 | #endif 90 | 91 | 92 | static void my_loadavg(RESULT * result, RESULT * arg1) 93 | { 94 | static int nelem = -1; 95 | int index, age; 96 | static double loadavg[3]; 97 | static struct timeval last_value; 98 | struct timeval now; 99 | 100 | gettimeofday(&now, NULL); 101 | 102 | age = (now.tv_sec - last_value.tv_sec) * 1000 + (now.tv_usec - last_value.tv_usec) / 1000; 103 | /* reread every 10 msec only */ 104 | if (nelem == -1 || age == 0 || age > 10) { 105 | 106 | nelem = getloadavg(loadavg, 3); 107 | if (nelem < 0) { 108 | error("getloadavg() failed!"); 109 | SetResult(&result, R_STRING, ""); 110 | return; 111 | } 112 | last_value = now; 113 | } 114 | 115 | index = R2N(arg1); 116 | if (index < 1 || index > nelem) { 117 | error("loadavg(%d): index out of range!", index); 118 | SetResult(&result, R_STRING, ""); 119 | return; 120 | } 121 | 122 | 123 | SetResult(&result, R_NUMBER, &(loadavg[index - 1])); 124 | return; 125 | 126 | } 127 | 128 | int plugin_init_loadavg(void) 129 | { 130 | AddFunction("loadavg", 1, my_loadavg); 131 | return 0; 132 | } 133 | 134 | void plugin_exit_loadavg(void) 135 | { 136 | #ifndef HAVE_GETLOADAVG 137 | if (fd > 0) 138 | close(fd); 139 | fd = -2; 140 | #endif 141 | } 142 | -------------------------------------------------------------------------------- /plugin_math.c: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * math plugin 5 | * 6 | * Copyright (C) 2003 Michael Reinelt 7 | * Copyright (C) 2004 The LCD4Linux Team 8 | * 9 | * This file is part of LCD4Linux. 10 | * 11 | * LCD4Linux is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2, or (at your option) 14 | * any later version. 15 | * 16 | * LCD4Linux is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | /* 28 | * exported functions: 29 | * 30 | * int plugin_init_math (void) 31 | * adds some handy constants and functions 32 | * 33 | */ 34 | 35 | 36 | #include "config.h" 37 | 38 | #include 39 | #include 40 | #include 41 | 42 | #include "debug.h" 43 | #include "plugin.h" 44 | 45 | 46 | static void my_sqrt(RESULT * result, RESULT * arg1) 47 | { 48 | double value = sqrt(R2N(arg1)); 49 | SetResult(&result, R_NUMBER, &value); 50 | } 51 | 52 | static void my_exp(RESULT * result, RESULT * arg1) 53 | { 54 | double value = exp(R2N(arg1)); 55 | SetResult(&result, R_NUMBER, &value); 56 | } 57 | 58 | static void my_ln(RESULT * result, RESULT * arg1) 59 | { 60 | double value = log(R2N(arg1)); 61 | SetResult(&result, R_NUMBER, &value); 62 | } 63 | 64 | static void my_log(RESULT * result, RESULT * arg1) 65 | { 66 | double value = log10(R2N(arg1)); 67 | SetResult(&result, R_NUMBER, &value); 68 | } 69 | 70 | static void my_sin(RESULT * result, RESULT * arg1) 71 | { 72 | double value = sin(R2N(arg1)); 73 | SetResult(&result, R_NUMBER, &value); 74 | } 75 | 76 | static void my_cos(RESULT * result, RESULT * arg1) 77 | { 78 | double value = cos(R2N(arg1)); 79 | SetResult(&result, R_NUMBER, &value); 80 | } 81 | 82 | static void my_tan(RESULT * result, RESULT * arg1) 83 | { 84 | double value = tan(R2N(arg1)); 85 | SetResult(&result, R_NUMBER, &value); 86 | } 87 | 88 | 89 | static void my_min(RESULT * result, RESULT * arg1, RESULT * arg2) 90 | { 91 | double a1 = R2N(arg1); 92 | double a2 = R2N(arg2); 93 | double value = a1 < a2 ? a1 : a2; 94 | SetResult(&result, R_NUMBER, &value); 95 | } 96 | 97 | static void my_max(RESULT * result, RESULT * arg1, RESULT * arg2) 98 | { 99 | double a1 = R2N(arg1); 100 | double a2 = R2N(arg2); 101 | double value = a1 > a2 ? a1 : a2; 102 | SetResult(&result, R_NUMBER, &value); 103 | } 104 | 105 | static void my_floor(RESULT * result, RESULT * arg) 106 | { 107 | double value = floor(R2N(arg)); 108 | SetResult(&result, R_NUMBER, &value); 109 | } 110 | 111 | static void my_ceil(RESULT * result, RESULT * arg) 112 | { 113 | double value = ceil(R2N(arg)); 114 | SetResult(&result, R_NUMBER, &value); 115 | } 116 | 117 | static void my_decode(RESULT * result, int argc, RESULT * argv[]) 118 | { 119 | int index; 120 | 121 | if (argc < 2) { 122 | error("decode(): wrong number of parameters"); 123 | SetResult(&result, R_STRING, ""); 124 | return; 125 | } 126 | 127 | index = R2N(argv[0]); 128 | 129 | if (index < 0 || index >= argc - 1) { 130 | SetResult(&result, R_STRING, ""); 131 | return; 132 | } 133 | 134 | CopyResult(&result, argv[index + 1]); 135 | } 136 | 137 | 138 | int plugin_init_math(void) 139 | { 140 | /* set some handy constants */ 141 | SetVariableNumeric("Pi", M_PI); 142 | SetVariableNumeric("e", M_E); 143 | 144 | /* register some basic math functions */ 145 | AddFunction("sqrt", 1, my_sqrt); 146 | AddFunction("exp", 1, my_exp); 147 | AddFunction("ln", 1, my_ln); 148 | AddFunction("log", 1, my_log); 149 | AddFunction("sin", 1, my_sin); 150 | AddFunction("cos", 1, my_cos); 151 | AddFunction("tan", 1, my_tan); 152 | 153 | /* min, max */ 154 | AddFunction("min", 2, my_min); 155 | AddFunction("max", 2, my_max); 156 | 157 | /* floor, ceil */ 158 | AddFunction("floor", 1, my_floor); 159 | AddFunction("ceil", 1, my_ceil); 160 | 161 | /* decode */ 162 | AddFunction("decode", -1, my_decode); 163 | 164 | return 0; 165 | } 166 | 167 | void plugin_exit_math(void) 168 | { 169 | } 170 | -------------------------------------------------------------------------------- /plugin_meminfo.c: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * plugin for /proc/meminfo parsing 5 | * 6 | * Copyright (C) 2003 Michael Reinelt 7 | * Copyright (C) 2004 The LCD4Linux Team 8 | * 9 | * This file is part of LCD4Linux. 10 | * 11 | * LCD4Linux is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2, or (at your option) 14 | * any later version. 15 | * 16 | * LCD4Linux is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | /* 28 | * exported functions: 29 | * 30 | * int plugin_init_meminfo (void) 31 | * adds functions to access /proc/meminfo 32 | * 33 | */ 34 | 35 | 36 | #include "config.h" 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | 44 | #include "debug.h" 45 | #include "plugin.h" 46 | 47 | #include "hash.h" 48 | 49 | 50 | static HASH MemInfo; 51 | static FILE *stream = NULL; 52 | 53 | static int parse_meminfo(void) 54 | { 55 | int age; 56 | 57 | /* reread every 10 msec only */ 58 | age = hash_age(&MemInfo, NULL); 59 | if (age > 0 && age <= 10) 60 | return 0; 61 | 62 | if (stream == NULL) 63 | stream = fopen("/proc/meminfo", "r"); 64 | if (stream == NULL) { 65 | error("fopen(/proc/meminfo) failed: %s", strerror(errno)); 66 | return -1; 67 | } 68 | 69 | rewind(stream); 70 | while (!feof(stream)) { 71 | char buffer[256]; 72 | char *c, *key, *val; 73 | fgets(buffer, sizeof(buffer), stream); 74 | c = strchr(buffer, ':'); 75 | if (c == NULL) 76 | continue; 77 | key = buffer; 78 | val = c + 1; 79 | /* strip leading blanks from key */ 80 | while (isspace(*key)) 81 | *key++ = '\0'; 82 | /* strip trailing blanks from key */ 83 | do 84 | *c = '\0'; 85 | while (isspace(*--c)); 86 | /* strip leading blanks from value */ 87 | while (isspace(*val)) 88 | *val++ = '\0'; 89 | /* strip trailing blanks from value */ 90 | for (c = val; *c != '\0'; c++); 91 | while (isspace(*--c)) 92 | *c = '\0'; 93 | /* skip lines that do not end with " kB" */ 94 | if (*c == 'B' && *(c - 1) == 'k' && *(c - 2) == ' ') { 95 | /* strip trailing " kB" from value */ 96 | *(c - 2) = '\0'; 97 | /* add entry to hash table */ 98 | hash_put(&MemInfo, key, val); 99 | } 100 | } 101 | return 0; 102 | } 103 | 104 | static void my_meminfo(RESULT * result, RESULT * arg1) 105 | { 106 | char *key, *val; 107 | 108 | if (parse_meminfo() < 0) { 109 | SetResult(&result, R_STRING, ""); 110 | return; 111 | } 112 | 113 | key = R2S(arg1); 114 | val = hash_get(&MemInfo, key, NULL); 115 | if (val == NULL) 116 | val = ""; 117 | 118 | SetResult(&result, R_STRING, val); 119 | } 120 | 121 | 122 | int plugin_init_meminfo(void) 123 | { 124 | hash_create(&MemInfo); 125 | AddFunction("meminfo", 1, my_meminfo); 126 | return 0; 127 | } 128 | 129 | 130 | void plugin_exit_meminfo(void) 131 | { 132 | if (stream != NULL) { 133 | fclose(stream); 134 | stream = NULL; 135 | } 136 | hash_destroy(&MemInfo); 137 | } 138 | -------------------------------------------------------------------------------- /plugin_netdev.c: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * plugin for /proc/net/dev parsing 5 | * 6 | * Copyright (C) 2003 Michael Reinelt 7 | * Copyright (C) 2004 The LCD4Linux Team 8 | * 9 | * This file is part of LCD4Linux. 10 | * 11 | * LCD4Linux is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2, or (at your option) 14 | * any later version. 15 | * 16 | * LCD4Linux is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | /* 28 | * exported functions: 29 | * 30 | * int plugin_init_netdev (void) 31 | * adds functions to access /proc/net/dev 32 | * 33 | */ 34 | 35 | 36 | #include "config.h" 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | 44 | #include "debug.h" 45 | #include "plugin.h" 46 | #include "qprintf.h" 47 | #include "hash.h" 48 | 49 | 50 | static HASH NetDev; 51 | static FILE *Stream = NULL; 52 | static char *DELIMITER = " :|\t\n"; 53 | 54 | static int parse_netdev(void) 55 | { 56 | int age; 57 | int row, col; 58 | static int first_time = 1; 59 | 60 | /* reread every 10 msec only */ 61 | age = hash_age(&NetDev, NULL); 62 | if (age > 0 && age <= 10) 63 | return 0; 64 | 65 | if (Stream == NULL) 66 | Stream = fopen("/proc/net/dev", "r"); 67 | if (Stream == NULL) { 68 | error("fopen(/proc/net/dev) failed: %s", strerror(errno)); 69 | return -1; 70 | } 71 | 72 | rewind(Stream); 73 | row = 0; 74 | 75 | while (!feof(Stream)) { 76 | char buffer[256]; 77 | char dev[16]; 78 | char *beg, *end; 79 | unsigned int len; 80 | 81 | if (fgets(buffer, sizeof(buffer), Stream) == NULL) 82 | break; 83 | 84 | switch (++row) { 85 | 86 | case 1: 87 | /* skip row 1 */ 88 | continue; 89 | 90 | case 2: 91 | /* row 2 used for headers */ 92 | if (first_time) { 93 | char *RxTx = strrchr(buffer, '|'); 94 | first_time = 0; 95 | col = 0; 96 | beg = buffer; 97 | while (beg) { 98 | char key[32]; 99 | 100 | while (strchr(DELIMITER, *beg)) 101 | beg++; 102 | if ((end = strpbrk(beg, DELIMITER)) != NULL) 103 | *end = '\0'; 104 | qprintf(key, sizeof(key), "%s_%s", beg < RxTx ? "Rx" : "Tx", beg); 105 | hash_set_column(&NetDev, col++, key); 106 | beg = end ? end + 1 : NULL; 107 | } 108 | } 109 | continue; 110 | 111 | default: 112 | /* fetch interface name (1st column) as key */ 113 | beg = buffer; 114 | while (*beg && *beg == ' ') 115 | beg++; 116 | end = beg + 1; 117 | while (*end && *end != ':') 118 | end++; 119 | len = end - beg; 120 | if (len >= sizeof(dev)) 121 | len = sizeof(dev) - 1; 122 | strncpy(dev, beg, len); 123 | dev[len] = '\0'; 124 | 125 | hash_put_delta(&NetDev, dev, buffer); 126 | } 127 | } 128 | 129 | return 0; 130 | } 131 | 132 | static void my_netdev(RESULT * result, RESULT * arg1, RESULT * arg2, RESULT * arg3) 133 | { 134 | char *dev, *key; 135 | int delay; 136 | double value; 137 | 138 | if (parse_netdev() < 0) { 139 | SetResult(&result, R_STRING, ""); 140 | return; 141 | } 142 | 143 | dev = R2S(arg1); 144 | key = R2S(arg2); 145 | delay = R2N(arg3); 146 | 147 | value = hash_get_regex(&NetDev, dev, key, delay); 148 | 149 | SetResult(&result, R_NUMBER, &value); 150 | } 151 | 152 | static void my_netdev_fast(RESULT * result, RESULT * arg1, RESULT * arg2, RESULT * arg3) 153 | { 154 | char *dev, *key; 155 | int delay; 156 | double value; 157 | 158 | if (parse_netdev() < 0) { 159 | SetResult(&result, R_STRING, ""); 160 | return; 161 | } 162 | 163 | dev = R2S(arg1); 164 | key = R2S(arg2); 165 | delay = R2N(arg3); 166 | 167 | value = hash_get_delta(&NetDev, dev, key, delay); 168 | 169 | SetResult(&result, R_NUMBER, &value); 170 | } 171 | 172 | 173 | int plugin_init_netdev(void) 174 | { 175 | hash_create(&NetDev); 176 | hash_set_delimiter(&NetDev, " :|\t\n"); 177 | 178 | AddFunction("netdev", 3, my_netdev); 179 | AddFunction("netdev::fast", 3, my_netdev_fast); 180 | return 0; 181 | } 182 | 183 | void plugin_exit_netdev(void) 184 | { 185 | if (Stream != NULL) { 186 | fclose(Stream); 187 | Stream = NULL; 188 | } 189 | hash_destroy(&NetDev); 190 | } 191 | -------------------------------------------------------------------------------- /plugin_ppp.c: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * plugin for ppp throughput 5 | * 6 | * Copyright (C) 2003 Michael Reinelt 7 | * Copyright (C) 2004 The LCD4Linux Team 8 | * 9 | * This file is part of LCD4Linux. 10 | * 11 | * LCD4Linux is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2, or (at your option) 14 | * any later version. 15 | * 16 | * LCD4Linux is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | /* 28 | * exported functions: 29 | * 30 | * int plugin_init_ppp (void) 31 | * adds ppp() function 32 | * 33 | */ 34 | 35 | #include "config.h" 36 | 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | #ifdef HAVE_NET_IF_PPP_H 44 | #include 45 | #else 46 | #warning if_ppp.h not found. PPP support deactivated. 47 | #endif 48 | 49 | #include "debug.h" 50 | #include "plugin.h" 51 | #include "qprintf.h" 52 | #include "hash.h" 53 | 54 | #ifdef HAVE_NET_IF_PPP_H 55 | 56 | static HASH PPP; 57 | 58 | static int get_ppp_stats(void) 59 | { 60 | int age; 61 | int unit; 62 | unsigned ibytes, obytes; 63 | static int fd = -2; 64 | struct ifpppstatsreq req; 65 | char key[16], val[16]; 66 | 67 | /* reread every 10 msec only */ 68 | age = hash_age(&PPP, NULL); 69 | if (age > 0 && age <= 10) 70 | return 0; 71 | 72 | /* open socket only once */ 73 | if (fd == -2) { 74 | fd = socket(AF_INET, SOCK_DGRAM, 0); 75 | if (fd == -1) { 76 | error("socket() failed: %s", strerror(errno)); 77 | return -1; 78 | } 79 | } 80 | 81 | for (unit = 0; unit < 8; unit++) { 82 | memset(&req, 0, sizeof(req)); 83 | req.stats_ptr = (caddr_t) & req.stats; 84 | qprintf(req.ifr__name, sizeof(req.ifr__name), "ppp%d", unit); 85 | 86 | if (ioctl(fd, SIOCGPPPSTATS, &req) == 0) { 87 | ibytes = req.stats.p.ppp_ibytes; 88 | obytes = req.stats.p.ppp_obytes; 89 | } else { 90 | ibytes = obytes = 0; 91 | } 92 | qprintf(key, sizeof(key), "Rx:%d", unit); 93 | qprintf(val, sizeof(val), "%d", ibytes); 94 | hash_put_delta(&PPP, key, val); 95 | qprintf(key, sizeof(key), "Tx:%d", unit); 96 | qprintf(val, sizeof(val), "%d", obytes); 97 | hash_put_delta(&PPP, key, val); 98 | 99 | } 100 | return 0; 101 | } 102 | 103 | 104 | static void my_ppp(RESULT * result, RESULT * arg1, RESULT * arg2) 105 | { 106 | double value; 107 | 108 | if (get_ppp_stats() < 0) { 109 | SetResult(&result, R_STRING, ""); 110 | return; 111 | } 112 | value = hash_get_delta(&PPP, R2S(arg1), NULL, R2N(arg2)); 113 | SetResult(&result, R_NUMBER, &value); 114 | } 115 | 116 | #endif 117 | 118 | 119 | int plugin_init_ppp(void) 120 | { 121 | hash_create(&PPP); 122 | #ifdef HAVE_NET_IF_PPP_H 123 | AddFunction("ppp", 2, my_ppp); 124 | #endif 125 | return 0; 126 | } 127 | 128 | void plugin_exit_ppp(void) 129 | { 130 | hash_destroy(&PPP); 131 | } 132 | -------------------------------------------------------------------------------- /plugin_python.c: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * Python plugin 5 | * 6 | * Copyright 2005 Dan Fritz 7 | * Copyright 2005 The LCD4Linux Team 8 | * 9 | * This file is part of LCD4Linux. 10 | * 11 | * LCD4Linux is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2, or (at your option) 14 | * any later version. 15 | * 16 | * LCD4Linux is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | /* 28 | * exported functions: 29 | * 30 | * int plugin_init_python (void) 31 | * adds a python interpreter 32 | * 33 | */ 34 | 35 | #include "config.h" 36 | #include 37 | #include "debug.h" 38 | #include "plugin.h" 39 | 40 | /* 41 | * Executes a python function specified by function name and module. 42 | * 43 | * This method is more or less a copy of an example found in the python 44 | * documentation. Kudos goes to Guido van Rossum and Fred L. Drake. 45 | * 46 | * Fixme: this function should be able to accept and receive any types 47 | * of arguments supported by the evaluator. Right now only strings are accepted. 48 | */ 49 | 50 | static void pyt_exec_str(RESULT * result, const char *module, const char *function, int argc, const char *argv[]) 51 | { 52 | 53 | PyObject *pName, *pModule, *pDict, *pFunc; 54 | PyObject *pArgs, *pValue; 55 | const char *rv = NULL; 56 | int i; 57 | 58 | pName = PyString_FromString(module); 59 | /* Error checking of pName left out */ 60 | 61 | pModule = PyImport_Import(pName); 62 | Py_DECREF(pName); 63 | 64 | if (pModule != NULL) { 65 | pDict = PyModule_GetDict(pModule); 66 | /* pDict is a borrowed reference */ 67 | 68 | pFunc = PyDict_GetItemString(pDict, function); 69 | /* pFun: Borrowed reference */ 70 | 71 | if (pFunc && PyCallable_Check(pFunc)) { 72 | pArgs = PyTuple_New(argc); 73 | for (i = 0; i < argc; ++i) { 74 | pValue = PyString_FromString(argv[i]); 75 | if (!pValue) { 76 | Py_DECREF(pArgs); 77 | Py_DECREF(pModule); 78 | error("Cannot convert argument \"%s\" to python format", argv[i]); 79 | SetResult(&result, R_STRING, ""); 80 | return; 81 | } 82 | /* pValue reference stolen here: */ 83 | PyTuple_SetItem(pArgs, i, pValue); 84 | } 85 | pValue = PyObject_CallObject(pFunc, pArgs); 86 | Py_DECREF(pArgs); 87 | if (pValue != NULL) { 88 | rv = PyString_AsString(pValue); 89 | SetResult(&result, R_STRING, rv); 90 | Py_DECREF(pValue); 91 | /* rv is now a 'dangling reference' */ 92 | return; 93 | } else { 94 | Py_DECREF(pModule); 95 | error("Python call failed (\"%s.%s\")", module, function); 96 | /* print traceback on stderr */ 97 | PyErr_PrintEx(0); 98 | SetResult(&result, R_STRING, ""); 99 | return; 100 | } 101 | /* pDict and pFunc are borrowed and must not be Py_DECREF-ed */ 102 | } else { 103 | error("Can not find python function \"%s.%s\"", module, function); 104 | } 105 | Py_DECREF(pModule); 106 | } else { 107 | error("Failed to load python module \"%s\"", module); 108 | /* print traceback on stderr */ 109 | PyErr_PrintEx(0); 110 | } 111 | SetResult(&result, R_STRING, ""); 112 | return; 113 | } 114 | 115 | static int python_cleanup_responsibility = 0; 116 | 117 | static void my_exec(RESULT * result, RESULT * module, RESULT * function, RESULT * arg) 118 | { 119 | /* Fixme: a plugin should be able to accept any number of arguments, don't know how 120 | to code that (yet) */ 121 | const char *args[] = { R2S(arg) }; 122 | pyt_exec_str(result, R2S(module), R2S(function), 1, args); 123 | } 124 | 125 | int plugin_init_python(void) 126 | { 127 | if (!Py_IsInitialized()) { 128 | Py_Initialize(); 129 | python_cleanup_responsibility = 1; 130 | } 131 | AddFunction("python::exec", 3, my_exec); 132 | return 0; 133 | } 134 | 135 | void plugin_exit_python(void) 136 | { 137 | /* Make sure NOT to call Py_Finalize() When (and if) the entire lcd4linux process 138 | * is started from inside python 139 | */ 140 | if (python_cleanup_responsibility) { 141 | python_cleanup_responsibility = 0; 142 | Py_Finalize(); 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /plugin_seti.c: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * plugin for seti@home status reporting 5 | * 6 | * Copyright (C) 2004 Michael Reinelt 7 | * Copyright (C) 2004 The LCD4Linux Team 8 | * 9 | * based on the old seti client which is 10 | * Copyright (C) 2001 Axel Ehnert 11 | * 12 | * 13 | * This file is part of LCD4Linux. 14 | * 15 | * LCD4Linux is free software; you can redistribute it and/or modify 16 | * it under the terms of the GNU General Public License as published by 17 | * the Free Software Foundation; either version 2, or (at your option) 18 | * any later version. 19 | * 20 | * LCD4Linux is distributed in the hope that it will be useful, 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | * GNU General Public License for more details. 24 | * 25 | * You should have received a copy of the GNU General Public License 26 | * along with this program; if not, write to the Free Software 27 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 28 | * 29 | */ 30 | 31 | /* 32 | * exported functions: 33 | * 34 | * int plugin_init_seti (void) 35 | * adds functions to access /seti/state.sah 36 | * 37 | */ 38 | 39 | 40 | #include "config.h" 41 | 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | 48 | #include "debug.h" 49 | #include "plugin.h" 50 | #include "hash.h" 51 | #include "cfg.h" 52 | 53 | #define SECTION "Plugin:Seti" 54 | #define DIRKEY "Directory" 55 | #define STATEFILE "state.sah" 56 | 57 | static HASH SETI; 58 | static int fatal = 0; 59 | 60 | static int parse_seti(void) 61 | { 62 | static char fn[256] = ""; 63 | FILE *stream; 64 | int age; 65 | 66 | /* if a fatal error occurred, do nothing */ 67 | if (fatal != 0) 68 | return -1; 69 | 70 | /* reread every 100 msec only */ 71 | age = hash_age(&SETI, NULL); 72 | if (age > 0 && age <= 100) 73 | return 0; 74 | 75 | if (fn[0] == '\0') { 76 | char *dir = cfg_get(SECTION, DIRKEY, NULL); 77 | if (dir == NULL || *dir == '\0') { 78 | error("no '%s.%s' entry from %s\n", SECTION, DIRKEY, cfg_source()); 79 | fatal = 1; 80 | return -1; 81 | } 82 | if (strlen(dir) > sizeof(fn) - sizeof(STATEFILE) - 2) { 83 | error("entry '%s.%s' too long from %s!\n", SECTION, DIRKEY, cfg_source()); 84 | fatal = 1; 85 | free(dir); 86 | return -1; 87 | } 88 | strcpy(fn, dir); 89 | if (fn[strlen(fn) - 1] != '/') 90 | strcat(fn, "/"); 91 | strcat(fn, STATEFILE); 92 | free(dir); 93 | } 94 | 95 | stream = fopen(fn, "r"); 96 | if (stream == NULL) { 97 | error("fopen(%s) failed: %s", fn, strerror(errno)); 98 | return -1; 99 | } 100 | 101 | while (!feof(stream)) { 102 | char buffer[256]; 103 | char *c, *key, *val; 104 | fgets(buffer, sizeof(buffer), stream); 105 | c = strchr(buffer, '='); 106 | if (c == NULL) 107 | continue; 108 | key = buffer; 109 | val = c + 1; 110 | /* strip leading blanks from key */ 111 | while (isspace(*key)) 112 | *key++ = '\0'; 113 | /* strip trailing blanks from key */ 114 | do 115 | *c = '\0'; 116 | while (isspace(*--c)); 117 | /* strip leading blanks from value */ 118 | while (isspace(*val)) 119 | *val++ = '\0'; 120 | /* strip trailing blanks from value */ 121 | for (c = val; *c != '\0'; c++); 122 | while (isspace(*--c)) 123 | *c = '\0'; 124 | /* add entry to hash table */ 125 | hash_put(&SETI, key, val); 126 | } 127 | 128 | fclose(stream); 129 | 130 | return 0; 131 | } 132 | 133 | 134 | static void my_seti(RESULT * result, RESULT * arg1) 135 | { 136 | char *key, *val; 137 | 138 | if (parse_seti() < 0) { 139 | SetResult(&result, R_STRING, ""); 140 | return; 141 | } 142 | 143 | key = R2S(arg1); 144 | val = hash_get(&SETI, key, NULL); 145 | if (val == NULL) 146 | val = ""; 147 | 148 | SetResult(&result, R_STRING, val); 149 | } 150 | 151 | 152 | int plugin_init_seti(void) 153 | { 154 | hash_create(&SETI); 155 | AddFunction("seti", 1, my_seti); 156 | return 0; 157 | } 158 | 159 | 160 | void plugin_exit_seti(void) 161 | { 162 | hash_destroy(&SETI); 163 | } 164 | -------------------------------------------------------------------------------- /plugin_statfs.c: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * plugin for statfs() syscall 5 | * 6 | * Copyright (C) 2005 Michael Reinelt 7 | * Copyright (C) 2005 The LCD4Linux Team 8 | * 9 | * This file is part of LCD4Linux. 10 | * 11 | * LCD4Linux is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2, or (at your option) 14 | * any later version. 15 | * 16 | * LCD4Linux is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | /* 28 | * exported functions: 29 | * 30 | * int plugin_init_statfs (void) 31 | * adds statfs() functions 32 | * 33 | */ 34 | 35 | 36 | #include "config.h" 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | #include "debug.h" 44 | #include "plugin.h" 45 | 46 | 47 | 48 | static void my_statfs(RESULT * result, RESULT * arg1, RESULT * arg2) 49 | { 50 | struct statfs buf; 51 | char *path, *key; 52 | double value; 53 | 54 | path = R2S(arg1); 55 | key = R2S(arg2); 56 | 57 | if (statfs(path, &buf) != 0) { 58 | error("statfs(%s) failed: %s", path, strerror(errno)); 59 | SetResult(&result, R_STRING, ""); 60 | return; 61 | } 62 | 63 | if (strcasecmp(key, "type") == 0) { 64 | value = buf.f_type; 65 | } else if (strcasecmp(key, "bsize") == 0) { 66 | value = buf.f_bsize; 67 | } else if (strcasecmp(key, "blocks") == 0) { 68 | value = buf.f_blocks; 69 | } else if (strcasecmp(key, "bfree") == 0) { 70 | value = buf.f_bfree; 71 | } else if (strcasecmp(key, "bavail") == 0) { 72 | value = buf.f_bavail; 73 | } else if (strcasecmp(key, "files") == 0) { 74 | value = buf.f_files; 75 | } else if (strcasecmp(key, "ffree") == 0) { 76 | value = buf.f_ffree; 77 | #if 0 78 | } else if (strcasecmp(key, "fsid") == 0) { 79 | value = buf.f_fsid; 80 | #endif 81 | } else if (strcasecmp(key, "namelen") == 0) { 82 | value = buf.f_namelen; 83 | } else { 84 | error("statfs: unknown field '%s'", key); 85 | value = -1; 86 | } 87 | 88 | SetResult(&result, R_NUMBER, &value); 89 | } 90 | 91 | 92 | int plugin_init_statfs(void) 93 | { 94 | AddFunction("statfs", 2, my_statfs); 95 | return 0; 96 | } 97 | 98 | void plugin_exit_statfs(void) 99 | { 100 | } 101 | -------------------------------------------------------------------------------- /plugin_string.c: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * string plugin 5 | * 6 | * Copyright (C) 2003, 2004 Michael Reinelt 7 | * Copyright (C) 2004 The LCD4Linux Team 8 | * 9 | * This file is part of LCD4Linux. 10 | * 11 | * LCD4Linux is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2, or (at your option) 14 | * any later version. 15 | * 16 | * LCD4Linux is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | /* 28 | * exported functions: 29 | * 30 | * int plugin_init_string (void) 31 | * adds some handy string functions 32 | * 33 | */ 34 | 35 | 36 | #include "config.h" 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | #include "debug.h" 44 | #include "plugin.h" 45 | 46 | 47 | static void my_strlen(RESULT * result, RESULT * arg1) 48 | { 49 | double value = strlen(R2S(arg1)); 50 | SetResult(&result, R_NUMBER, &value); 51 | } 52 | 53 | /* 'upcase' function (shamelessly stolen from plugin_sample.c)*/ 54 | /* returns the string in upper case letters */ 55 | static void my_strupper(RESULT * result, RESULT * arg1) 56 | { 57 | char *value, *p; 58 | 59 | value = strdup(R2S(arg1)); 60 | 61 | for (p = value; *p != '\0'; p++) 62 | *p = toupper(*p); 63 | 64 | SetResult(&result, R_STRING, value); 65 | free(value); 66 | } 67 | 68 | static void my_strstr(RESULT * result, RESULT * arg1, RESULT * arg2) 69 | { 70 | char *p; 71 | double value; 72 | 73 | char *haystack = R2S(arg1); 74 | char *needle = R2S(arg2); 75 | 76 | p = strstr(haystack, needle); 77 | 78 | if (p == NULL) { 79 | value = -1; 80 | } else { 81 | value = p - haystack; 82 | } 83 | 84 | SetResult(&result, R_NUMBER, &value); 85 | } 86 | 87 | static void my_substr(RESULT * result, int argc, RESULT * argv[]) 88 | { 89 | char *str, *p1, *p2; 90 | int pos, len; 91 | 92 | if (argc < 2 || argc > 3) { 93 | error("substr(): wrong number of parameters"); 94 | SetResult(&result, R_STRING, ""); 95 | return; 96 | } 97 | 98 | str = strdup(R2S(argv[0])); 99 | 100 | pos = R2N(argv[1]); 101 | if (pos < 0) 102 | pos = 0; 103 | 104 | if (argc == 3) { 105 | len = R2N(argv[2]); 106 | if (len < 0) 107 | len = 0; 108 | } else { 109 | len = -1; 110 | } 111 | 112 | p1 = str; 113 | while (pos > 0 && *p1 != '\0') { 114 | p1++; 115 | pos--; 116 | } 117 | 118 | if (len >= 0) { 119 | p2 = p1; 120 | while (len > 0 && *p2 != '\0') { 121 | p2++; 122 | len--; 123 | } 124 | *p2 = '\0'; 125 | } 126 | 127 | SetResult(&result, R_STRING, p1); 128 | free(str); 129 | } 130 | 131 | int plugin_init_string(void) 132 | { 133 | 134 | /* register some basic string functions */ 135 | AddFunction("strlen", 1, my_strlen); 136 | AddFunction("strupper", 1, my_strupper); 137 | AddFunction("strstr", 2, my_strstr); 138 | AddFunction("substr", -1, my_substr); 139 | return 0; 140 | } 141 | 142 | void plugin_exit_string(void) 143 | { 144 | /* empty */ 145 | } 146 | -------------------------------------------------------------------------------- /plugin_test.c: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * Handy functions for testing displays and debugging code. 5 | * 6 | * Copyright (C) 2004 Andy Baxter. 7 | * 8 | * Based on sample plugin which is 9 | * Copyright (C) 2003 Michael Reinelt 10 | * Copyright (C) 2004 The LCD4Linux Team 11 | * 12 | * This file is part of LCD4Linux. 13 | * 14 | * LCD4Linux is free software; you can redistribute it and/or modify 15 | * it under the terms of the GNU General Public License as published by 16 | * the Free Software Foundation; either version 2, or (at your option) 17 | * any later version. 18 | * 19 | * LCD4Linux is distributed in the hope that it will be useful, 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | * GNU General Public License for more details. 23 | * 24 | * You should have received a copy of the GNU General Public License 25 | * along with this program; if not, write to the Free Software 26 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 27 | * 28 | */ 29 | 30 | int plugin_init_test(void); 31 | 32 | #include "config.h" 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | #include "debug.h" 40 | #include "plugin.h" 41 | 42 | #ifdef WITH_DMALLOC 43 | #include 44 | #endif 45 | 46 | 47 | /* used for testing bars - keeps values for a series of 10 bars, 48 | * which are incremented and decremented between 0 and rmax by 49 | * amount rdelta every time they are read. Starting value is rstart. 50 | * rbar gives the number of the test bar. 51 | */ 52 | static void my_test_bar(RESULT * result, RESULT * rbar, RESULT * rmax, RESULT * rstart, RESULT * rdelta) 53 | { 54 | static double values[10] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; 55 | static double deltas[10]; 56 | int bar; 57 | double max, delta, value; 58 | 59 | max = R2N(rmax); 60 | delta = R2N(rdelta); 61 | 62 | /* the maths is just to stop double rounding errors and bad values. */ 63 | bar = ((int) floor(R2N(rbar) + 0.1)) % 10; 64 | if (fabs(delta) > 0.1) { 65 | /* don't move or init the bar if delta=0 (the widget is only browsing) */ 66 | if (values[bar] == -1) { 67 | /* first time called. */ 68 | values[bar] = R2N(rstart); 69 | deltas[bar] = delta; 70 | }; 71 | values[bar] += deltas[bar]; 72 | }; 73 | if (values[bar] < 0 || values[bar] > max) { 74 | /* turn around. */ 75 | deltas[bar] = -deltas[bar]; 76 | values[bar] += deltas[bar]; 77 | }; 78 | value = values[bar]; 79 | SetResult(&result, R_NUMBER, &value); 80 | } 81 | 82 | 83 | /* like above, but just switches a value between 1 and -1. Can use to test 84 | * visibility of icons. 85 | */ 86 | static void my_test_onoff(RESULT * result, RESULT * arg1) 87 | { 88 | static int on[10] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; 89 | int i; 90 | double val; 91 | 92 | i = ((int) floor(R2N(arg1) + 0.1)) % 10; 93 | on[i] = -on[i]; 94 | val = (double) on[i]; 95 | 96 | SetResult(&result, R_NUMBER, &val); 97 | } 98 | 99 | 100 | int plugin_init_test(void) 101 | { 102 | 103 | AddFunction("test::bar", 4, my_test_bar); 104 | AddFunction("test::onoff", 1, my_test_onoff); 105 | 106 | return 0; 107 | } 108 | 109 | void plugin_exit_test(void) 110 | { 111 | /* empty */ 112 | } 113 | -------------------------------------------------------------------------------- /plugin_time.c: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * time plugin 5 | * 6 | * Copyright (C) 2003, 2004 Michael Reinelt 7 | * Copyright (C) 2004 The LCD4Linux Team 8 | * 9 | * This file is part of LCD4Linux. 10 | * 11 | * LCD4Linux is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2, or (at your option) 14 | * any later version. 15 | * 16 | * LCD4Linux is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | /* 28 | * exported functions: 29 | * 30 | * int plugin_init_time (void) 31 | * adds some handy time functions 32 | * 33 | */ 34 | 35 | 36 | #include "config.h" 37 | 38 | #include 39 | #include 40 | #include 41 | 42 | #include "debug.h" 43 | #include "plugin.h" 44 | 45 | 46 | static void my_time(RESULT * result) 47 | { 48 | double value = time(NULL); 49 | SetResult(&result, R_NUMBER, &value); 50 | } 51 | 52 | 53 | static void my_strftime(RESULT * result, RESULT * arg1, RESULT * arg2) 54 | { 55 | char value[256]; 56 | time_t t = R2N(arg2); 57 | 58 | value[0] = '\0'; 59 | strftime(value, sizeof(value), R2S(arg1), localtime(&t)); 60 | 61 | SetResult(&result, R_STRING, value); 62 | } 63 | 64 | static void my_stftime_tz(RESULT * result, RESULT * arg1, RESULT * arg2, RESULT * arg3) 65 | { 66 | char value[256] = ""; 67 | time_t t = R2N(arg2); 68 | char *tz = R2S(arg3); 69 | char *old_tz; 70 | 71 | old_tz = getenv("TZ"); 72 | 73 | /* 74 | * because the next setenv() call may overwrite that string, we 75 | * duplicate it here 76 | */ 77 | if (old_tz) { 78 | old_tz = strdup(old_tz); 79 | } 80 | 81 | setenv("TZ", tz, 1); 82 | tzset(); 83 | 84 | strftime(value, sizeof(value), R2S(arg1), localtime(&t)); 85 | 86 | if (old_tz) { 87 | setenv("TZ", old_tz, 1); 88 | } else { 89 | unsetenv("TZ"); 90 | } 91 | tzset(); 92 | 93 | free(old_tz); 94 | 95 | SetResult(&result, R_STRING, value); 96 | } 97 | 98 | 99 | int plugin_init_time(void) 100 | { 101 | 102 | /* register some basic time functions */ 103 | AddFunction("time", 0, my_time); 104 | AddFunction("strftime", 2, my_strftime); 105 | AddFunction("strftime_tz", 3, my_stftime_tz); 106 | 107 | return 0; 108 | } 109 | 110 | void plugin_exit_time(void) 111 | { 112 | /* empty */ 113 | } 114 | -------------------------------------------------------------------------------- /plugin_uname.c: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * plugin for uname() syscall 5 | * 6 | * Copyright (C) 2003 Michael Reinelt 7 | * Copyright (C) 2004 The LCD4Linux Team 8 | * 9 | * This file is part of LCD4Linux. 10 | * 11 | * LCD4Linux is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2, or (at your option) 14 | * any later version. 15 | * 16 | * LCD4Linux is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | /* 28 | * exported functions: 29 | * 30 | * int plugin_init_uname (void) 31 | * adds uname() functions 32 | * 33 | */ 34 | 35 | 36 | #include "config.h" 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | #include "debug.h" 44 | #include "plugin.h" 45 | 46 | 47 | 48 | static void my_uname(RESULT * result, RESULT * arg1) 49 | { 50 | struct utsname utsbuf; 51 | char *key, *value; 52 | 53 | key = R2S(arg1); 54 | 55 | if (uname(&utsbuf) != 0) { 56 | error("uname() failed: %s", strerror(errno)); 57 | SetResult(&result, R_STRING, ""); 58 | return; 59 | } 60 | 61 | if (strcasecmp(key, "sysname") == 0) { 62 | value = utsbuf.sysname; 63 | } else if (strcasecmp(key, "nodename") == 0) { 64 | value = utsbuf.nodename; 65 | } else if (strcasecmp(key, "release") == 0) { 66 | value = utsbuf.release; 67 | } else if (strcasecmp(key, "version") == 0) { 68 | value = utsbuf.version; 69 | } else if (strcasecmp(key, "machine") == 0) { 70 | value = utsbuf.machine; 71 | #if defined(_GNU_SOURCE) && ! defined(__APPLE__) && ! defined(__CYGWIN__) 72 | } else if (strcasecmp(key, "domainname") == 0) { 73 | value = utsbuf.domainname; 74 | #endif 75 | } else { 76 | error("uname: unknown field '%s'", key); 77 | value = ""; 78 | } 79 | 80 | SetResult(&result, R_STRING, value); 81 | } 82 | 83 | 84 | int plugin_init_uname(void) 85 | { 86 | AddFunction("uname", 1, my_uname); 87 | return 0; 88 | } 89 | 90 | void plugin_exit_uname(void) 91 | { 92 | } 93 | -------------------------------------------------------------------------------- /plugin_xmms.c: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * XMMS-Plugin for LCD4Linux 5 | * Copyright (C) 2003 Markus Keil 6 | * 7 | * This file is part of LCD4Linux. 8 | * 9 | * LCD4Linux is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2, or (at your option) 12 | * any later version. 13 | * 14 | * LCD4Linux is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 | * 23 | */ 24 | 25 | /* 26 | * exported functions: 27 | * 28 | * int plugin_init_xmms (void) 29 | * adds parser for /tmp/xmms-info 30 | * 31 | */ 32 | 33 | 34 | /* 35 | * The Argument 'arg1' must be one of these Things (without brackets): 36 | * 37 | * 'Title' - The title of the current song 38 | * 'Status' - The status of XMMS (playing, pause, ...) 39 | * 'Tunes in playlist' - How many entries are in the playlist 40 | * 'Currently playing' - which playlist-entry is playing 41 | * 'uSecPosition' - The position of the title in seconds (usefull for bargraphs ;-) ) 42 | * 'Position' - The position of the title in mm:ss 43 | * 'uSecTime' - The length of the current title in seconds 44 | * 'Time' - The length of the current title in mm:ss 45 | * 'Current bitrate' - The current bitrate in bit 46 | * 'Samping Frequency' - The current samplingfreqency in Hz 47 | * 'Channels' - The current number of audiochannels 48 | * 'File' - The full path of the current file 49 | * 50 | * These arguments are case-sensitive 51 | */ 52 | 53 | 54 | #include "config.h" 55 | 56 | #include 57 | #include 58 | #include 59 | 60 | #include "hash.h" 61 | #include "debug.h" 62 | #include "plugin.h" 63 | 64 | 65 | static HASH xmms; 66 | 67 | 68 | static int parse_xmms_info(void) 69 | { 70 | int age; 71 | FILE *xmms_stream; 72 | char zeile[200]; 73 | 74 | /* reread every 100msec only */ 75 | age = hash_age(&xmms, NULL); 76 | if (age >= 0 && age <= 200) 77 | return 0; 78 | /* Open Filestream for '/tmp/xmms-info' */ 79 | xmms_stream = fopen("/tmp/xmms-info", "r"); 80 | 81 | /* Check for File */ 82 | if (!xmms_stream) { 83 | error("Error: Cannot open XMMS-Info Stream! Is XMMS started?"); 84 | return -1; 85 | } 86 | 87 | /* Read Lines from the Stream */ 88 | while (fgets(zeile, sizeof(zeile), xmms_stream)) { 89 | char *c, *key, *val; 90 | c = strchr(zeile, ':'); 91 | if (c == NULL) 92 | continue; 93 | key = zeile; 94 | val = c + 1; 95 | /* strip leading blanks from key */ 96 | while (isspace(*key)) 97 | *key++ = '\0'; 98 | /* strip trailing blanks from key */ 99 | do 100 | *c = '\0'; 101 | while (isspace(*--c)); 102 | /* strip leading blanks from value */ 103 | while (isspace(*val)) 104 | *val++ = '\0'; 105 | /* strip trailing blanks from value */ 106 | for (c = val; *c != '\0'; c++); 107 | while (isspace(*--c)) 108 | *c = '\0'; 109 | hash_put(&xmms, key, val); 110 | } 111 | 112 | fclose(xmms_stream); 113 | return 0; 114 | 115 | } 116 | 117 | static void my_xmms(RESULT * result, RESULT * arg1) 118 | { 119 | char *key, *val; 120 | 121 | if (parse_xmms_info() < 0) { 122 | SetResult(&result, R_STRING, ""); 123 | return; 124 | } 125 | 126 | key = R2S(arg1); 127 | val = hash_get(&xmms, key, NULL); 128 | if (val == NULL) 129 | val = ""; 130 | 131 | SetResult(&result, R_STRING, val); 132 | } 133 | 134 | 135 | int plugin_init_xmms(void) 136 | { 137 | hash_create(&xmms); 138 | 139 | /* register xmms info */ 140 | AddFunction("xmms", 1, my_xmms); 141 | 142 | return 0; 143 | } 144 | 145 | void plugin_exit_xmms(void) 146 | { 147 | hash_destroy(&xmms); 148 | } 149 | -------------------------------------------------------------------------------- /png.html: -------------------------------------------------------------------------------- 1 | 2 | PNG Test 3 | 4 | 5 |

PNG test

6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /property.c: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * dynamic properties 5 | * 6 | * Copyright (C) 2006 Michael Reinelt 7 | * Copyright (C) 2006 The LCD4Linux Team 8 | * 9 | * This file is part of LCD4Linux. 10 | * 11 | * LCD4Linux is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2, or (at your option) 14 | * any later version. 15 | * 16 | * LCD4Linux is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | 28 | /* 29 | * exported functions: 30 | * 31 | * void property_load (const char *section, const char *name, const char *defval, PROPERTY *prop) 32 | * initializes and loads a property from the config file and pre-compiles it 33 | * 34 | * void property_free (PROPERTY *prop) 35 | * frees all property allocations 36 | * 37 | * int property_eval(PROPERTY * prop) 38 | * evaluates a property; returns 1 if value has changed 39 | * 40 | * double P2N(PROPERTY * prop) 41 | * returns a (already evaluated) property as number 42 | * 43 | * char *P2S(PROPERTY * prop) 44 | * returns a (already evaluated) property as string 45 | * 46 | */ 47 | 48 | 49 | #include "config.h" 50 | 51 | #include 52 | #include 53 | #include 54 | 55 | #include "debug.h" 56 | #include "cfg.h" 57 | #include "evaluator.h" 58 | #include "property.h" 59 | 60 | #ifdef WITH_DMALLOC 61 | #include 62 | #endif 63 | 64 | 65 | void property_load(const char *section, const char *name, const char *defval, PROPERTY * prop) 66 | { 67 | char *expression; 68 | 69 | /* initialize structure */ 70 | prop->valid = 0; 71 | prop->name = NULL; 72 | prop->expression = NULL; 73 | prop->compiled = NULL; 74 | DelResult(&prop->result); 75 | 76 | /* remember the name */ 77 | prop->name = strdup(name); 78 | 79 | /* load expression from config, but do not evaluate it */ 80 | expression = cfg_get_raw(section, name, NULL); 81 | 82 | if (expression == NULL) { 83 | if (defval != NULL && *defval != '\0') 84 | debug("Notice: using default value <%s> for property '%s.%s'", defval, section, name); 85 | prop->expression = (char *) defval; 86 | } else { 87 | prop->valid = 1; 88 | prop->expression = expression; 89 | } 90 | 91 | /* pre-compile the expression */ 92 | Compile(prop->expression, &prop->compiled); 93 | 94 | } 95 | 96 | 97 | int property_valid(PROPERTY * prop) 98 | { 99 | return prop->valid; 100 | } 101 | 102 | 103 | int property_eval(PROPERTY * prop) 104 | { 105 | RESULT old; 106 | int update; 107 | 108 | /* this is a bit ugly: we need to remember the old value */ 109 | old.type = prop->result.type; 110 | old.size = prop->result.size; 111 | old.number = prop->result.number; 112 | old.string = prop->result.string != NULL ? strdup(prop->result.string) : NULL; 113 | 114 | DelResult(&prop->result); 115 | Eval(prop->compiled, &prop->result); 116 | 117 | /* check if property value has changed */ 118 | update = 1; 119 | if (prop->result.type & R_NUMBER && old.type & R_NUMBER && prop->result.number == old.number) { 120 | update = 0; 121 | } 122 | if (prop->result.type & R_STRING && old.type & R_STRING && prop->result.size == old.size) { 123 | if (prop->result.string == NULL && old.string == NULL) { 124 | update = 0; 125 | } else if (prop->result.string != NULL && old.string != NULL && strcmp(prop->result.string, old.string) == 0) { 126 | update = 0; 127 | } 128 | } 129 | 130 | if (old.string) 131 | free(old.string); 132 | 133 | return update; 134 | } 135 | 136 | 137 | double P2N(PROPERTY * prop) 138 | { 139 | if (prop == NULL) { 140 | error("Property: internal error: NULL property"); 141 | return 0.0; 142 | } 143 | return R2N(&prop->result); 144 | } 145 | 146 | 147 | char *P2S(PROPERTY * prop) 148 | { 149 | if (prop == NULL) { 150 | error("Property: internal error: NULL property"); 151 | return NULL; 152 | } 153 | return R2S(&prop->result); 154 | } 155 | 156 | void property_free(PROPERTY * prop) 157 | { 158 | if (prop->name != NULL) { 159 | free(prop->name); 160 | prop->name = NULL; 161 | } 162 | 163 | if (prop->expression != NULL) { 164 | /* do *not* free expression */ 165 | prop->expression = NULL; 166 | } 167 | 168 | if (prop->compiled != NULL) { 169 | free(prop->compiled); 170 | prop->compiled = NULL; 171 | } 172 | 173 | DelResult(&prop->result); 174 | } 175 | -------------------------------------------------------------------------------- /property.h: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * dynamic properties 5 | * 6 | * Copyright (C) 2006 Michael Reinelt 7 | * Copyright (C) 2006 The LCD4Linux Team 8 | * 9 | * This file is part of LCD4Linux. 10 | * 11 | * LCD4Linux is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2, or (at your option) 14 | * any later version. 15 | * 16 | * LCD4Linux is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | 28 | #ifndef _PROPERTY_H_ 29 | #define _PROPERTY_H_ 30 | 31 | #include "evaluator.h" 32 | 33 | 34 | typedef struct { 35 | int valid; 36 | char *name; 37 | char *expression; 38 | void *compiled; 39 | RESULT result; 40 | } PROPERTY; 41 | 42 | 43 | void property_load(const char *section, const char *name, const char *defval, PROPERTY * prop); 44 | int property_valid(PROPERTY * prop); 45 | int property_eval(PROPERTY * prop); 46 | double P2N(PROPERTY * prop); 47 | char *P2S(PROPERTY * prop); 48 | void property_free(PROPERTY * prop); 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /qprintf.h: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * simple but quick snprintf() replacement 5 | * 6 | * Copyright (C) 2004 Michael Reinelt 7 | * Copyright (C) 2004 The LCD4Linux Team 8 | * 9 | * derived from a patch from Martin Hejl which is 10 | * Copyright (C) 2003 Martin Hejl (martin@hejl.de) 11 | * 12 | * This file is part of LCD4Linux. 13 | * 14 | * LCD4Linux is free software; you can redistribute it and/or modify 15 | * it under the terms of the GNU General Public License as published by 16 | * the Free Software Foundation; either version 2, or (at your option) 17 | * any later version. 18 | * 19 | * LCD4Linux is distributed in the hope that it will be useful, 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | * GNU General Public License for more details. 23 | * 24 | * You should have received a copy of the GNU General Public License 25 | * along with this program; if not, write to the Free Software 26 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 27 | * 28 | */ 29 | 30 | #ifndef _QPRINTF_H_ 31 | #define _QPRINTF_H_ 32 | 33 | /* size_t */ 34 | #include 35 | 36 | int qprintf(char *str, size_t size, const char *format, ...); 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /rgb.c: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * generic color handling 5 | * 6 | * Copyright (C) 2005 Michael Reinelt 7 | * Copyright (C) 2005 The LCD4Linux Team 8 | * 9 | * This file is part of LCD4Linux. 10 | * 11 | * LCD4Linux is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2, or (at your option) 14 | * any later version. 15 | * 16 | * LCD4Linux is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | 28 | #include "config.h" 29 | 30 | #include 31 | #include 32 | 33 | #include "rgb.h" 34 | 35 | 36 | int color2RGBA(const char *color, RGBA * C) 37 | { 38 | char *e; 39 | unsigned long l; 40 | 41 | if (color == NULL || *color == '\0') { 42 | return -1; 43 | } 44 | 45 | l = strtoul(color, &e, 16); 46 | if (e != NULL && *e != '\0') { 47 | return -1; 48 | } 49 | 50 | if (strlen(color) == 8) { 51 | /* RGBA */ 52 | C->R = (l >> 24) & 0xff; 53 | C->G = (l >> 16) & 0xff; 54 | C->B = (l >> 8) & 0xff; 55 | C->A = (l >> 0) & 0xff; 56 | } else { 57 | /* RGB */ 58 | C->R = (l >> 16) & 0xff; 59 | C->G = (l >> 8) & 0xff; 60 | C->B = l & 0xff; 61 | C->A = 0xff; 62 | } 63 | return 0; 64 | } 65 | -------------------------------------------------------------------------------- /rgb.h: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * generic color handling 5 | * 6 | * Copyright (C) 2005 Michael Reinelt 7 | * Copyright (C) 2005 The LCD4Linux Team 8 | * 9 | * This file is part of LCD4Linux. 10 | * 11 | * LCD4Linux is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2, or (at your option) 14 | * any later version. 15 | * 16 | * LCD4Linux is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | 28 | #ifndef _RGB_H_ 29 | #define _RGB_H_ 30 | 31 | typedef struct { 32 | unsigned char R; 33 | unsigned char G; 34 | unsigned char B; 35 | unsigned char A; 36 | } RGBA; 37 | 38 | 39 | int color2RGBA(const char *color, RGBA * C); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /smoketest.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | # $Id$ 4 | # $URL$ 5 | 6 | 7 | rm -f smoketest.log lcd4linux 8 | 9 | make distclean 10 | ./bootstrap 11 | 12 | for driver in ASTUSB BeckmannEgle BWCT CrystalFontz Curses Cwlinux D4D DPF EA232graphic EFN FutabaVFD G15 GLCD2USB HD44780 IRLCD LCD2USB LCDLinux LCDTerm LEDMatrix LPH7508 LUIse LW_ABP M50530 MatrixOrbital MatrixOrbitalGX MilfordInstruments Noritake NULL Pertelian PHAnderson picoLCD picoLCDGraphic PNG PPM RouterBoard Sample SamsungSPF serdisplib SimpleLCD T6963 TeakLCM Trefon ULA200 USBHUB USBLCD WincorNixdorf X11; do 13 | 14 | make distclean 15 | ./configure --with-drivers=$driver 16 | make -s -j 8 17 | 18 | if [ -x lcd4linux ]; then 19 | echo "Success: drv_$driver" >>smoketest.log 20 | else 21 | echo "FAILED: drv_$driver" >>smoketest.log 22 | fi 23 | 24 | done 25 | 26 | for plugin in apm asterisk button_exec cpuinfo dbus diskstats dvb exec event fifo file gps hddtemp huawei i2c_sensors iconv imon isdn kvv loadavg meminfo mpd mpris_dbus mysql netdev netinfo pop3 ppp proc_stat python qnaplog sample seti statfs uname uptime w1retap wireless xmms; do 27 | 28 | make distclean 29 | ./configure --with-drivers=NULL --with-plugins=$plugin 30 | make -s -j 8 31 | 32 | if [ -x lcd4linux ]; then 33 | echo "Success: plugin_$plugin" >>smoketest.log 34 | else 35 | echo "FAILED: plugin_$plugin" >>smoketest.log 36 | fi 37 | 38 | done 39 | 40 | make distclean 41 | ./configure 42 | -------------------------------------------------------------------------------- /svn_version.h: -------------------------------------------------------------------------------- 1 | #define SVN_VERSION "1193" 2 | -------------------------------------------------------------------------------- /svn_version.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # $Id$ 4 | # $URL$ 5 | 6 | 7 | OLD_VERSION=`cat svn_version.h 2>/dev/null` 8 | 9 | if [ -d .svn ]; then 10 | NEW_VERSION="#define SVN_VERSION \"`svnversion -n`\"" 11 | fi 12 | 13 | if [ "$NEW_VERSION" != "$OLD_VERSION" ]; then 14 | echo $NEW_VERSION >svn_version.h 15 | fi 16 | -------------------------------------------------------------------------------- /thread.c: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * thread handling (mutex, shmem, ...) 5 | * 6 | * Copyright (C) 2004 Michael Reinelt 7 | * Copyright (C) 2004 The LCD4Linux Team 8 | * 9 | * parts of this code are based on the old XWindow driver which is 10 | * Copyright (C) 2000 Herbert Rosmanith 11 | * 12 | * This file is part of LCD4Linux. 13 | * 14 | * LCD4Linux is free software; you can redistribute it and/or modify 15 | * it under the terms of the GNU General Public License as published by 16 | * the Free Software Foundation; either version 2, or (at your option) 17 | * any later version. 18 | * 19 | * LCD4Linux is distributed in the hope that it will be useful, 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | * GNU General Public License for more details. 23 | * 24 | * You should have received a copy of the GNU General Public License 25 | * along with this program; if not, write to the Free Software 26 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 27 | * 28 | */ 29 | 30 | /* 31 | * exported functions: 32 | * 33 | * int mutex_create (void); 34 | * creates a mutex and treturns its ID 35 | * 36 | * void mutex_lock (int semid); 37 | * try to lock a mutex 38 | * 39 | * void mutex_unlock (int semid); 40 | * unlock a mutex 41 | * 42 | * void mutex_destroy (int semid); 43 | * release a mutex 44 | * 45 | * 46 | * int shm_create (void **buffer, int size); 47 | * create shared memory segment 48 | * 49 | * void shm_destroy (int shmid, void *buffer) ; 50 | * release shared memory segment 51 | * 52 | * int thread_create (char *name, void (*thread)(void *data), void *data); 53 | * create a new thread 54 | * 55 | */ 56 | 57 | 58 | #include "config.h" 59 | 60 | #include 61 | #include 62 | #include 63 | #include 64 | #include 65 | #include 66 | #include 67 | #include 68 | #include 69 | #include 70 | 71 | #include "debug.h" 72 | #include "thread.h" 73 | 74 | 75 | #ifdef WITH_DMALLOC 76 | #include 77 | #endif 78 | 79 | 80 | int thread_argc; 81 | char **thread_argv; 82 | 83 | 84 | /* glibc 2.1 requires defining semun ourselves */ 85 | #ifdef _SEM_SEMUN_UNDEFINED 86 | union semun { 87 | int val; 88 | struct semid_ds *buf; 89 | unsigned short int *array; 90 | struct seminfo *__buf; 91 | }; 92 | #endif 93 | 94 | 95 | int mutex_create(void) 96 | { 97 | int semid; 98 | union semun semun; 99 | 100 | semid = semget(IPC_PRIVATE, 1, 0); 101 | if (semid == -1) { 102 | error("fatal error: semget() failed: %s", strerror(errno)); 103 | return -1; 104 | } 105 | semun.val = 1; 106 | semctl(semid, 0, SETVAL, semun); 107 | 108 | return semid; 109 | } 110 | 111 | 112 | void mutex_lock(const int semid) 113 | { 114 | struct sembuf sembuf; 115 | sembuf.sem_num = 0; 116 | sembuf.sem_op = -1; 117 | sembuf.sem_flg = 0; 118 | semop(semid, &sembuf, 1); 119 | } 120 | 121 | 122 | void mutex_unlock(const int semid) 123 | { 124 | struct sembuf sembuf; 125 | sembuf.sem_num = 0; 126 | sembuf.sem_op = 1; 127 | sembuf.sem_flg = 0; 128 | semop(semid, &sembuf, 1); 129 | } 130 | 131 | 132 | void mutex_destroy(const int semid) 133 | { 134 | union semun arg; 135 | semctl(semid, 0, IPC_RMID, arg); 136 | } 137 | 138 | 139 | int shm_create(void **buffer, const int size) 140 | { 141 | int shmid; 142 | 143 | shmid = shmget(IPC_PRIVATE, size, SHM_R | SHM_W); 144 | if (shmid == -1) { 145 | error("fatal error: shmget() failed: %s", strerror(errno)); 146 | return -1; 147 | } 148 | 149 | *buffer = shmat(shmid, NULL, 0); 150 | if (*buffer == NULL) { 151 | error("fatal error: shmat() failed: %s", strerror(errno)); 152 | return -1; 153 | } 154 | 155 | return shmid; 156 | } 157 | 158 | 159 | void shm_destroy(const int shmid, const void *buffer) 160 | { 161 | shmdt(buffer); 162 | shmctl(shmid, IPC_RMID, NULL); 163 | } 164 | 165 | 166 | int thread_create(const char *name, void (*thread) (void *data), void *data) 167 | { 168 | pid_t pid; 169 | 170 | switch (pid = fork()) { 171 | case -1: 172 | error("fatal error: fork(%s) failed: %s", name, strerror(errno)); 173 | return -1; 174 | case 0: 175 | info("thread %s starting...", name); 176 | if (thread_argc > 0) { 177 | strncpy(thread_argv[0], name, strlen(thread_argv[0])); 178 | } 179 | thread(data); 180 | info("thread %s ended.", name); 181 | exit(0); 182 | default: 183 | info("forked process %d for thread %s", pid, name); 184 | } 185 | 186 | return pid; 187 | } 188 | 189 | 190 | int thread_destroy(const int pid) 191 | { 192 | return kill(pid, SIGKILL); 193 | } 194 | -------------------------------------------------------------------------------- /thread.h: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * thread handling (mutex, shmem, ...) 5 | * 6 | * Copyright (C) 2004 Michael Reinelt 7 | * Copyright (C) 2004 The LCD4Linux Team 8 | * 9 | * parts of this code are based on the old XWindow driver which is 10 | * Copyright (C) 2000 Herbert Rosmanith 11 | * 12 | * This file is part of LCD4Linux. 13 | * 14 | * LCD4Linux is free software; you can redistribute it and/or modify 15 | * it under the terms of the GNU General Public License as published by 16 | * the Free Software Foundation; either version 2, or (at your option) 17 | * any later version. 18 | * 19 | * LCD4Linux is distributed in the hope that it will be useful, 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | * GNU General Public License for more details. 23 | * 24 | * You should have received a copy of the GNU General Public License 25 | * along with this program; if not, write to the Free Software 26 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 27 | * 28 | */ 29 | 30 | #ifndef _THREAD_H_ 31 | #define _THREAD_H_ 32 | 33 | #ifdef __CYGWIN__ 34 | 35 | #ifndef HAVE_UNION_SEMUN 36 | union semun { 37 | int val; 38 | struct semid_ds *buf; 39 | unsigned short *array; 40 | }; 41 | #endif 42 | 43 | #ifndef SHM_R 44 | #define SHM_R 0400 45 | #endif 46 | #ifndef SHM_W 47 | #define SHM_W 0660 48 | #endif 49 | 50 | #endif 51 | 52 | extern int thread_argc; 53 | extern char **thread_argv; 54 | 55 | int mutex_create(void); 56 | void mutex_lock(const int semid); 57 | void mutex_unlock(const int semid); 58 | void mutex_destroy(const int semid); 59 | 60 | int shm_create(void **buffer, const int size); 61 | void shm_destroy(const int shmid, const void *buffer); 62 | 63 | int thread_create(const char *name, void (*thread) (void *data), void *data); 64 | int thread_destroy(const int pid); 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /timer.h: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * generic timer handling 5 | * 6 | * Copyright (C) 2003, 2004 Michael Reinelt 7 | * Copyright (C) 2004 The LCD4Linux Team 8 | * 9 | * This file is part of LCD4Linux. 10 | * 11 | * LCD4Linux is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2, or (at your option) 14 | * any later version. 15 | * 16 | * LCD4Linux is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | 28 | #ifndef _TIMER_H_ 29 | #define _TIMER_H_ 30 | 31 | #define TIMER_ACTIVE 1 32 | #define TIMER_INACTIVE 0 33 | 34 | #include 35 | 36 | int timer_add(void (*callback) (void *data), void *data, const int interval, const int one_shot); 37 | 38 | int timer_add_late(void (*callback) (void *data), void *data, const int interval, const int one_shot); 39 | 40 | int timer_process(struct timespec *delay); 41 | 42 | int timer_remove(void (*callback) (void *data), void *data); 43 | 44 | void timer_exit(void); 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /timer_group.h: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * generic grouping of widget timers that have been set to the same 5 | * update interval, thus allowing synchronized updates 6 | * 7 | * Copyright (C) 2010 Martin Zuther 8 | * Copyright (C) 2010 The LCD4Linux Team 9 | * 10 | * This file is part of LCD4Linux. 11 | * 12 | * LCD4Linux is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License as published by 14 | * the Free Software Foundation; either version 2, or (at your option) 15 | * any later version. 16 | * 17 | * LCD4Linux is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | * GNU General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * along with this program; if not, write to the Free Software 24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 25 | * 26 | */ 27 | 28 | 29 | #ifndef _TIMER_GROUP_H_ 30 | #define _TIMER_GROUP_H_ 31 | 32 | 33 | void timer_process_group(void *data); 34 | 35 | void timer_exit_group(void); 36 | 37 | int timer_add_widget(void (*callback) (void *data), void *data, const int interval, const int one_shot); 38 | 39 | int timer_remove_widget(void (*callback) (void *data), void *data); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /tux.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jmccrohan/lcd4linux/cb69a93a4501b2a58e1f991c953b3c58d6ceeb67/tux.png -------------------------------------------------------------------------------- /udelay.c: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * short delays 5 | * 6 | * Copyright (C) 1999, 2000 Michael Reinelt 7 | * Copyright (C) 2004 The LCD4Linux Team 8 | * 9 | * This file is part of LCD4Linux. 10 | * 11 | * LCD4Linux is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2, or (at your option) 14 | * any later version. 15 | * 16 | * LCD4Linux is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | /* 28 | * 29 | * exported fuctions: 30 | * 31 | * void udelay_init (void) 32 | * selects delay method (gettimeofday() ord rdtsc() according 33 | * to processor features 34 | * 35 | * unsigned long timing (const char *driver, const char *section, const char *name, const int defval, const char *unit); 36 | * returns a timing value from config or the default value 37 | * 38 | * void udelay (unsigned long usec) 39 | * delays program execution for usec microseconds 40 | * uses global variable 'loops_per_usec', which has to be set before. 41 | * This function does busy-waiting! so use only for delays smaller 42 | * than 10 msec 43 | * 44 | */ 45 | 46 | #include "config.h" 47 | #include 48 | #include 49 | 50 | 51 | #include 52 | #include 53 | #include 54 | #include 55 | #include 56 | #include 57 | 58 | 59 | #include "debug.h" 60 | #include "cfg.h" 61 | #include "qprintf.h" 62 | #include "udelay.h" 63 | 64 | 65 | 66 | void udelay_init(void) 67 | { 68 | info("udelay: using gettimeofday() delay loop"); 69 | } 70 | 71 | 72 | unsigned long timing(const char *driver, const char *section, const char *name, const int defval, const char *unit) 73 | { 74 | char sec[256]; 75 | int fuzz, val; 76 | 77 | qprintf(sec, sizeof(sec), "%s.Timing", section); 78 | 79 | /* fuzz all timings by given factor */ 80 | cfg_number(sec, "fuzz", 100, 1, -1, &fuzz); 81 | 82 | cfg_number(sec, name, defval, 0, -1, &val); 83 | val = val * fuzz / 100; 84 | 85 | if (val != defval) { 86 | if (fuzz != 100) { 87 | info("%s: timing: %6s = %5d %s (default %d %s, fuzz %d)", driver, name, val, unit, defval, unit, fuzz); 88 | } else { 89 | info("%s: timing: %6s = %5d %s (default %d %s)", driver, name, val, unit, defval, unit); 90 | } 91 | } else { 92 | info("%s: timing: %6s = %5d %s (default)", driver, name, defval, unit); 93 | } 94 | return val; 95 | } 96 | 97 | 98 | void ndelay(const unsigned long nsec) 99 | { 100 | 101 | struct timeval now, end; 102 | 103 | gettimeofday(&end, NULL); 104 | end.tv_usec += (nsec + 999) / 1000; 105 | while (end.tv_usec > 1000000) { 106 | end.tv_usec -= 1000000; 107 | end.tv_sec++; 108 | } 109 | 110 | do { 111 | rep_nop(); 112 | gettimeofday(&now, NULL); 113 | } while (now.tv_sec == end.tv_sec ? now.tv_usec < end.tv_usec : now.tv_sec < end.tv_sec); 114 | } 115 | -------------------------------------------------------------------------------- /udelay.h: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * short delays 5 | * 6 | * Copyright (C) 1999, 2000 Michael Reinelt 7 | * Copyright (C) 2004 The LCD4Linux Team 8 | * 9 | * This file is part of LCD4Linux. 10 | * 11 | * LCD4Linux is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2, or (at your option) 14 | * any later version. 15 | * 16 | * LCD4Linux is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | #ifndef _UDELAY_H_ 28 | #define _UDELAY_H_ 29 | 30 | /* stolen from linux/asm-i386/processor.h */ 31 | /* REP NOP (PAUSE) is a good thing to insert into busy-wait loops. */ 32 | static inline void rep_nop(void) 33 | { 34 | #if defined(__i386) || defined(__i386__) || defined(__AMD64__) || defined(__x86_64__) || defined(__amd64__) 35 | /* intel or amd64 arch, the "rep" and "nop" opcodes are available */ 36 | __asm__ __volatile__("rep; nop"); 37 | #else 38 | /* other Arch, maybe add core cooldown code here, too. */ 39 | do { 40 | } while (0); 41 | #endif 42 | } 43 | 44 | void udelay_init(void); 45 | unsigned long timing(const char *driver, const char *section, const char *name, const int defval, const char *unit); 46 | void ndelay(const unsigned long nsec); 47 | 48 | #define udelay(usec) ndelay(usec*1000) 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /usbhub.conf: -------------------------------------------------------------------------------- 1 | # $Id$ 2 | # $URL$ 3 | 4 | Variables { 5 | tick 50 6 | netstep 0.5 7 | diskstep 1.5 8 | } 9 | 10 | Display SitecomHUB { 11 | Driver 'USBHUB' 12 | Vendor '0x04b4' 13 | Product '0x6560' 14 | } 15 | 16 | Display TyphoonHUB { 17 | Driver 'USBHUB' 18 | Vendor '0x0409' 19 | Product '0x0058' 20 | } 21 | 22 | 23 | Widget GPO_Test300 { 24 | class 'GPO' 25 | expression 2+(1+test::onoff(1))/2 26 | update 300 27 | } 28 | Widget GPO_Test400 { 29 | class 'GPO' 30 | expression 2+(1+test::onoff(2))/2 31 | update 400 32 | } 33 | Widget GPO_Test500 { 34 | class 'GPO' 35 | expression 2+(1+test::onoff(3))/2 36 | update 500 37 | } 38 | Widget GPO_Test600 { 39 | class 'GPO' 40 | expression 2+(1+test::onoff(4))/2 41 | update 600 42 | } 43 | 44 | 45 | # Display network activity as pulse duration on the hub leds. 46 | # currently configured to 47 | # 48 | # 0 % pulse width : traffic < exp(10) == 22kbyte/sec 49 | # 50 % pulse width : traffic about exp(13.5) == 730kbyte/sec 50 | # 100 % pulse width : traffic > exp(16) == 8886kbyte/sec 51 | # 52 | # Which is quite suitable for a 100mbit network. 53 | 54 | Widget Net_RX { 55 | class 'GPO' 56 | expression (exp(10+test::bar(1,6,0,0.5)) < netdev('eth0', 'Rx_bytes', (6/netstep)*2*tick))?2:3 57 | update tick 58 | } 59 | Widget Net_TX { 60 | class 'GPO' 61 | expression (exp(10+test::bar(2,6,0,0.5)) < netdev('eth0', 'Tx_bytes', (6/netstep)*2*tick))?2:3 62 | update tick 63 | } 64 | 65 | # As above, but for disk read/writes, pwm for 0bytes/sec .. 33MB/sec (e^9 * 4096) 66 | Widget SDA_read { 67 | class 'GPO' 68 | expression (exp(test::bar(3,9,0,diskstep)) < diskstats('sda', 'read_sectors', (9/diskstep)*2*tick))?2:3 69 | update tick 70 | } 71 | Widget SDA_write{ 72 | class 'GPO' 73 | expression (exp(test::bar(4,9,0,diskstep)) < diskstats('sda', 'write_sectors', (9/diskstep)*2*tick))?2:3 74 | update tick 75 | } 76 | 77 | Layout TestHUB { 78 | GPO1 'GPO_Test300' 79 | GPO2 'GPO_Test400' 80 | GPO3 'GPO_Test500' 81 | GPO4 'GPO_Test600' 82 | } 83 | 84 | Layout NetAndHDD { 85 | GPO1 'Net_RX' 86 | GPO2 'Net_TX' 87 | GPO3 'SDA_read' 88 | GPO4 'SDA_write' 89 | } 90 | 91 | #Display 'SitecomHUB' 92 | Display 'TyphoonHUB' 93 | #Layout 'TestHUB' 94 | Layout 'NetAndHDD' 95 | -------------------------------------------------------------------------------- /widget.h: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * generic widget handling 5 | * 6 | * Copyright (C) 2003, 2004 Michael Reinelt 7 | * Copyright (C) 2004 The LCD4Linux Team 8 | * 9 | * This file is part of LCD4Linux. 10 | * 11 | * LCD4Linux is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2, or (at your option) 14 | * any later version. 15 | * 16 | * LCD4Linux is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | 28 | #ifndef _WIDGET_H_ 29 | #define _WIDGET_H_ 30 | 31 | #include "rgb.h" 32 | 33 | 34 | struct WIDGET; /* forward declaration */ 35 | 36 | 37 | typedef struct WIDGET_CLASS { 38 | char *name; 39 | int type; 40 | int (*init) (struct WIDGET * Self); 41 | int (*draw) (struct WIDGET * Self); 42 | int (*find) (struct WIDGET * Self, void *needle); 43 | int (*quit) (struct WIDGET * Self); 44 | } WIDGET_CLASS; 45 | 46 | 47 | typedef struct WIDGET { 48 | char *name; 49 | WIDGET_CLASS *class; 50 | struct WIDGET *parent; 51 | RGBA fg_color; 52 | RGBA bg_color; 53 | int fg_valid; 54 | int bg_valid; 55 | int layer; 56 | int row; 57 | int col; 58 | void *data; 59 | int x2; /* x of opposite corner, -1 for no display widget */ 60 | int y2; /* y of opposite corner, -1 for no display widget */ 61 | } WIDGET; 62 | 63 | 64 | #define WIDGET_TYPE_RC 1 65 | #define WIDGET_TYPE_XY 2 66 | #define WIDGET_TYPE_GPO 3 67 | #define WIDGET_TYPE_TIMER 4 68 | #define WIDGET_TYPE_KEYPAD 5 69 | 70 | 71 | int widget_register(WIDGET_CLASS * widget); 72 | void widget_unregister(void); 73 | int intersect(WIDGET * w1, WIDGET * w2); 74 | int widget_add(const char *name, const int type, const int layer, const int row, const int col); 75 | WIDGET *widget_find(int type, void *needle); 76 | int widget_color(const char *section, const char *name, const char *key, RGBA * C); 77 | 78 | #undef MIN 79 | #define MIN(a,b) ((a) < (b) ? (a) : (b)) 80 | #undef MAX 81 | #define MAX(a,b) ((a) > (b) ? (a) : (b)) 82 | #define NOCOORD (-1) 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /widget_bar.h: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * bar widget handling 5 | * 6 | * Copyright (C) 2003, 2004 Michael Reinelt 7 | * Copyright (C) 2004 The LCD4Linux Team 8 | * 9 | * This file is part of LCD4Linux. 10 | * 11 | * LCD4Linux is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2, or (at your option) 14 | * any later version. 15 | * 16 | * LCD4Linux is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | 28 | #ifndef _WIDGET_BAR_H_ 29 | #define _WIDGET_BAR_H_ 30 | 31 | #include "property.h" 32 | #include "widget.h" 33 | #include "rgb.h" 34 | 35 | typedef enum { DIR_EAST = 1, DIR_WEST = 2, DIR_NORTH = 4, DIR_SOUTH = 8 } DIRECTION; 36 | typedef enum { STYLE_HOLLOW = 1, STYLE_FIRST = 2, STYLE_LAST = 4 } STYLE; 37 | 38 | typedef struct WIDGET_BAR { 39 | PROPERTY expression1; /* value (length) of upper half */ 40 | PROPERTY expression2; /* value (length) of lower half */ 41 | PROPERTY expr_min; /* explicit minimum value */ 42 | PROPERTY expr_max; /* explicit maximum value */ 43 | DIRECTION direction; /* bar direction */ 44 | STYLE style; /* bar style (hollow) */ 45 | int length; /* bar length */ 46 | int update; /* update interval (msec) */ 47 | double val1; /* bar value, 0.0 ... 1.0 */ 48 | double val2; /* bar value, 0.0 ... 1.0 */ 49 | double min; /* minimum value */ 50 | double max; /* maximum value */ 51 | RGBA color[2]; /* bar colors */ 52 | int color_valid[2]; /* bar color is valid */ 53 | } WIDGET_BAR; 54 | 55 | 56 | extern WIDGET_CLASS Widget_Bar; 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /widget_gpo.c: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * GPO widget handling 5 | * 6 | * Copyright (C) 2005 Michael Reinelt 7 | * Copyright (C) 2005, 2006, 2007 The LCD4Linux Team 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2, or (at your option) 12 | * any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 | * 23 | */ 24 | 25 | /* 26 | * exported functions: 27 | * 28 | * WIDGET_CLASS Widget_GPO 29 | * the GPO widget 30 | * 31 | */ 32 | 33 | 34 | #include "config.h" 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | #include "debug.h" 42 | #include "cfg.h" 43 | #include "property.h" 44 | #include "timer_group.h" 45 | #include "widget.h" 46 | #include "widget_gpo.h" 47 | 48 | #ifdef WITH_DMALLOC 49 | #include 50 | #endif 51 | 52 | 53 | void widget_gpo_update(void *Self) 54 | { 55 | WIDGET *W = (WIDGET *) Self; 56 | WIDGET_GPO *GPO = W->data; 57 | 58 | /* evaluate properties */ 59 | property_eval(&GPO->expression); 60 | property_eval(&GPO->update); 61 | 62 | /* finally, draw it! */ 63 | if (W->class->draw) 64 | W->class->draw(W); 65 | 66 | /* add a new one-shot timer */ 67 | if (P2N(&GPO->update) > 0) { 68 | timer_add_widget(widget_gpo_update, Self, P2N(&GPO->update), 1); 69 | } 70 | 71 | } 72 | 73 | 74 | int widget_gpo_init(WIDGET * Self) 75 | { 76 | char *section; 77 | WIDGET_GPO *GPO; 78 | 79 | /* prepare config section */ 80 | /* strlen("Widget:")=7 */ 81 | section = malloc(strlen(Self->name) + 8); 82 | strcpy(section, "Widget:"); 83 | strcat(section, Self->name); 84 | 85 | GPO = malloc(sizeof(WIDGET_GPO)); 86 | memset(GPO, 0, sizeof(WIDGET_GPO)); 87 | 88 | /* load properties */ 89 | property_load(section, "expression", NULL, &GPO->expression); 90 | property_load(section, "update", "1000", &GPO->update); 91 | 92 | /* sanity checks */ 93 | if (!property_valid(&GPO->expression)) { 94 | error("Warning: widget %s has no expression", section); 95 | } 96 | 97 | free(section); 98 | Self->data = GPO; 99 | /* no display dimension */ 100 | Self->x2 = NOCOORD; 101 | Self->y2 = NOCOORD; 102 | 103 | /* fire it the first time */ 104 | widget_gpo_update(Self); 105 | 106 | return 0; 107 | } 108 | 109 | 110 | int widget_gpo_quit(WIDGET * Self) 111 | { 112 | if (Self && Self->data) { 113 | WIDGET_GPO *GPO = Self->data; 114 | property_free(&GPO->expression); 115 | property_free(&GPO->update); 116 | free(Self->data); 117 | Self->data = NULL; 118 | } 119 | return 0; 120 | } 121 | 122 | 123 | 124 | WIDGET_CLASS Widget_GPO = { 125 | .name = "gpo", 126 | .type = WIDGET_TYPE_GPO, 127 | .init = widget_gpo_init, 128 | .draw = NULL, 129 | .quit = widget_gpo_quit, 130 | }; 131 | -------------------------------------------------------------------------------- /widget_gpo.h: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * GPO widget handling 5 | * 6 | * Copyright (C) 2005 Michael Reinelt 7 | * Copyright (C) 2005, 2006, 2007 The LCD4Linux Team 8 | * 9 | * This file is part of LCD4Linux. 10 | * 11 | * LCD4Linux is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2, or (at your option) 14 | * any later version. 15 | * 16 | * LCD4Linux is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | 28 | #ifndef _WIDGET_GPO_H_ 29 | #define _WIDGET_GPO_H_ 30 | 31 | #include "property.h" 32 | #include "widget.h" 33 | 34 | typedef struct WIDGET_GPO { 35 | PROPERTY expression; /* main GPO expression */ 36 | PROPERTY update; /* update interval (msec) */ 37 | } WIDGET_GPO; 38 | 39 | 40 | extern WIDGET_CLASS Widget_GPO; 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /widget_icon.c: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * icon widget handling 5 | * 6 | * Copyright (C) 2003, 2004 Michael Reinelt 7 | * Copyright (C) 2004 The LCD4Linux Team 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2, or (at your option) 12 | * any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 | * 23 | */ 24 | 25 | /* 26 | * exported functions: 27 | * 28 | * WIDGET_CLASS Widget_Icon 29 | * the icon widget 30 | * 31 | */ 32 | 33 | 34 | #include "config.h" 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | #include "debug.h" 42 | #include "cfg.h" 43 | #include "qprintf.h" 44 | #include "property.h" 45 | #include "timer_group.h" 46 | #include "widget.h" 47 | #include "widget_icon.h" 48 | 49 | #ifdef WITH_DMALLOC 50 | #include 51 | #endif 52 | 53 | /* icons size is same as char size */ 54 | extern int XRES, YRES; 55 | 56 | static void widget_icon_read_bitmap(const char *section, WIDGET_ICON * Icon) 57 | { 58 | int row, n; 59 | char key[15]; 60 | char *val, *v; 61 | unsigned char *map; 62 | 63 | for (row = 0; row < YRES; row++) { 64 | qprintf(key, sizeof(key), "Bitmap.Row%d", row + 1); 65 | val = cfg_get(section, key, ""); 66 | map = Icon->bitmap + row; 67 | n = 0; 68 | for (v = val; *v != '\0'; v++) { 69 | if (n >= Icon->maxmap) { 70 | Icon->maxmap++; 71 | Icon->bitmap = realloc(Icon->bitmap, Icon->maxmap * YRES * sizeof(char)); 72 | memset(Icon->bitmap + n * YRES, 0, YRES * sizeof(char)); 73 | map = Icon->bitmap + n * YRES + row; 74 | } 75 | switch (*v) { 76 | case '|': 77 | n++; 78 | map += YRES; 79 | break; 80 | case '*': 81 | (*map) <<= 1; 82 | (*map) |= 1; 83 | break; 84 | default: 85 | (*map) <<= 1; 86 | } 87 | } 88 | free(val); 89 | } 90 | } 91 | 92 | 93 | void widget_icon_update(void *Self) 94 | { 95 | WIDGET *W = (WIDGET *) Self; 96 | WIDGET_ICON *Icon = W->data; 97 | 98 | /* process the parent only */ 99 | if (W->parent == NULL) { 100 | 101 | /* evaluate properties */ 102 | property_eval(&Icon->speed); 103 | property_eval(&Icon->visible); 104 | property_eval(&Icon->frame); 105 | 106 | int frame = P2N(&Icon->frame); 107 | if ((frame >= 0) && (frame <= Icon->maxmap)) { 108 | /* select icon bitmap by evaluated frame number */ 109 | Icon->curmap = frame; 110 | } else { 111 | /* rotate icon bitmap */ 112 | Icon->curmap++; 113 | if (Icon->curmap >= Icon->maxmap) 114 | Icon->curmap = 0; 115 | } 116 | } 117 | 118 | /* finally, draw it! */ 119 | if (W->class->draw) 120 | W->class->draw(W); 121 | 122 | /* add a new one-shot timer */ 123 | if (P2N(&Icon->speed) > 0) { 124 | timer_add_widget(widget_icon_update, Self, P2N(&Icon->speed), 1); 125 | } 126 | } 127 | 128 | 129 | 130 | int widget_icon_init(WIDGET * Self) 131 | { 132 | char *section; 133 | WIDGET_ICON *Icon; 134 | 135 | /* re-use the parent if one exists */ 136 | if (Self->parent == NULL) { 137 | 138 | /* prepare config section */ 139 | /* strlen("Widget:")=7 */ 140 | section = malloc(strlen(Self->name) + 8); 141 | strcpy(section, "Widget:"); 142 | strcat(section, Self->name); 143 | 144 | Icon = malloc(sizeof(WIDGET_ICON)); 145 | memset(Icon, 0, sizeof(WIDGET_ICON)); 146 | 147 | /* load properties */ 148 | property_load(section, "speed", "100", &Icon->speed); 149 | property_load(section, "visible", "1", &Icon->visible); 150 | property_load(section, "frame", "-1", &Icon->frame); 151 | 152 | /* read bitmap */ 153 | widget_icon_read_bitmap(section, Icon); 154 | 155 | free(section); 156 | Self->data = Icon; 157 | Self->x2 = Self->col + 1; 158 | Self->y2 = Self->row + 1; 159 | 160 | /* as the speed is evaluatod on every call, we use 'one-shot'-timers. */ 161 | /* The timer will be reactivated on every call to widget_icon_update(). */ 162 | /* We do the initial call here... */ 163 | Icon->prvmap = -1; 164 | 165 | /* reset ascii */ 166 | Icon->ascii = -1; 167 | 168 | } else { 169 | 170 | /* re-use the parent */ 171 | Self->data = Self->parent->data; 172 | 173 | } 174 | 175 | /* just do it! */ 176 | widget_icon_update(Self); 177 | 178 | return 0; 179 | } 180 | 181 | 182 | int widget_icon_quit(WIDGET * Self) 183 | { 184 | if (Self) { 185 | /* do not deallocate child widget! */ 186 | if (Self->parent == NULL) { 187 | if (Self->data) { 188 | WIDGET_ICON *Icon = Self->data; 189 | property_free(&Icon->speed); 190 | property_free(&Icon->visible); 191 | property_free(&Icon->frame); 192 | if (Icon->bitmap) 193 | free(Icon->bitmap); 194 | free(Self->data); 195 | Self->data = NULL; 196 | } 197 | } 198 | } 199 | 200 | return 0; 201 | 202 | } 203 | 204 | 205 | 206 | WIDGET_CLASS Widget_Icon = { 207 | .name = "icon", 208 | .type = WIDGET_TYPE_RC, 209 | .init = widget_icon_init, 210 | .draw = NULL, 211 | .quit = widget_icon_quit, 212 | }; 213 | -------------------------------------------------------------------------------- /widget_icon.h: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * icon widget handling 5 | * 6 | * Copyright (C) 2003, 2004 Michael Reinelt 7 | * Copyright (C) 2004 The LCD4Linux Team 8 | * 9 | * This file is part of LCD4Linux. 10 | * 11 | * LCD4Linux is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2, or (at your option) 14 | * any later version. 15 | * 16 | * LCD4Linux is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | 28 | #ifndef _WIDGET_ICON_H_ 29 | #define _WIDGET_ICON_H_ 30 | 31 | #include "property.h" 32 | #include "widget.h" 33 | 34 | typedef struct WIDGET_ICON { 35 | PROPERTY speed; /* update interval (msec) */ 36 | PROPERTY visible; /* icon visible? */ 37 | PROPERTY frame; /* evaluated expression of frame number (optional) */ 38 | int ascii; /* ascii code of icon (depends on the driver) */ 39 | int curmap; /* current bitmap sequence */ 40 | int prvmap; /* previous bitmap sequence */ 41 | int maxmap; /* number of bitmap sequences */ 42 | unsigned char *bitmap; /* bitmaps of (animated) icon */ 43 | } WIDGET_ICON; 44 | 45 | 46 | extern WIDGET_CLASS Widget_Icon; 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /widget_image.h: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * image widget handling 5 | * 6 | * Copyright (C) 2006 Michael Reinelt 7 | * Copyright (C) 2006 The LCD4Linux Team 8 | * 9 | * This file is part of LCD4Linux. 10 | * 11 | * LCD4Linux is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2, or (at your option) 14 | * any later version. 15 | * 16 | * LCD4Linux is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | 28 | #ifndef _WIDGET_IMAGE_H_ 29 | #define _WIDGET_IMAGE_H_ 30 | 31 | #include "property.h" 32 | #include "widget.h" 33 | #include "rgb.h" 34 | 35 | typedef struct WIDGET_IMAGE { 36 | void *gdImage; /* raw gd image */ 37 | RGBA *bitmap; /* image bitmap */ 38 | int width, height; /* size of the image */ 39 | PROPERTY file; /* image filename */ 40 | PROPERTY update; /* update interval */ 41 | PROPERTY reload; /* reload image on update? */ 42 | PROPERTY visible; /* image visible? */ 43 | PROPERTY inverted; /* image inverted? */ 44 | } WIDGET_IMAGE; 45 | 46 | extern WIDGET_CLASS Widget_Image; 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /widget_keypad.c: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * keypad widget handling 5 | * 6 | * Copyright (C) 2006 Chris Maj 7 | * Copyright (C) 2006 The LCD4Linux Team 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2, or (at your option) 12 | * any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 | * 23 | */ 24 | 25 | /* 26 | * exported functions: 27 | * 28 | * WIDGET_CLASS Widget_Keypad 29 | * the keypad widget 30 | * 31 | */ 32 | 33 | 34 | #include "config.h" 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | #include "debug.h" 42 | #include "cfg.h" 43 | #include "property.h" 44 | #include "timer.h" 45 | #include "widget.h" 46 | #include "widget_keypad.h" 47 | 48 | #ifdef WITH_DMALLOC 49 | #include 50 | #endif 51 | 52 | 53 | int widget_keypad_draw(WIDGET * Self) 54 | { 55 | WIDGET_KEYPAD *keypad = Self->data; 56 | 57 | /* evaluate properties */ 58 | property_eval(&keypad->expression); 59 | 60 | return P2N(&keypad->expression); 61 | } 62 | 63 | 64 | int widget_keypad_init(WIDGET * Self) 65 | { 66 | char *section; 67 | char *c; 68 | WIDGET_KEYPAD *keypad; 69 | 70 | /* prepare config section */ 71 | /* strlen("Widget:")=7 */ 72 | section = malloc(strlen(Self->name) + 8); 73 | strcpy(section, "Widget:"); 74 | strcat(section, Self->name); 75 | 76 | keypad = malloc(sizeof(WIDGET_KEYPAD)); 77 | memset(keypad, 0, sizeof(WIDGET_KEYPAD)); 78 | 79 | /* load properties */ 80 | property_load(section, "expression", NULL, &keypad->expression); 81 | 82 | /* state: pressed (default), released */ 83 | c = cfg_get(section, "state", "pressed"); 84 | if (!strcasecmp(c, "released")) 85 | keypad->key = WIDGET_KEY_RELEASED; 86 | else 87 | keypad->key = WIDGET_KEY_PRESSED; 88 | 89 | /* position: confirm (default), up, down, left, right, cancel */ 90 | c = cfg_get(section, "position", "confirm"); 91 | if (!strcasecmp(c, "up")) 92 | keypad->key += WIDGET_KEY_UP; 93 | else if (!strcasecmp(c, "down")) 94 | keypad->key += WIDGET_KEY_DOWN; 95 | else if (!strcasecmp(c, "left")) 96 | keypad->key += WIDGET_KEY_LEFT; 97 | else if (!strcasecmp(c, "right")) 98 | keypad->key += WIDGET_KEY_RIGHT; 99 | else if (!strcasecmp(c, "cancel")) 100 | keypad->key += WIDGET_KEY_CANCEL; 101 | else 102 | keypad->key += WIDGET_KEY_CONFIRM; 103 | 104 | free(section); 105 | Self->data = keypad; 106 | Self->x2 = NOCOORD; 107 | Self->y2 = NOCOORD; 108 | 109 | return 0; 110 | } 111 | 112 | int widget_keypad_find(WIDGET * Self, void *needle) 113 | { 114 | WIDGET_KEYPAD *keypad; 115 | KEYPADKEY key = *(KEYPADKEY *) needle; 116 | 117 | if (Self && Self->data) { 118 | keypad = Self->data; 119 | if (keypad->key == key) 120 | return 0; 121 | } 122 | 123 | return -1; 124 | } 125 | 126 | int widget_keypad_quit(WIDGET * Self) 127 | { 128 | if (Self && Self->data) { 129 | WIDGET_KEYPAD *keypad = Self->data; 130 | property_free(&keypad->expression); 131 | free(Self->data); 132 | Self->data = NULL; 133 | } 134 | return 0; 135 | } 136 | 137 | 138 | 139 | WIDGET_CLASS Widget_Keypad = { 140 | .name = "keypad", 141 | .type = WIDGET_TYPE_KEYPAD, 142 | .init = widget_keypad_init, 143 | .draw = widget_keypad_draw, 144 | .find = widget_keypad_find, 145 | .quit = widget_keypad_quit, 146 | }; 147 | -------------------------------------------------------------------------------- /widget_keypad.h: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * keypad widget handling 5 | * 6 | * Copyright (C) 2006 Chris Maj 7 | * Copyright (C) 2006 The LCD4Linux Team 8 | * 9 | * This file is part of LCD4Linux. 10 | * 11 | * LCD4Linux is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2, or (at your option) 14 | * any later version. 15 | * 16 | * LCD4Linux is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | 28 | #ifndef _WIDGET_KEYPAD_H_ 29 | #define _WIDGET_KEYPAD_H_ 30 | 31 | #include "property.h" 32 | #include "widget.h" 33 | 34 | typedef enum { 35 | WIDGET_KEY_UP = 1, 36 | WIDGET_KEY_DOWN = 2, 37 | WIDGET_KEY_LEFT = 4, 38 | WIDGET_KEY_RIGHT = 8, 39 | WIDGET_KEY_CONFIRM = 16, 40 | WIDGET_KEY_CANCEL = 32, 41 | WIDGET_KEY_PRESSED = 64, 42 | WIDGET_KEY_RELEASED = 128 43 | } KEYPADKEY; 44 | 45 | typedef struct WIDGET_KEYPAD { 46 | PROPERTY expression; /* expression that delivers the value */ 47 | KEYPADKEY key; /* which key */ 48 | } WIDGET_KEYPAD; 49 | 50 | 51 | extern WIDGET_CLASS Widget_Keypad; 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /widget_text.h: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * simple text widget handling 5 | * 6 | * Copyright (C) 2003, 2004 Michael Reinelt 7 | * Copyright (C) 2004 The LCD4Linux Team 8 | * 9 | * This file is part of LCD4Linux. 10 | * 11 | * LCD4Linux is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2, or (at your option) 14 | * any later version. 15 | * 16 | * LCD4Linux is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | 28 | #ifndef _WIDGET_TEXT_H_ 29 | #define _WIDGET_TEXT_H_ 30 | 31 | #include "property.h" 32 | #include "widget.h" 33 | 34 | typedef enum { ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT, ALIGN_MARQUEE, ALIGN_AUTOMATIC, ALIGN_PINGPONG_LEFT, 35 | ALIGN_PINGPONG_CENTER, ALIGN_PINGPONG_RIGHT 36 | } TEXT_ALIGN; 37 | 38 | typedef struct WIDGET_TEXT { 39 | PROPERTY prefix; /* label on the left side */ 40 | PROPERTY postfix; /* label on the right side */ 41 | PROPERTY value; /* value of text widget */ 42 | PROPERTY style; /* text style (plain/bold/slant) */ 43 | char *string; /* formatted value */ 44 | char *buffer; /* string with 'width+1' bytes allocated */ 45 | int width; /* field width */ 46 | int precision; /* number of digits after the decimal point */ 47 | TEXT_ALIGN align; /* alignment: L(eft), C(enter), R(ight), M(arquee), A(utomatic) */ 48 | int update; /* update interval */ 49 | int scroll; /* marquee starting point */ 50 | int speed; /* marquee scrolling speed */ 51 | int direction; /* pingpong direction, 0=right, 1=left */ 52 | int delay; /* pingpong scrolling, wait before switch direction */ 53 | } WIDGET_TEXT; 54 | 55 | 56 | extern WIDGET_CLASS Widget_Text; 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /widget_timer.c: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * timer widget handling 5 | * 6 | * Copyright (C) 2006 Michael Reinelt 7 | * Copyright (C) 2006 The LCD4Linux Team 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2, or (at your option) 12 | * any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 | * 23 | */ 24 | 25 | /* 26 | * exported functions: 27 | * 28 | * WIDGET_CLASS Widget_Timer 29 | * the timer widget 30 | * 31 | */ 32 | 33 | 34 | #include "config.h" 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | #include "debug.h" 42 | #include "cfg.h" 43 | #include "qprintf.h" 44 | #include "property.h" 45 | #include "timer.h" 46 | #include "widget.h" 47 | #include "widget_timer.h" 48 | 49 | #ifdef WITH_DMALLOC 50 | #include 51 | #endif 52 | 53 | void widget_timer_update(void *Self) 54 | { 55 | WIDGET *W = (WIDGET *) Self; 56 | WIDGET_TIMER *Timer = W->data; 57 | int update, active; 58 | 59 | /* evaluate expressions */ 60 | property_eval(&Timer->update); 61 | property_eval(&Timer->active); 62 | 63 | /* get new update interval */ 64 | update = P2N(&Timer->update); 65 | if (update < 10) 66 | update = 10; 67 | 68 | /* finally, fire it! */ 69 | active = P2N(&Timer->active); 70 | if (active > 0) { 71 | property_eval(&Timer->expression); 72 | } 73 | 74 | /* add a new one-shot timer */ 75 | timer_add(widget_timer_update, Self, update, 1); 76 | } 77 | 78 | 79 | 80 | int widget_timer_init(WIDGET * Self) 81 | { 82 | char *section; 83 | WIDGET_TIMER *Timer; 84 | 85 | /* prepare config section */ 86 | /* strlen("Widget:")=7 */ 87 | section = malloc(strlen(Self->name) + 8); 88 | strcpy(section, "Widget:"); 89 | strcat(section, Self->name); 90 | 91 | Timer = malloc(sizeof(WIDGET_TIMER)); 92 | memset(Timer, 0, sizeof(WIDGET_TIMER)); 93 | 94 | /* load properties */ 95 | property_load(section, "expression", NULL, &Timer->expression); 96 | property_load(section, "update", "100", &Timer->update); 97 | property_load(section, "active", "1", &Timer->active); 98 | 99 | free(section); 100 | Self->data = Timer; 101 | Self->x2 = NOCOORD; 102 | Self->y2 = NOCOORD; 103 | 104 | /* just do it! */ 105 | widget_timer_update(Self); 106 | 107 | return 0; 108 | } 109 | 110 | 111 | int widget_timer_quit(WIDGET * Self) 112 | { 113 | if (Self) { 114 | /* do not deallocate child widget! */ 115 | if (Self->parent == NULL) { 116 | if (Self->data) { 117 | WIDGET_TIMER *Timer = Self->data; 118 | property_free(&Timer->expression); 119 | property_free(&Timer->update); 120 | property_free(&Timer->active); 121 | free(Self->data); 122 | Self->data = NULL; 123 | } 124 | } 125 | } 126 | 127 | return 0; 128 | 129 | } 130 | 131 | 132 | int widget_timer_register(void) 133 | { 134 | WIDGET_CLASS wc; 135 | wc = Widget_Timer; 136 | widget_register(&wc); 137 | return 0; 138 | } 139 | 140 | 141 | WIDGET_CLASS Widget_Timer = { 142 | .name = "timer", 143 | .type = WIDGET_TYPE_TIMER, 144 | .init = widget_timer_init, 145 | .draw = NULL, 146 | .quit = widget_timer_quit, 147 | }; 148 | -------------------------------------------------------------------------------- /widget_timer.h: -------------------------------------------------------------------------------- 1 | /* $Id$ 2 | * $URL$ 3 | * 4 | * timer widget handling 5 | * 6 | * Copyright (C) 2006 Michael Reinelt 7 | * Copyright (C) 2006 The LCD4Linux Team 8 | * 9 | * This file is part of LCD4Linux. 10 | * 11 | * LCD4Linux is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2, or (at your option) 14 | * any later version. 15 | * 16 | * LCD4Linux is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | 28 | #ifndef _WIDGET_TIMER_H_ 29 | #define _WIDGET_TIMER_H_ 30 | 31 | #include "property.h" 32 | #include "widget.h" 33 | 34 | typedef struct WIDGET_TIMER { 35 | PROPERTY expression; /* main timer expression */ 36 | PROPERTY update; /* update interval (msec) */ 37 | PROPERTY active; /* timer active? */ 38 | } WIDGET_TIMER; 39 | 40 | extern WIDGET_CLASS Widget_Timer; 41 | 42 | int widget_timer_register(void); 43 | 44 | #endif 45 | --------------------------------------------------------------------------------