~vcs-imports/lcd4linux/trunk

« back to all changes in this revision

Viewing changes to drv_SamsungSPF.c

  • Committer: michael
  • Date: 2012-02-23 06:36:53 UTC
  • Revision ID: svn-v4:3ae390bd-cb1e-0410-b409-cd5a39f66f1f:trunk:1178
some fixes from Sascha Plazar

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
 
39
39
#include "config.h"
40
40
 
41
 
#include <stdlib.h>
42
41
#include <stdio.h>
43
 
#include <unistd.h>
44
42
#include <string.h>
45
 
#include <errno.h>
46
 
 
47
 
#include <fcntl.h>
48
 
#include <signal.h>
49
 
#include <time.h>
50
 
#include <getopt.h>
51
43
 
52
44
#include <usb.h>
53
45
#include <jpeglib.h>
55
47
#include "debug.h"
56
48
#include "cfg.h"
57
49
#include "qprintf.h"
58
 
#include "udelay.h"
59
 
#include "plugin.h"
60
50
#include "timer.h"
61
 
#include "widget.h"
62
 
#include "widget_text.h"
63
 
#include "widget_icon.h"
64
 
#include "widget_bar.h"
65
51
#include "drv.h"
66
52
 
67
53
/* graphic display? */
68
54
#include "drv_generic_graphic.h"
69
 
#include "drv_SamsungSPF.h"
 
55
 
 
56
// Drivername for verbose output
 
57
static char Name[] = "SamsungSPF";
 
58
 
 
59
struct SPFdev {
 
60
    const char type[64];
 
61
    const int vendorID;
 
62
    struct {
 
63
        const int storageMode;
 
64
        const int monitorMode;
 
65
    } productID;
 
66
    const unsigned int xRes;
 
67
    const unsigned int yRes;
 
68
};
 
69
 
 
70
static struct SPFdev spfDevices[] = {
 
71
    {
 
72
     .type = "SPF-75H",
 
73
     .vendorID = 0x04e8,
 
74
     .productID = {0x200e, 0x200f},
 
75
     .xRes = 800,
 
76
     .yRes = 480,
 
77
     },
 
78
    {
 
79
     .type = "SPF-85H",
 
80
     .vendorID = 0x04e8,
 
81
     .productID = {0x2012, 0x2013},
 
82
     .xRes = 800,
 
83
     .yRes = 600,
 
84
     },
 
85
    {
 
86
     .type = "SPF-107H",
 
87
     .vendorID = 0x04e8,
 
88
     .productID = {0x2027, 0x2028},
 
89
     .xRes = 1024,
 
90
     .yRes = 600,
 
91
     },
 
92
};
 
93
 
 
94
static int numFrames = sizeof(spfDevices) / sizeof(spfDevices[0]);
 
95
 
 
96
struct usb_device *myDev;
 
97
usb_dev_handle *myDevHandle;
 
98
struct SPFdev *myFrame;
 
99
 
 
100
typedef struct {
 
101
    unsigned char R, G, B;
 
102
} RGB;
 
103
 
 
104
static struct {
 
105
    RGB *buf;
 
106
    int dirty;
 
107
    int fbsize;
 
108
} image;
 
109
 
 
110
static struct {
 
111
    unsigned char *buf;
 
112
    unsigned long int size;
 
113
} jpegImage;
70
114
 
71
115
 
72
116
/****************************************/
107
151
 
108
152
    /* Finish compression and free internal memory */
109
153
    jpeg_finish_compress(&cinfo);
110
 
    jpeg_destroy(&cinfo);
 
154
    jpeg_destroy_compress(&cinfo);
111
155
 
112
156
    return 0;
113
157
}
200
244
 
201
245
 
202
246
/* dummy function that sends something to the display */
203
 
static int drv_SamsungSPF_send(unsigned char *data, unsigned int len)
 
247
static int drv_SamsungSPF_send(char *data, unsigned int len)
204
248
{
205
 
    char usb_hdr[USB_HDR_LEN] = { 0xa5, 0x5a, 0x18, 0x04, 0xff, 0xff,
 
249
    char usb_hdr[12] = { 0xa5, 0x5a, 0x18, 0x04, 0xff, 0xff,
206
250
        0xff, 0xff, 0x48, 0x00, 0x00, 0x00
207
251
    };
208
252
    char buffer[1] = { 0x0 };
212
256
 
213
257
    *(int *) (usb_hdr + 4) = len;
214
258
 
215
 
    debug("bytes_to_send: %d, offset: %d", len, USB_HDR_LEN);
 
259
    debug("bytes_to_send: %d, offset: %d", len, 12);
216
260
 
217
261
    /* Send USB header */
218
262
    if ((ret = usb_bulk_write(myDevHandle, usb_endpoint, usb_hdr, 12, usb_timeout)) < 0) {
222
266
    }
223
267
 
224
268
    /* Send JPEG image */
225
 
    if ((ret = usb_bulk_write(myDevHandle, usb_endpoint, (char *) jpegImage.buf, len, usb_timeout)) < 0) {
 
269
    if ((ret = usb_bulk_write(myDevHandle, usb_endpoint, data, len, usb_timeout)) < 0) {
226
270
        error("%s: Error occurred while writing data to device.", Name);
227
271
        error("%s: usb_bulk_write returned: %d", Name, ret);
228
272
        return -1;
267
311
        convert2JPG();
268
312
 
269
313
        /* Sent image to display */
270
 
        if ((drv_SamsungSPF_send(jpegImage.buf, jpegImage.size)) != 0) {
 
314
        if ((drv_SamsungSPF_send((char *) jpegImage.buf, jpegImage.size)) != 0) {
271
315
            error("%s: Error occurred while sending jpeg image to device.", Name);
272
316
        }
273
317
        /* Clean dirty bit */
285
329
/* start graphic display */
286
330
static int drv_SamsungSPF_start(const char *section)
287
331
{
288
 
    unsigned int timerInterval = 1000;
 
332
    int timerInterval = 1000;
289
333
    char *s;
290
334
 
291
335
    cfg_number(section, "update", timerInterval, 0, -1, &timerInterval);
379
423
    }
380
424
    // Look for specified device
381
425
    for (i = 0; i < numFrames; i++) {
382
 
        if (strcasecmp(s, spfDevices[i].type) == NULL) {
 
426
        if (strcasecmp(s, spfDevices[i].type) == 0) {
383
427
            myFrame = &spfDevices[i];
384
428
            info("%s: Configured for model %s.", Name, spfDevices[i].type);
385
429
            break;
450
494
 
451
495
    debug("closing connection");
452
496
    printf("%s: Closing driver...\n", Name);
453
 
    usb_close(myDev);
 
497
    usb_close(myDevHandle);
454
498
    free(myDev);
455
499
    free(myDevHandle);
456
500