Erste CVS-Version

This commit is contained in:
Ronald Schaten 2006-09-26 18:18:27 +00:00
parent 62a932ecdd
commit b282d4a32c
35 changed files with 7302 additions and 0 deletions

346
License.txt Normal file
View File

@ -0,0 +1,346 @@
The following license applies to all but the firmware/usbdrv directories. For
that directory, please refer to the firmware/usbdrv/License.txt file for
additional license restrictions.
-------------------------------------------------------------------------------
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
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
(at your option) 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.

297
Readme.txt Normal file
View File

@ -0,0 +1,297 @@
$Id: Readme.txt,v 1.1 2006/09/26 18:18:27 rschaten Exp $
For full documentation and examples, take a look at htmldoc/index.html.
Introduction
============
The USB-LED-Fader is a device to control a number of LEDs via USB. I built it
to display the online-status of my internet-connection, the recording-status of
my videorecorder, and warnings if the available disc-space is low. You can
imagine an endless number of applications for this.
The LEDs are controlled with pulse width modulation (PWM). That way, they are
not only on or off, it is possible to control the brightness. Included in the
device is a number of 'waveforms' that can be displayed on the LEDs. That way,
one LED can display some kind of a sinus- or triangular wave without any
interaction with the controlling host.
Every LED can be controlled individually, each one can display it's own
waveforms.
You can assign three different waves to every LED: two 'eternal' waves (0 & 1).
They are displayed alternating until anything different is required. The third
wave (2) is only displayed once, afterwards the device will switch back to
alternating between the first two waves.
One wave is described by three parameters: the waveform, the duration for one
repetition of the wave and the number of repetitions before switching to the
next wave.
This version supports four LEDs, it should be quite easy to change that number
between one and eight. I have not tested any number greater than four, but I
can imagine that the load on the controller can be too high to reliably
communicate via USB.
There are three parts included in the distribution: The firmware for an ATmega8
microcontroller, a commandline-client that can be run under Linux, and the
circuits needed to build the device.
This project is based on the PowerSwitch example application by Objective
Development. Like that, it uses Objective Development's firmware-only USB
driver for Atmel's AVR microcontrollers.
Objective Development's USB driver is a firmware-only implementation of the USB
1.1 standard (low speed device) on cheap single chip microcomputers of Atmel's
AVR series, such as the ATtiny2313 or even some of the small 8 pin devices. It
implements the standard to the point where useful applications can be
implemented. See the file "firmware/usbdrv/usbdrv.h" for features and
limitations.
Building and installing
=======================
Both, the firmware and Unix command line tool are built with "make". You may
need to customize both makefiles.
Firmware
--------
The firmware for this project requires avr-gcc and avr-libc (a C-library for
the AVR controller). Please read the instructions at
http://www.nongnu.org/avr-libc/user-manual/install_tools.html for how to
install the GNU toolchain (avr-gcc, assembler, linker etc.) and avr-libc.
Once you have the GNU toolchain for AVR microcontrollers installed, you can run
"make" in the subdirectory "firmware". You may have to edit the Makefile to use
your preferred downloader with "make program". The current version is built for
avrdude with a parallel connection to an stk200-compatible programmer.
If working with a brand-new controller, you may have to set the fuse-bits to
use the external crystal:
avrdude -p atmega8 -P /dev/parport0 -c sp12 -U hfuse:w:0xC9:m \
-U lfuse:w:0x9F:m
Afterwards, you can compile and flash to the device:
make program
Commandline client
------------------
The command line tool requires libusb. Please download libusb from
http://libusb.sourceforge.net/ and install it before you compile. Change to
directory "commandline", check the Makefile and edit the settings if required
and type
make
This will build the unix executable "usb-led-fader" which can be used to
control the device.
Usage
=====
Connect the device to the USB-port. All LED should flash up to indicate that
the device is initialized.
Then use the commandline-client as follows:
usb-led-fader status
usb-led-fader set <ledId> <waveId> <waveformId> <periodDuration> <repetitionCount>
usb-led-fader clear <ledId>
usb-led-fader reset
usb-led-fader show <waveformId>
usb-led-fader test
When using the set-function, it is possible to define several waves at once.
You simply have to give the parameters for all waves. See examples below.
Parameters
----------
- ledId: ID of the LED (0-n, depending on the number of LEDs in your circuit).
- waveId: ID of the wave (0-1: constant waves, 2: override).
- waveformId: ID of the waveform (0-31: brightness, 32-37: patterns). For a
reference to the patterns, consult the function fade_calculateWaveform() in
the file "firmware/main.c".
- periodDuration: Time in sec/10 for one repetition of the waveform. A value of
0 can be used to reset the wave.
- repetitionCount: Number of repetitions before switching to the next wave. A
value of 0 can be used to repeat this forever.
Examples
--------
-> Get the status of all LEDs:
usb-led-fader status
This will result in an output similar to this:
LED 0 curid curvalue curpos currep nextupd
0 2 26 0 23
wave waveform length repeat duration updtime
0 38 32 1 20 45
1 0 1 1 0 1
2 0 1 1 0 1
LED 1 curid curvalue curpos currep nextupd
0 14 19 0 19
wave waveform length repeat duration updtime
0 38 32 1 20 45
1 0 1 1 0 1
2 0 1 1 0 1
LED 2 curid curvalue curpos currep nextupd
0 31 16 0 43
wave waveform length repeat duration updtime
0 38 32 1 20 45
1 0 1 1 0 1
2 0 1 1 0 1
LED 3 curid curvalue curpos currep nextupd
0 6 9 0 39
wave waveform length repeat duration updtime
0 38 32 1 20 45
1 0 1 1 0 1
2 0 1 1 0 1
In this output, the values curvalue, curpos, nextupd and updtime are for
debugging purposes only. They shouldn't be of interest to the common user. The
meaning of the other values should be clear.
-> Set the first LED to keep a middle brightness:
usb-led-fader set 0 0 15 10 1
So, on LED 0 the wave 0 is set to waveform 15. It will stay there for one
second and will be repeated once before switching to the next wave. There is no
next wave because we didn't define one, so this waveform will stay forever.
-> Now set a second wave on the first LED, a little brighter than the one
before:
usb-led-fader set 0 1 25 10 1
This is wave 1 on LED 0, waveform 25 indicates a constant level of brightness.
After setting the second wave, it will alternate with the first one after every
second, because both waves have the same duration and the same number of
repetitions.
-> Set a third wave on the first LED:
usb-led-fader set 0 2 36 20 5
This sets the third wave (wave 2) on the first LED. Waveform 36 is a nice
sinus-like wave, so the LED starts to fade. One period of the fading takes 2
seconds, it is repeated for 5 times. Since this is the third wave, after the
repetitions the LED returns to alternating between wave 0 and wave 1, this wave
is discarded.
-> Set multiple waves at once:
usb-led-fader set 0 0 15 10 1 0 1 25 10 1 0 2 36 20 5
This will set all of the above waves at once. Thus, the first LED will first
fade the sinus-wave five times, then start alternating between the two
brightnesses in one-second-rhythm.
Clear the first LED:
usb-led-fader clear 0
This will clear all three waves on the first LED.
-> Reset the device:
usb-led-fader reset
All LEDs will flash once, to indicate that the device is reset and the LEDs are
working.
-> Show a waveform on the screen:
usb-led-fader show 36
This will lead to an output like the following:
wave 36 - length 64
31: *****
30: *********
29: ***********
28: ***************
27: *****************
26: *******************
25: *******************
24: *********************
23: ***********************
22: *************************
21: *************************
20: ***************************
19: *****************************
18: *****************************
17: *******************************
16: *********************************
15: ***********************************
14: ***********************************
13: *************************************
12: ***************************************
11: ***************************************
10: *****************************************
9: *******************************************
8: *********************************************
7: *********************************************
6: ***********************************************
5: *************************************************
4: *****************************************************
3: *******************************************************
2: ***********************************************************
1: ****************************************************************
================================================================
Keep in mind that the width of the displayed wave corresponds to the length of
the waveform. If you display a very simple one like the constant brightness
levels (0-31), the length is 1. Therefore only one column is displayed.
-> Test the device:
usb-led-fader test
This function sends many random numbers to the device. The device returns the
packages, and the client looks for differences in the sent and the received
numbers.
Drawbacks
=========
As mentioned above, controlling the PWM for several LEDs is a lot of work for
one small microcontroller. Speaking the USB protocol is so, either. Both
combined result in a lot of load on the device, so the communication with the
device is not 100% reliable. More than 99% though, at least in our tests.
SO BE WARNED: You should not use this device to control the state of your
nuclear reactor. If you intend to use it in that way despite of this warning,
please let me know... ;-)
Files in the distribution
=========================
- Readme.txt: The file you are currently reading.
- firmware: Source code of the controller firmware.
- firmware/usbdrv: USB driver -- See Readme.txt in this directory for info
- commandline: Source code of the host software (needs libusb).
- common: Files needed by the firmware and the commandline-client.
- circuit: Circuit diagrams in PDF and EAGLE 4 format. A free version of EAGLE
is available for Linux, Mac OS X and Windows from http://www.cadsoft.de/.
- License.txt: Public license for all contents of this project, except for the
USB driver. Look in firmware/usbdrv/License.txt for further info.
- Changelog.txt: Logfile documenting changes in soft-, firm- and hardware.
Thanks!
=======
I'd like to thank Objective Development for the possibility to use their driver
for my project. In fact, this project wouldn't exist without the driver.
And I'd like to give special credits to Thomas Stegemann. He wrote the
PWM-stuff, and I guess it would have been nearly to impossible to me to write
the rest of the project without his help since C isn't my natural language.
About the license
=================
Our work - all contents except for the USB driver - are licensed under the GNU
General Public License (GPL). A copy of the GPL is included in License.txt. The
driver itself is licensed under a special license by Objective Development. See
firmware/usbdrv/License.txt for further info.
(c) 2006 by Ronald Schaten - http://www.schatenseite.de

