~ubuntu-branches/ubuntu/saucy/nut/saucy

« back to all changes in this revision

Viewing changes to drivers/hidups.c

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2005-07-20 19:48:50 UTC
  • mto: (16.1.1 squeeze)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20050720194850-oo61wjr33rrx2mre
Tags: upstream-2.0.2
ImportĀ upstreamĀ versionĀ 2.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
90
90
        experimental_driver = 1;
91
91
}
92
92
 
93
 
static inline int find_collection(int fd, unsigned usage) 
 
93
static inline int find_application(int fd, int usage) 
94
94
{
95
 
 
96
 
/* this isn't in all 2.4 kernels... */
97
 
#ifdef HIDIOCGCOLLECTIONINFO
98
 
        struct hiddev_collection_info cinfo;
99
 
 
100
 
        cinfo.index = 0;
101
 
        cinfo.usage = 0;
102
 
 
103
 
        ioctl(fd, HIDIOCGCOLLECTIONINFO, &cinfo);
104
 
        return (cinfo.usage == usage);
105
 
#else
106
 
        upslogx(LOG_WARNING, "HIDIOCGCOLLECTIONINFO not known at compile-time, winging it...");
107
 
        return 1;
108
 
#endif
109
 
 
 
95
        int     i = 0, ret;
 
96
 
 
97
        while ((ret = ioctl(fd, HIDIOCAPPLICATION, i)) > 0 &&
 
98
               ret != usage) 
 
99
                i++;
 
100
 
 
101
        return (ret == usage);
110
102
}
111
103
 
112
104
static void parse_event(struct hiddev_event *ev)
128
120
                return;
129
121
        }
130
122
 
 
123
        upsdebugx(2, "event(%x, %d)",ev->hid,ev->value);
131
124
        switch (ev->hid) {
132
125
                case UPS_BATTVOLT:
133
126
                        dstate_setinfo("battery.voltage", "%2.1f", 
136
129
                case BATT_RUNTIME_TO_EMPTY:
137
130
                        dstate_setinfo("battery.runtime", "%d", ev->value);
138
131
                        break;
 
132
                case UPS_LOADPCT:
 
133
                        dstate_setinfo("ups.load", "%d", ev->value);
 
134
                        break;
139
135
                case BATT_REMAINING_CAPACITY:
140
136
                        dstate_setinfo("battery.charge", "%d", ev->value);
141
137
                        break;
285
281
{
286
282
        fd_set  fdset;
287
283
        struct  timeval tv;
288
 
        int     rd, i;
 
284
        int     rd;
 
285
        unsigned int    i;
289
286
        struct  hiddev_event ev[64];
290
287
 
 
288
        /* For some reason, APC XS BX1500 does not report changes
 
289
         * in LOADPCT without HIDIOCINITREPORT. */
 
290
        ioctl(fd, HIDIOCINITREPORT, 0);
291
291
        FD_ZERO(&fdset);
292
292
        FD_SET(fd, &fdset);
293
293
        tv.tv_sec = 0;
339
339
        }
340
340
 
341
341
        dstate_setinfo(varname, "%d", val);
 
342
        upsdebugx(2, "addhidvalue(%x, %s): obtained %d", 
 
343
          query, varname, val);
342
344
}
343
345
 
344
346
int setvalue(int type, int value)
401
403
}
402
404
 
403
405
/* handler for settable variables in UPS*/
404
 
void setvar (int auxcmd, int dlen, char *data)
 
406
int setvar(const char *varname, const char *val)
405
407
{
406
 
        ;       
407
408
        /* int setvalue(int type, int value) */
 
409
 
 
410
        return STAT_SET_UNKNOWN;
408
411
}
409
412
 
410
413
void upsdrv_initinfo(void) 
455
458
        if (str)
456
459
                dstate_setinfo("ups.serial", "%s", str);
457
460
 
 
461
        str = getstring(BATT_ICHEMISTRY);
 
462
        if (str)
 
463
                dstate_setinfo("battery.chemistry", "%s", str);
 
464
 
458
465
        /* seed the status register */
459
466
 
460
467
        val = getvalue(BATT_AC_PRESENT);
544
551
 
545
552
        open_usb(device_path, O_RDONLY);
546
553
 
547
 
        ioctl(fd, HIDIOCINITREPORT, 0);
548
 
 
549
 
        if (!find_collection(fd, UPS_USAGE))
 
554
        if ((!find_application(fd, UPS_USAGE)) &&
 
555
                (!find_application(fd, POWER_USAGE)))
550
556
                fatalx("%s is not a UPS\n", device_path);
551
557
 
552
558
        ioctl(fd, HIDIOCGNAME(sizeof(name)), name);
553
559
        printf("Detected %s\n", name);
554
560
        printf("on port %s\n", device_path);
555
561
 
 
562
        ioctl(fd, HIDIOCINITREPORT, 0);
556
563
}
557
564
 
558
565
void upsdrv_cleanup(void)