commandline/usb-led-fader.c File Reference

Commandline-tool for the USB-LED-Fader. More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <usb.h>
#include "usbledfader.h"
#include "channels.h"

Go to the source code of this file.

Defines

#define USBDEV_SHARED_VENDOR   0x16C0
 VOTI.
#define USBDEV_SHARED_PRODUCT   0x05DC
 Obdev's free shared PID.
#define USB_ERROR_NOTFOUND   1
 Error code if the device isn't found.
#define USB_ERROR_ACCESS   2
 Error code if the device isn't accessible.
#define USB_ERROR_IO   3
 Error code if errors in the communication with the device occur.

Functions

void usage (char *name)
 Displays usage-informations.
int usbGetStringAscii (usb_dev_handle *dev, int index, int langid, char *buf, int buflen)
 Reads and converts a string from USB.
int usbOpenDevice (usb_dev_handle **device, int vendor, char *vendorName, int product, char *productName)
 Connect to the USB-device.
void dev_test (usb_dev_handle *handle, int argc, char **argv)
 Test connection to the device.
void dev_set (usb_dev_handle *handle, int argc, char **argv)
 Set waves.
void dev_clear (usb_dev_handle *handle, int argc, char **argv)
 Clear all waves on one LED.
void dev_status (usb_dev_handle *handle, int argc, char **argv)
 Get the status of the device.
void dev_reset (usb_dev_handle *handle, int argc, char **argv)
 Reset the device.
void dev_show (usb_dev_handle *handle, int argc, char **argv)
 Show a waveform.
int main (int argc, char **argv)
 Main function.


Detailed Description

Commandline-tool for the USB-LED-Fader.

Author:
Ronald Schaten
Version:
Id
usb-led-fader.c,v 1.2 2006/10/01 16:28:38 rschaten Exp
License: See documentation.

Definition in file usb-led-fader.c.


Define Documentation

#define USB_ERROR_ACCESS   2

Error code if the device isn't accessible.

Definition at line 23 of file usb-led-fader.c.

Referenced by usbOpenDevice().

#define USB_ERROR_IO   3

Error code if errors in the communication with the device occur.

Definition at line 24 of file usb-led-fader.c.

Referenced by usbOpenDevice().

#define USB_ERROR_NOTFOUND   1

Error code if the device isn't found.

Definition at line 22 of file usb-led-fader.c.

Referenced by usbOpenDevice().

#define USBDEV_SHARED_PRODUCT   0x05DC

Obdev's free shared PID.

Use obdev's generic shared VID/PID pair and follow the rules outlined in firmware/usbdrv/USBID-License.txt.

Definition at line 19 of file usb-led-fader.c.

Referenced by main().

#define USBDEV_SHARED_VENDOR   0x16C0

VOTI.

Definition at line 18 of file usb-led-fader.c.

Referenced by main().


Function Documentation

void dev_clear ( usb_dev_handle *  handle,
int  argc,
char **  argv 
)

Clear all waves on one LED.

Parameters:
handle Handle to talk to the device.
argc Number of arguments.
argv Arguments.

Definition at line 261 of file usb-led-fader.c.

References CHANNELS, CMD_CLEAR, and usage().

Referenced by main().

void dev_reset ( usb_dev_handle *  handle,
int  argc,
char **  argv 
)

Reset the device.

Parameters:
handle Handle to talk to the device.
argc Number of arguments.
argv Arguments.

Definition at line 330 of file usb-led-fader.c.

References CMD_RESET, and usage().

Referenced by main().

void dev_set ( usb_dev_handle *  handle,
int  argc,
char **  argv 
)

Set waves.

It is possible to set any number of waves at once.

Parameters:
handle Handle to talk to the device.
argc Number of arguments.
argv Arguments.

Definition at line 204 of file usb-led-fader.c.

References CHANNELS, CMD_SET, and usage().

Referenced by main().

void dev_show ( usb_dev_handle *  handle,
int  argc,
char **  argv 
)

Show a waveform.

This will not send a command to the device, the waveform is only printed on the screen.

Parameters:
handle Handle to talk to the device (not needed).
argc Number of arguments.
argv Arguments.

Definition at line 351 of file usb-led-fader.c.

References fade_calculateWaveform(), and usage().

Referenced by main().

void dev_status ( usb_dev_handle *  handle,
int  argc,
char **  argv 
)

Get the status of the device.

Status information is printed in detail.

Parameters:
handle Handle to talk to the device.
argc Number of arguments.
argv Arguments.

Definition at line 286 of file usb-led-fader.c.

References CHANNELS, CMD_GET, and usage().

Referenced by main().

void dev_test ( usb_dev_handle *  handle,
int  argc,
char **  argv 
)

Test connection to the device.

The test consists of writing 1000 random numbers to the device and checking the echo. This should discover systematic bit errors (e.g. in bit stuffing).

Parameters:
handle Handle to talk to the device.
argc Number of arguments.
argv Arguments.

Definition at line 171 of file usb-led-fader.c.

References CMD_ECHO, and usage().

Referenced by main().

int main ( int  argc,
char **  argv 
)

Main function.

Initializes the USB-device, parses commandline-parameters and calls the functions that communicate with the device.

Parameters:
argc Number of arguments.
argv Arguments.
Returns:
Error code.

Definition at line 390 of file usb-led-fader.c.

References dev_clear(), dev_reset(), dev_set(), dev_show(), dev_status(), dev_test(), usage(), USBDEV_SHARED_PRODUCT, USBDEV_SHARED_VENDOR, and usbOpenDevice().

void usage ( char *  name  ) 

Displays usage-informations.

This function is called if the parameters cannot be parsed.

Parameters:
name The name of this application.

Definition at line 31 of file usb-led-fader.c.

References CHANNELS.

Referenced by dev_clear(), dev_reset(), dev_set(), dev_show(), dev_status(), dev_test(), and main().

int usbGetStringAscii ( usb_dev_handle *  dev,
int  index,
int  langid,
char *  buf,
int  buflen 
)

Reads and converts a string from USB.

The conversion to ASCII is 'lossy' (unknown characters become '?').

Parameters:
dev Handle of the USB-Device.
index Index of the required data.
langid Index of the expected language.
buf Buffer to contain the return-string.
buflen Length of buf.
Returns:
Length of the string.

Definition at line 59 of file usb-led-fader.c.

Referenced by usbOpenDevice().

int usbOpenDevice ( usb_dev_handle **  device,
int  vendor,
char *  vendorName,
int  product,
char *  productName 
)

Connect to the USB-device.

Loops through all connected USB-Devices and searches our counterpart.

Parameters:
device Handle to address the device.
vendor USBDEV_SHARED_VENDOR as defined.
vendorName In our case "www.schatenseite.de".
product USBDEV_SHARED_PRODUCT as defined.
productName In our case "USB-LED-Fader".
Returns:
Error code.

Definition at line 99 of file usb-led-fader.c.

References USB_ERROR_ACCESS, USB_ERROR_IO, USB_ERROR_NOTFOUND, and usbGetStringAscii().

Referenced by main().


Generated on Mon Oct 2 19:31:17 2006 for USB-LED-Fader by  doxygen 1.4.7