BIN
circuit/circuit.brd Normal file

Binary file not shown.

BIN
circuit/circuit.sch Normal file

Binary file not shown.

30
circuit/partlist.txt Normal file
View File

@ -0,0 +1,30 @@
Partlist
Exported from circuit.sch at 9/15/2006 14:21:25
EAGLE Version 4.16 Copyright (c) 1988-2005 CadSoft
Part Value Device Package Library Sheet
C1 4,7u CPOL-EUE2.5-5 E2,5-5 rcl 1
C2 100n C-EU025-024X044 C025-024X044 rcl 1
C3 22p C-EU025-024X044 C025-024X044 rcl 1
C4 22p C-EU025-024X044 C025-024X044 rcl 1
IC1 MEGA8-P MEGA8-P DIL28-3 avr 1
IC2 LM317LZ LM317LZ TO92 linear 1
JP1 ISP JP5Q JP5Q jumper 1
LED1 LED5MM LED5MM led 1
LED2 LED5MM LED5MM led 1
LED3 LED5MM LED5MM led 1
LED4 LED5MM LED5MM led 1
Q1 12MHz CRYTALHC18U-V HC18U-V crystal 1
R1 432 R-EU_0207/10 0207/10 rcl 1
R2 240 R-EU_0207/10 0207/10 rcl 1
R3 1k5 R-EU_0207/10 0207/10 rcl 1
R4 68 R-EU_0207/10 0207/10 rcl 1
R5 68 R-EU_0207/10 0207/10 rcl 1
R6 1k R-EU_0207/10 0207/10 rcl 1
R7 1k R-EU_0207/10 0207/10 rcl 1
R8 1k R-EU_0207/10 0207/10 rcl 1
R9 1k R-EU_0207/10 0207/10 rcl 1
X1 PN61729 PN61729 con-berg 1

