File: lib-mylcd.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 (133 lines) | stat: -rw-r--r-- 3,201 bytes parent folder | download | duplicates (5)
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
/* lib-mylcd.h

 used by interfacedemo for "pyramid" LCD device.
 */

/*
 Copyright (C) 2005 Silvan Marco Fin <silvan@kernelconcepts.de>

 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301

 */

#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "lib-mylcd.h"

#define DEBUG 0

/* Request information from LCDd */

int get_integer(int SD, char *request)
{
    static char output[MAXREAD];

    write(SD, request, strlen(request));
    read(SD, output, MAXREAD-1);
    return atoi(output);
}

/* Used to parse the reply from the hello-msg.
 */
void parse_hello(char *input)
{
    char *next=input;
    char *retval;

    while (1)
    {
        retval=strtok(next, " ");
        next=NULL;
        if (retval==NULL)
            break;
        if (strcmp(retval, "wid")==0)
            screen.width=atoi(strtok(next, " "));
        if (strcmp(retval, "hgt")==0)
            screen.height=atoi(strtok(next, " "));
    }
}

int parse_reply(char *input)
{
    char *next=input;
    char *retstr;
    int retint=UNKNOWNKEY;
    int inputlen=strlen(input);
    int len=0;

    printf("Eingabe: %s\n", input);
    while (1)
    {
        retstr=strtok(next, " \n");
        next=NULL;
        if (retstr==NULL)
        {
            input[0]=0; /* wof�r war das? */
            break;
        }
        len+=strlen(retstr)+1;
        /* key detected? */
        if (strcmp(retstr, "key")==0)
        {
            retstr=strtok(next, " \n");
            len+=strlen(retstr)+1;
            if (strcmp(retstr, "Escape")==0)
                retint=ESCAPEKEY;
            if (strcmp(retstr, "Down")==0)
                retint=DOWNKEY;
            if (strcmp(retstr, "Right")==0)
                retint=RIGHTKEY;
            if (strcmp(retstr, "Enter")==0)
                retint=ENTERKEY;

            input=strncpy(input, &input[len], inputlen-len+1);

            return retint;
        }
    }
    return NOKEY;
}

char *basic_send(int SD, char *request)
{
    static char answer[MAXREAD];
    if (DEBUG)
        printf("Sending command: %s\n", request);
    memset(answer, 0, MAXREAD);
    write(SD, request, strlen(request));
    write(SD, "\n", strlen("\n"));
    read(SD, answer, MAXREAD);
    if (DEBUG)
        printf("Answer to command to LCDproc: %s\n", answer);

    return answer;
}

char *basic_read(int SD)
{
    static char answer[MAXREAD];
    memset(answer, 0, MAXREAD);
    if (DEBUG)
        printf("Going for read!\n");
    read(SD, answer, MAXREAD);
    if (DEBUG)
        printf("Read returned: %s\n", answer);

    return answer;
}