File: lcd_lib.c

package info (click to toggle)
lcdproc 0.5.7-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 5,012 kB
  • ctags: 6,532
  • sloc: ansic: 58,028; sh: 2,005; perl: 681; makefile: 482
file content (85 lines) | stat: -rw-r--r-- 2,396 bytes parent folder | download | duplicates (3)
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
/** \file server/drivers/lcd_lib.c
 * LCD library of useful functions for drivers.
 *
 * Drawn from the "base driver" which really was the precursor
 * to this library.
 *
 * \todo Make use of the \c options parameter to specify SEAMLESS_HBARS,
 *       the height of hbars, etc.
 */

#include "lcd.h"

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

/**
 * This function places a hbar using the v0.5 API format and the given cellwidth.
 * It assumes that custom chars have been statically defined, so that number
 * 1 has 1 pixel, number 2 has 2 etc.
 *
 * LCDs that have the custom chars at other char numbers than 0 should put the
 * first custom char number in cc_offset.
 */
void
lib_hbar_static (Driver *drvthis, int x, int y, int len, int promille, int options, int cellwidth, int cc_offset)
{
	int total_pixels  = ((long) 2 * len * cellwidth + 1 ) * promille / 2000;
	int pos;

	for (pos = 0; pos < len; pos ++ ) {

		int pixels = total_pixels - cellwidth * pos;

		if ( pixels >= cellwidth ) {
			/* write a "full" block to the screen... */
#if defined(SEAMLESS_HBARS)
			drvthis->chr (drvthis, x+pos, y, cellwidth + cc_offset);
#else
			drvthis->icon (drvthis, x+pos, y, ICON_BLOCK_FILLED);
#endif
		}
		else if ( pixels > 0 ) {
			/* write a partial block... */
			drvthis->chr (drvthis, x+pos, y, pixels + cc_offset);
			break;
		}
		else {
			; /* write nothing (not even a space) */
		}
	}
}

/**
 * This function places a vbar using the v0.5 API format and the given cellwidth.
 * It assumes that custom chars have been statically defined, so that number
 * 1 has 1 pixel, number 2 has 2 etc., just like in good old times.
 *
 * LCDs that have the custom chars at other char numbers than 0 should put the
 * first custom char number in cc_offset.
 */
void
lib_vbar_static (Driver *drvthis, int x, int y, int len, int promille, int options, int cellheight, int cc_offset)
{
	int total_pixels = ((long) 2 * len * cellheight + 1 ) * promille / 2000;
	int pos;

	for (pos = 0; pos < len; pos ++ ) {

		int pixels = total_pixels - cellheight * pos;

		if ( pixels >= cellheight ) {
			/* write a "full" block to the screen... */
			drvthis->icon (drvthis, x, y-pos, ICON_BLOCK_FILLED);
		}
		else if ( pixels > 0 ) {
			/* write a partial block... */
			drvthis->chr (drvthis, x, y-pos, pixels + cc_offset);
			break;
		}
		else {
			; /* write nothing (not even a space) */
		}
	}
}