23
commandline/Makefile Normal file
View File

@ -0,0 +1,23 @@
# $Id: Makefile,v 1.1 2006/09/26 18:18:27 rschaten Exp $
CC = gcc
LIBUSB_CONFIG = libusb-config
# Make sure that libusb-config is in the search path or specify a full path. On
# Windows, there is no libusb-config and you must configure the options below
# manually. See examples.
CFLAGS = `$(LIBUSB_CONFIG) --cflags` -O -Wall -I../common
LIBS = `$(LIBUSB_CONFIG) --libs`
all: usb-led-fader
.c.o:
$(CC) $(CFLAGS) -c $<
usb-led-fader: usb-led-fader.o
$(CC) -o usb-led-fader usb-led-fader.o $(LIBS)
clean:
rm -f *.o
rm -f usb-led-fader

426
commandline/usb-led-fader.c Normal file
View File

@ -0,0 +1,426 @@
/**
* \file usb-led-fader.c
* \brief Commandline-tool for the USB-LED-Fader.
* \author Ronald Schaten
* \version $Id: usb-led-fader.c,v 1.1 2006/09/26 18:18:27 rschaten Exp $
*
* License: See documentation.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <usb.h> /* this is libusb, see http://libusb.sourceforge.net/ */
#include "usbledfader.h"
#include "channels.h"
#define USBDEV_SHARED_VENDOR 0x16C0 /**< VOTI */
#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. */
/* These are error codes for the communication via USB. */
#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. */
/**
* Displays usage-informations. This function is called if the parameters
* cannot be parsed.
* \param name The name of this application.
*/
void usage(char *name)
{
fprintf(stderr, "usage:\n");
fprintf(stderr, " %s status\n", name);
fprintf(stderr, " %s set ledId waveId waveformId periodDuration repetitionCount\n", name);
fprintf(stderr, " %s clear ledId\n", name);
fprintf(stderr, " %s reset\n", name);
fprintf(stderr, " %s show waveformId\n", name);
fprintf(stderr, " %s test\n\n", name);
fprintf(stderr, "parameters:\n");
fprintf(stderr, " ledId: ID of the LED (0-%d).\n", CHANNELS - 1);
fprintf(stderr, " waveId: ID of the wave (0-1: constant waves, 2: override).\n");
fprintf(stderr, " waveformId: ID of the waveform (0-31: brightness, 32-37: patterns).\n");
fprintf(stderr, " periodDuration: Time in sec/10 for one repetition of the waveform.\n");
fprintf(stderr, " A value of 0 can be used to reset the wave.\n");
fprintf(stderr, " repetitionCount: Number of repetitions before switching to the next wave.\n");
fprintf(stderr, " A value of 0 can be used to repeat this forever.\n");
}
/**
* Reads and converts a string from USB. The conversion to ASCII is 'lossy' (unknown characters become '?').
* \param dev Handle of the USB-Device.
* \param index Index of the required data.
* \param langid Index of the expected language.
* \param buf Buffer to contain the return-string.
* \param buflen Length of buf.
* \return Length of the string.
*/
int usbGetStringAscii(usb_dev_handle * dev, int index, int langid, char *buf, int buflen) {
char buffer[256];
int rval, i;
if ((rval = usb_control_msg(dev, USB_ENDPOINT_IN, USB_REQ_GET_DESCRIPTOR, (USB_DT_STRING << 8) + index, langid, buffer, sizeof(buffer), 1000)) < 0) {
return rval;
}
if (buffer[1] != USB_DT_STRING) {
return 0;
}
if ((unsigned char) buffer[0] < rval) {
rval = (unsigned char) buffer[0];
}
rval /= 2;
/* lossy conversion to ISO Latin1 */
for (i = 1; i < rval; i++) {
if (i > buflen) {
/* destination buffer overflow */
break;
}
buf[i - 1] = buffer[2 * i];
if (buffer[2 * i + 1] != 0) {
/* outside of ISO Latin1 range */
buf[i - 1] = '?';
}
}
buf[i - 1] = 0;
return i - 1;
}
/**
* Connect to the USB-device. Loops through all connected USB-Devices and
* searches our counterpart.
* \param device Handle to address the device.
* \param vendor USBDEV_SHARED_VENDOR as defined.
* \param vendorName In our case "www.schatenseite.de".
* \param product USBDEV_SHARED_PRODUCT as defined.
* \param productName In our case "USB-LED-Fader".
* \return Error code.
*/
int usbOpenDevice(usb_dev_handle ** device, int vendor, char *vendorName, int product, char *productName) {
struct usb_bus *bus;
struct usb_device *dev;
usb_dev_handle *handle = NULL;
int errorCode = USB_ERROR_NOTFOUND;
static int didUsbInit = 0;
if (!didUsbInit) {
didUsbInit = 1;
usb_init();
}
usb_find_busses();
usb_find_devices();
for (bus = usb_get_busses(); bus; bus = bus->next) {
for (dev = bus->devices; dev; dev = dev->next) {
if (dev->descriptor.idVendor == vendor && dev->descriptor.idProduct == product) {
char string[256];
int len;
handle = usb_open(dev); /* we need to open the device in order to query strings */
if (!handle) {
errorCode = USB_ERROR_ACCESS;
fprintf(stderr, "Warning: cannot open USB device: %s\n", usb_strerror());
continue;
}
if (vendorName == NULL && productName == NULL) { /* name does not matter */
break;
}
/* now check whether the names match: */
len = usbGetStringAscii(handle, dev->descriptor.iManufacturer, 0x0409, string, sizeof(string));
if (len < 0) {
errorCode = USB_ERROR_IO;
fprintf(stderr, "Warning: cannot query manufacturer for device: %s\n", usb_strerror());
} else {
errorCode = USB_ERROR_NOTFOUND;
/* fprintf(stderr, "seen device from vendor ->%s<-\n", string); */
if (strcmp(string, vendorName) == 0) {
len = usbGetStringAscii(handle, dev->descriptor.iProduct, 0x0409, string, sizeof(string));
if (len < 0) {
errorCode = USB_ERROR_IO;
fprintf(stderr, "Warning: cannot query product for device: %s\n", usb_strerror());
} else {
errorCode = USB_ERROR_NOTFOUND;
/* fprintf(stderr, "seen product ->%s<-\n", string); */
if (strcmp(string, productName) == 0) {
break;
}
}
}
}
usb_close(handle);
handle = NULL;
}
}
if (handle) {
break;
}
}
if (handle != NULL) {
errorCode = 0;
*device = handle;
}
return errorCode;
}
/**
* 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).
* \param handle Handle to talk to the device.
* \param argc Number of arguments.
* \param argv Arguments.
*/
void dev_test(usb_dev_handle *handle, int argc, char** argv) {
unsigned char buffer[8];
int nBytes;
int i, v, r;
if (argc != 2) {
usage(argv[0]);
exit(1);
}
for (i = 0; i < 1000; i++) {
v = rand() & 0xffff;
nBytes = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, CMD_ECHO, v, 0, (char *) buffer, sizeof(buffer), 5000);
if (nBytes < 2) {
if (nBytes < 0) {
fprintf(stderr, "USB error: %s\n", usb_strerror());
}
fprintf(stderr, "only %d bytes received in iteration %d\n", nBytes, i);
exit(1);
}
r = buffer[0] | (buffer[1] << 8);
if (r != v) {
fprintf(stderr, "data error: received 0x%x instead of 0x%x in iteration %d\n", r, v, i);
exit(1);
}
}
printf("test succeeded\n");
}
/**
* Set waves. It is possible to set any number of waves at once.
* \param handle Handle to talk to the device.
* \param argc Number of arguments.
* \param argv Arguments.
*/
void dev_set(usb_dev_handle *handle, int argc, char** argv) {
unsigned char buffer[8];
int nBytes;
int parameter;
if ((argc < 7) || ((argc - 2) % 5 != 0)) {
usage(argv[0]);
exit(1);
}
for (parameter = 2; (parameter + 4) < argc; parameter += 5) {
int ledId = atoi(argv[parameter + 0]);
if ((ledId < 0) || (ledId > (CHANNELS - 1))) {
fprintf(stderr, "invalid ledId: %d\n", ledId);
exit(1);
}
int waveId = atoi(argv[parameter + 1]);
if ((waveId < 0) || (waveId > 2)) {
fprintf(stderr, "invalid waveId: %d\n", waveId);
exit(1);
}
int waveformId = atoi(argv[parameter + 2]);
if ((waveformId < 0) || (waveformId > 38)) {
fprintf(stderr, "invalid waveformId: %d\n", waveformId);
exit(1);
}
int periodDuration = atoi(argv[parameter + 3]);
if ((periodDuration < 0) || (periodDuration > 255)) {
fprintf(stderr, "invalid periodDuration: %d\n", periodDuration);
exit(1);
}
int repetitionCount = atoi(argv[parameter + 4]);
if ((repetitionCount < 0) || (repetitionCount > 255)) {
fprintf(stderr, "invalid repetitionCount: %d\n", repetitionCount);
exit(1);
}
buffer[0] = CMD_SET;
buffer[1] = ledId;
buffer[2] = waveId;
buffer[3] = waveformId;
buffer[4] = periodDuration;
buffer[5] = repetitionCount;
nBytes = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CMD_SET, ledId, 0, (char *) buffer, sizeof(buffer), 5000);
if (nBytes < 0) {
fprintf(stderr, "USB error: %s\n", usb_strerror());
exit(1);
}
}
}
/**
* Clear all waves on one LED.
* \param handle Handle to talk to the device.
* \param argc Number of arguments.
* \param argv Arguments.
*/
void dev_clear(usb_dev_handle *handle, int argc, char** argv) {
unsigned char buffer[8];
int nBytes;
if (argc != 3) {
usage(argv[0]);
exit(1);
}
int ledId = atoi(argv[2]);
if ((ledId < 0) || (ledId > (CHANNELS - 1))) {
fprintf(stderr, "invalid LED: %d\n", ledId);
exit(1);
}
nBytes = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CMD_CLEAR, ledId, 0, (char *) buffer, sizeof(buffer), 5000);
if (nBytes < 0) {
fprintf(stderr, "USB error: %s\n", usb_strerror());
exit(1);
}
}
/**
* Get the status of the device. Status information is printed in detail.
* \param handle Handle to talk to the device.
* \param argc Number of arguments.
* \param argv Arguments.
*/
void dev_status(usb_dev_handle *handle, int argc, char** argv) {
int nBytes;
int i, j;
static fade_GlobalData fade_globalData; /* contains the state of all four LEDs. */
if (argc != 2) {
usage(argv[0]);
exit(1);
}
nBytes = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, CMD_GET, 0, 0, (char *) &fade_globalData, sizeof(fade_globalData), 5000);
if (nBytes < 0) {
fprintf(stderr, "USB error: %s\n", usb_strerror());
exit(1);
}
if (nBytes != sizeof(fade_globalData)) {
fprintf(stderr, "USB oddity: %d bytes received, %d bytes expected.\n", nBytes, sizeof(fade_globalData));
exit(1);
}
for (i = 0; i < CHANNELS; i++) {
printf("LED %d %10s %10s %10s %10s %10s\n", i, "curid", "curvalue", "curpos", "currep", "nextupd");
printf(" %10d %10d %10d %10d %10d\n",
fade_globalData.led[i].waveCurrentId,
fade_globalData.led[i].waveCurrentValue,
fade_globalData.led[i].waveCurrentPosition,
fade_globalData.led[i].waveCurrentRepetition,
fade_globalData.led[i].waveNextUpdate);
printf("%10s %10s %10s %10s %10s %10s\n", "wave", "waveform", "length", "repeat", "duration", "updtime");
for (j = 0; j < 3; j++) {
printf("%10d %10d %10d %10d %10d %10d\n",
j,
fade_globalData.led[i].wave[j].waveformId,
fade_globalData.led[i].wave[j].waveformLength,
fade_globalData.led[i].wave[j].waveformRepetition,
fade_globalData.led[i].wave[j].waveformDuration,
fade_globalData.led[i].wave[j].waveformUpdateTime);
}
}
}
/**
* Reset the device.
* \param handle Handle to talk to the device.
* \param argc Number of arguments.
* \param argv Arguments.
*/
void dev_reset(usb_dev_handle *handle, int argc, char** argv) {
unsigned char buffer[8];
int nBytes;
if (argc != 2) {
usage(argv[0]);
exit(1);
}
nBytes = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CMD_RESET, 0, 0, (char *) buffer, sizeof(buffer), 5000);
if (nBytes < 0) {
fprintf(stderr, "USB error: %s\n", usb_strerror());
exit(1);
}
}
/**
* Show a waveform. This will not send a command to the device, the waveform is
* only printed on the screen.
* \param handle Handle to talk to the device (not needed).
* \param argc Number of arguments.
* \param argv Arguments.
*/
int dev_show(int argc, char **argv) {
if (argc != 3) {
usage(argv[0]);
exit(1);
}
int waveformId = atoi(argv[2]);
if ((waveformId < 0) || (waveformId > 38)) {
fprintf(stderr, "invalid waveformId: %d\n", waveformId);
exit(1);
}
int i, j;
int length = fade_calculateWaveform(waveformId, 0);
printf("wave %2d - length %2d\n", waveformId, length);
for (i = 31; i > 0; i--) {
printf("%2d: ", i);
for (j = 1; j <= length; j++) {
if (fade_calculateWaveform(waveformId, j) >= i) {
printf("*");
} else {
printf(" ");
}
}
printf("\n");
}
printf(" ");
for (j = 1; j <= length; j++) {
printf("=");
}
printf("\n");
exit(0);
}
/**
* Main function. Initializes the USB-device, parses commandline-parameters and
* calls the functions that communicate with the device.
* \param argc Number of arguments.
* \param argv Arguments.
* \return Error code.
*/
int main(int argc, char **argv)
{
usb_dev_handle *handle = NULL;
if (argc < 2) {
usage(argv[0]);
exit(1);
}
usb_init();
if (usbOpenDevice (&handle, USBDEV_SHARED_VENDOR, "www.schatenseite.de", USBDEV_SHARED_PRODUCT, "USB-LED-Fader") != 0) {
fprintf(stderr, "Could not find USB device \"USB-LED-Fader\" with vid=0x%x pid=0x%x\n", USBDEV_SHARED_VENDOR, USBDEV_SHARED_PRODUCT);
exit(1);
}
/* We have searched all devices on all busses for our USB device above. Now
* try to open it and perform the vendor specific control operations for the
* function requested by the user.
*/
if (strcmp(argv[1], "test") == 0) {
dev_test(handle, argc, argv);
} else if (strcmp(argv[1], "set") == 0) {
dev_set(handle, argc, argv);
} else if (strcmp(argv[1], "clear") == 0) {
dev_clear(handle, argc, argv);
} else if (strcmp(argv[1], "status") == 0) {
dev_status(handle, argc, argv);
} else if (strcmp(argv[1], "reset") == 0) {
dev_reset(handle, argc, argv);
} else if (strcmp(argv[1], "show") == 0) {
dev_reset(handle, argc, argv);
} else {
usage(argv[0]);
exit(1);
}
usb_close(handle);
return 0;
}

