File: mode.c

package info (click to toggle)
lcdproc 0.5.9-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 5,064 kB
  • sloc: ansic: 59,645; sh: 1,740; perl: 681; makefile: 417
file content (217 lines) | stat: -rw-r--r-- 4,922 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/** \file clients/lcdproc/mode.c
 * Implements the 'About' screen and contains wrappers for machine dependend
 * initialization / closing.
 */

/*-
 * This file is part of lcdproc, the lcdproc client.
 *
 * This file is released under the GNU General Public License.
 * Refer to the COPYING file distributed with this package.
 */

#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/utsname.h>
#include <string.h>

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#if defined( IRIX ) || defined( SOLARIS )
# include <strings.h>
#endif

#include "shared/sockets.h"

#include "main.h"
#include "mode.h"
#include "machine.h"
#ifdef LCDPROC_EYEBOXONE
# include "eyebox.h"
#endif

/** Initialize mode specific things. */
int
mode_init(void)
{
	machine_init();

	return (0);
}

/** Clean up modes on exit */
void
mode_close(void)
{
	machine_close();
}


/**
 * Calls the mode specific screen init / update function and updates the Eyebox
 * screen as well. Sets the backlight state according to return value of the
 * mode specific screen function.
 *
 * \param m        The screen mode
 * \param display  Flag whether to update screen even if not visible.
 * \return  Backlight state
 */
int
update_screen(ScreenMode *m, int display)
{
	static int status = -1;
	int old_status = status;

	if (m && m->func) {
#ifdef LCDPROC_EYEBOXONE
		/* Save the initialized flag (may be modified by m->func) */
		int init_flag = (m->flags & INITIALIZED);
#endif
		status = m->func(m->timer, display, &(m->flags));
#ifdef LCDPROC_EYEBOXONE
		/* Eyebox Init */
		if (init_flag == 0)
			eyebox_screen(m->which, 0);
		/* Eyebox Flush */
		eyebox_screen(m->which, 1);
#endif
	}

	if (status != old_status) {
		if (status == BACKLIGHT_OFF)
			sock_send_string(sock, "backlight off\n");
		if (status == BACKLIGHT_ON)
			sock_send_string(sock, "backlight on\n");
		if (status == BLINK_ON)
			sock_send_string(sock, "backlight blink\n");
	}

	return (status);
}


/**
 * Credit Screen shows who wrote this...
 *
 * \param rep        Time since last screen update
 * \param display    1 if screen is visible or data should be updated
 * \param flags_ptr  Mode flags
 * \return  Always 0
 */
int
credit_screen(int rep, int display, int *flags_ptr)
{
	/*
	 * List of persons who contributed to LCDproc. Keep in sync with
	 * CREDITS file (ordered by appearance)
	 */
	const char *contributors[] = {
		"William Ferrell",
		"Selene Scriven",
		"Gareth Watts",
		"Lorand Bruhacs",
		"Benjamin Tse",
		"Matthias Prinke",
		"Richard Rognlie",
		"Tom Wheeley",
		"Bjoern Andersson",
		"Andrew McMeikan",
		"David Glaude",
		"Todd Porter",
		"Bjoern Andersson",
		"Jason Dale Woodward",
		"Ethan Dicks",
		"Michael Reinelt",
		"Simon Harrison",
		"Charles Steinkuehler",
		"Harald Klein",
		"Philip Pokorny",
		"Glen Gray",
		"David Douthitt",
		"Eddie Sheldrake",
		"Rene Wagner",
		"Andre Breiler",
		"Joris Robijn",
		"Guillaume Filion",
		"Chris Debenham",
		"Mark Haemmerling",
		"Robin Adams",
		"Manuel Stahl",
		"Mike Patnode",
		"Peter Marschall",
		"Markus Dolze",
		"Volker Boerchers",
		"Lucian Muresan",
		"Matteo Pillon",
		"Laurent Arnal",
		"Simon Funke",
		"Matthias Goebl",
		"Stefan Herdler",
		"Bernhard Walle",
		"Andrew Foss",
		"Anthony J. Mirabella",
		"Cedric Tessier",
		"John Sanders",
		"Eric Pooch",
		"Benjamin Wiedmann",
		"Frank Jepsen",
		"Karsten Festag",
		"Gatewood Green",
		"Dave Platt",
		"Nicu Pavel",
		"Daryl Fonseca-Holt",
		"Thien Vu",
		"Thomas Jarosch",
		"Christian Jodar",
		"Mariusz Bialonczyk",
		"Jack Cleaver",
		"Aron Parsons",
		"Malte Poeggel",
		"Dean Harding",
		"Christian Leuschen",
		"Jonathan Kyler",
		"Sam Bingner",
		NULL
	};
	int contr_num = 0;
	int i;

	if ((*flags_ptr & INITIALIZED) == 0) {
		*flags_ptr |= INITIALIZED;

		/* get number of contributors */
		for (contr_num = 0; contributors[contr_num] != NULL; contr_num++)
			;	/* NADA */

		sock_send_string(sock, "screen_add A\n");
		sock_send_string(sock, "screen_set A -name {Credits for LCDproc}\n");
		sock_send_string(sock, "widget_add A title title\n");
		sock_printf(sock, "widget_set A title {LCDPROC %s}\n", version);
		if (lcd_hgt >= 4) {
			sock_send_string(sock, "widget_add A text scroller\n");
			sock_printf(sock, "widget_set A text 1 2 %d 2 h 8 {%s}\n",
				    lcd_wid, "LCDproc was brought to you by:");
		}

		/* frame from (2nd/3rd line, left) to (last line, right) */
		sock_send_string(sock, "widget_add A f frame\n");
		sock_printf(sock, "widget_set A f 1 %i %i %i %i %i v %i\n",
			    ((lcd_hgt >= 4) ? 3 : 2), lcd_wid, lcd_hgt, lcd_wid, contr_num,
			    /* scroll rate: 1 line every X ticks (= 1/8 sec) */
			    ((lcd_hgt >= 4) ? 8 : 12));

		/* frame contents */
		for (i = 1; i < contr_num; i++) {
			sock_printf(sock, "widget_add A c%i string -in f\n", i);
			sock_printf(sock, "widget_set A c%i 1 %i {%s}\n", i, i, contributors[i]);
		}
	}

	return 0;
}

/* EOF */