16
common/channels.h Normal file
View File

@ -0,0 +1,16 @@
#ifndef __channels_h_included__
#define __channels_h_included__
/**
* \file channels.h
* \brief Global definitions, used by the firmware and the commandline-client.
* \author Thomas Stegemann
* \version $Id: channels.h,v 1.1 2006/09/26 18:18:27 rschaten Exp $
*
* License: See documentation.
*/
#define CHANNELS 4 /**< number of output channels */
#endif

466
common/usbledfader.h Normal file
View File

@ -0,0 +1,466 @@
#ifndef __usbledfader_h_included__
#define __usbledfader_h_included__
/**
* \file usbledfader.h
* \brief Global definitions and datatypes, used by the firmware and the commandline-client. Also contains the main doxygen-documentation.
* \author Ronald Schaten & Thomas Stegemann
* \version $Id: usbledfader.h,v 1.1 2006/09/26 18:18:27 rschaten Exp $
*
* License: See documentation.
*/
/**
* \mainpage USB-LED-Fader
*
* \section sec_intro Introduction
*
* The USB-LED-Fader is a device to control a number of LEDs via USB. I built
* it to display the online-status of my internet-connection, the
* recording-status of my videorecorder, and warnings if the available
* disc-space is low. You can imagine an endless number of applications for
* this.
*
* The LEDs are controlled with pulse width modulation (PWM). That way, they
* are not only on or off, it is possible to control the brightness. Included
* in the device is a number of 'waveforms' that can be displayed on the LEDs.
* That way, one LED can display some kind of a sinus- or triangular wave
* without any interaction with the controlling host.
*
* Every LED can be controlled individually, each one can display it's own
* waveforms.
*
* You can assign three different waves to every LED: two 'eternal' waves (0 &
* 1). They are displayed alternating until anything different is required. The
* third wave (2) is only displayed once, afterwards the device will switch
* back to alternating between the first two waves.
*
* One wave is described by three parameters: the waveform, the duration for
* one repetition of the wave and the number of repetitions before switching to
* the next wave.
*
* This version supports four LEDs, it should be quite easy to change that
* number between one and eight. I have not tested any number greater than
* four, but I can imagine that the load on the controller can be too high to
* reliably communicate via USB.
*
* There are three parts included in the distribution: The firmware for an
* ATmega8 microcontroller, a commandline-client that can be run under Linux,
* and the circuits needed to build the device.
*
* This project is based on the PowerSwitch example application by Objective
* Development. Like that, it uses Objective Development's firmware-only USB
* driver for Atmel's AVR microcontrollers.
*
* Objective Development's USB driver is a firmware-only implementation of the
* USB 1.1 standard (low speed device) on cheap single chip microcomputers of
* Atmel's AVR series, such as the ATtiny2313 or even some of the small 8 pin
* devices. It implements the standard to the point where useful applications
* can be implemented. See the file "firmware/usbdrv/usbdrv.h" for features and
* limitations.
*
* \section sec_install Building and installing
*
* Both, the firmware and Unix command line tool are built with "make". You may
* need to customize both makefiles.
*
* \subsection sec_fw Firmware
*
* The firmware for this project requires avr-gcc and avr-libc (a C-library for
* the AVR controller). Please read the instructions at
* http://www.nongnu.org/avr-libc/user-manual/install_tools.html for how to
* install the GNU toolchain (avr-gcc, assembler, linker etc.) and avr-libc.
*
* Once you have the GNU toolchain for AVR microcontrollers installed, you can
* run "make" in the subdirectory "firmware". You may have to edit the Makefile
* to use your preferred downloader with "make program". The current version is
* built for avrdude with a parallel connection to an stk200-compatible
* programmer.
*
* If working with a brand-new controller, you may have to set the fuse-bits to
* use the external crystal:
*
* \code
* avrdude -p atmega8 -P /dev/parport0 -c sp12 -U hfuse:w:0xC9:m -U lfuse:w:0x9F:m
* \endcode
*
* Afterwards, you can compile and flash to the device:
*
* \code
* make program
* \endcode
*
* \subsection sec_client Commandline client
*
* The command line tool requires libusb. Please take the packages from your
* system's distribution or download libusb from http://libusb.sourceforge.net/
* and install it before you compile. Change to directory "commandline", check
* the Makefile and edit the settings if required and type
*
* \code
* make
* \endcode
*
* This will build the unix executable "usb-led-fader" which can be used to
* control the device.
*
* \section sec_usage Usage
*
* Connect the device to the USB-port. All LED should flash up to indicate that
* the device is initialized.
*
* Then use the commandline-client as follows:
*
* \code
* usb-led-fader status
* usb-led-fader set <ledId> <waveId> <waveformId> <periodDuration> <repetitionCount>
* usb-led-fader clear <ledId>
* usb-led-fader reset
* usb-led-fader show <waveformId>
* usb-led-fader test
* \endcode
*
* When using the set-function, it is possible to define several waves at once.
* You simply have to give the parameters for all waves. See examples below.
*
* \subsection sec_params Parameters
*
* - \e ledId: ID of the LED (0-n, depending on the number of LEDs in your
* circuit).
* - \e waveId: ID of the wave (0-1: constant waves, 2: override).
* - \e waveformId: ID of the waveform (0-31: brightness, 32-37: patterns). For
* a reference to the patterns, consult the function fade_calculateWaveform()
* in the file "firmware/main.c".
* - \e periodDuration: Time in sec/10 for one repetition of the waveform. A
* value of 0 can be used to reset the wave.
* - \e repetitionCount: Number of repetitions before switching to the next
* wave. A value of 0 can be used to repeat this forever.
*
* \subsection sec_examples Examples
*
* <b>Get the status of all LEDs:</b>
* \code
* usb-led-fader status
* \endcode
* This will result in an output similar to this:
* \code
* LED 0 curid curvalue curpos currep nextupd
* 0 2 26 0 23
* wave waveform length repeat duration updtime
* 0 38 32 1 20 45
* 1 0 1 1 0 1
* 2 0 1 1 0 1
* LED 1 curid curvalue curpos currep nextupd
* 0 14 19 0 19
* wave waveform length repeat duration updtime
* 0 38 32 1 20 45
* 1 0 1 1 0 1
* 2 0 1 1 0 1
* LED 2 curid curvalue curpos currep nextupd
* 0 31 16 0 43
* wave waveform length repeat duration updtime
* 0 38 32 1 20 45
* 1 0 1 1 0 1
* 2 0 1 1 0 1
* LED 3 curid curvalue curpos currep nextupd
* 0 6 9 0 39
* wave waveform length repeat duration updtime
* 0 38 32 1 20 45
* 1 0 1 1 0 1
* 2 0 1 1 0 1
* \endcode
* In this output, the values curvalue, curpos, nextupd and updtime are for
* debugging purposes only. They shouldn't be of interest to the common user.
* The meaning of the other values should be clear.
*
* <b>Set the first LED to keep a middle brightness:</b>
* \code
* usb-led-fader set 0 0 15 10 1
* \endcode
* So, on LED 0 the wave 0 is set to waveform 15. It will stay there for one
* second and will be repeated once before switching to the next wave. There is
* no next wave because we didn't define one, so this waveform will stay
* forever.
*
* <b>Now set a second wave on the first LED, a little brighter than the one
* before:</b>
* \code
* usb-led-fader set 0 1 25 10 1
* \endcode
* This is wave 1 on LED 0, waveform 25 indicates a constant level of
* brightness. After setting the second wave, it will alternate with the first
* one after every second, because both waves have the same duration and the
* same number of repetitions.
*
* <b>Set a third wave on the first LED:</b>
* \code
* usb-led-fader set 0 2 36 20 5
* \endcode
* This sets the third wave (wave 2) on the first LED. Waveform 36 is a nice
* sinus-like wave, so the LED starts to fade. One period of the fading takes 2
* seconds, it is repeated for 5 times. Since this is the third wave, after the
* repetitions the LED returns to alternating between wave 0 and wave 1, this
* wave is discarded.
*
* <b>Set multiple waves at once:</b>
* \code
* usb-led-fader set 0 0 15 10 1 0 1 25 10 1 0 2 36 20 5
* \endcode
* This will set all of the above waves at once. Thus, the first LED will first
* fade the sinus-wave five times, then start alternating between the two
* brightnesses in one-second-rhythm.
*
* <b>Clear the first LED:</b>
* \code
* usb-led-fader clear 0
* \endcode
* This will clear all three waves on the first LED.
*
* <b>Reset the device:</b>
* \code
* usb-led-fader reset
* \endcode
* All LEDs will flash once, to indicate that the device is reset and the LEDs
* are working.
*
* <b>Show a waveform on the screen:</b>
* \code
* usb-led-fader show 36
* \endcode
* This will lead to an output like the following:
* \code
* wave 36 - length 64
* 31: *****
* 30: *********
* 29: ***********
* 28: ***************
* 27: *****************
* 26: *******************
* 25: *******************
* 24: *********************
* 23: ***********************
* 22: *************************
* 21: *************************
* 20: ***************************
* 19: *****************************
* 18: *****************************
* 17: *******************************
* 16: *********************************
* 15: ***********************************
* 14: ***********************************
* 13: *************************************
* 12: ***************************************
* 11: ***************************************
* 10: *****************************************
* 9: *******************************************
* 8: *********************************************
* 7: *********************************************
* 6: ***********************************************
* 5: *************************************************
* 4: *****************************************************
* 3: *******************************************************
* 2: ***********************************************************
* 1: ****************************************************************
* ================================================================
* \endcode
* Keep in mind that the width of the displayed wave corresponds to the length
* of the waveform. If you display a very simple one like the constant
* brightness levels (0-31), the length is 1. Therefore only one column is
* displayed.
*
* <b>Test the device:</b>
* \code
* usb-led-fader test
* \endcode
* This function sends many random numbers to the device. The device returns
* the packages, and the client looks for differences in the sent and the
* received numbers.
*
* \section sec_drawbacks Drawbacks
*
* As mentioned above, controlling the PWM for several LEDs is a lot of work
* for one small microcontroller. Speaking the USB protocol is so, either. Both
* combined result in a lot of load on the device, so the communication with
* the device is not 100% reliable. More than 99% though, at least in our
* tests.
*
* <b>SO BE WARNED:</b> You should not use this device to control the state of
* your nuclear reactor. If you intend to use it in that way despite of this
* warning, please let me know... ;-)
*
*
* \section sec_files Files in the distribution
*
* - \e Readme.txt: The file you are currently reading.
* - \e firmware: Source code of the controller firmware.
* - \e firmware/usbdrv: USB driver -- See Readme.txt in this directory for
* info
* - \e commandline: Source code of the host software (needs libusb).
* - \e common: Files needed by the firmware and the commandline-client.
* - \e circuit: Circuit diagrams in PDF and EAGLE 4 format. A free version of
* EAGLE is available for Linux, Mac OS X and Windows from
* http://www.cadsoft.de/.
* - \e License.txt: Public license for all contents of this project, except
* for the USB driver. Look in firmware/usbdrv/License.txt for further info.
* - \e Changelog.txt: Logfile documenting changes in soft-, firm- and
* hardware.
*
* \section sec_thanks Thanks!
*
* I'd like to thank <b>Objective Development</b> for the possibility to use
* their driver for my project. In fact, this project wouldn't exist without
* the driver.
*
* And I'd like to give special credits to <b>Thomas Stegemann</b>. He wrote
* the PWM-stuff, and I guess it would have been nearly to impossible to me to
* write the rest of the project without his help since C isn't my natural
* language.
*
* \section sec_license About the license
*
* Our work - all contents except for the USB driver - are licensed under the
* GNU General Public License (GPL). A copy of the GPL is included in
* License.txt. The driver itself is licensed under a special license by
* Objective Development. See firmware/usbdrv/License.txt for further info.
*
* <b>(c) 2006 by Ronald Schaten - http://www.schatenseite.de</b>
*/
#include <stdint.h>
/* return codes for USB-communication */
#define msgOK 0 /**< Return code for OK. */
#define msgErr 1 /**< Return code for Error. */
/* These are the vendor specific SETUP commands implemented by our USB device */
#define CMD_ECHO 0 /**< Command to echo the sent data */
#define CMD_GET 1 /**< Command to fetch values */
#define CMD_SET 2 /**< Command to send values */
#define CMD_CLEAR 3