Enhance the HotmailNotifier project so that the LEDs' individual brightness can be controlled individually via software PWM.

pull/1469/head
Dean Camera 15 years ago
parent 2cab8f0725
commit 3d6508c9b9

File diff suppressed because one or more lines are too long

@ -0,0 +1,37 @@
/** \file
*
* This file contains special DoxyGen information for the generation of the main page and other special
* documentation pages. It is not a project source file.
*/
/**
* \page Page_AlternativeStacks Alternative USB AVR Stacks
*
* LUFA is not the only stack available for the USB AVRs, although it is perhaps the best (\see Page_WhyUseLUFA).
* In the interests of completeness and user choice, other known USB AVR stacks are listed here.
*
* - Atmel USB AVR Stack (<i>Atmel Inc.</i>) \n
* <b>Cost:</b> Free \n
* <b>License:</b> Atmel Limited License (see Atmel download for details) \n
* <b>Website:</b> http://atmel.com/dyn/products/app_notes.asp?family_id=607#USB \n
* <b>Description:</b> This is the official Atmel USB AVR stack, for their 8-bit USB AVR lineup. Each series of
* USB AVR is seperated into a seperate download stack, which is both AVR-GCC and IAR compatible.
*
* - Dr. Stefan Salewski's AT90USB1287 Stack (<i>Dr. Stefan Salewski</i>) \n
* <b>Cost:</b> Free \n
* <b>License:</b> GPL \n
* <b>Website:</b> http://www.ssalewski.de/AT90USB_firmware.html.en \n
* <b>Description:</b> This is a GPL'd library specifically designed for the AT90USB1287, by Dr. Stefan Salewski, a
* German Physicist. It compiles for AVR-GCC and can potentially be modified to work on other USB
* AVR models.
*
* - PJRC Teensy Stack (<i>Paul Stoffregen</i>) \n
* <b>Cost:</b> Free \n
* <b>License:</b> BSD \n
* <b>Website:</b> http://www.pjrc.com/teensy/usb_debug_only.html \n
* <b>Description:</b> Not so much a complete stack as a collection of USB enabled demos, this library is specifically
* designed for the PJRC Teensy line of USB AVRs, and thus may need to be modified for other USB AVR
* chips. These code samples shows the inner workings of the USB controller, without all the abstraction
* present in most other USB AVR stacks.
*/

@ -17,6 +17,7 @@
* -# Add ability to get number of bytes not written with pipe/endpoint write routines after an error
* -# Add standardized descriptor names to class driver structures
* -# Correct mishandling of error cases in Mass Storage demos
* -# Add TPI programming support to the AVRISP project
* - Documentation/Support
* -# Remake AVRStudio project files
* -# Add detailed overviews of how each demo works

@ -33,8 +33,9 @@
* <b>Subsections:</b>
* - \subpage Page_WhyUseLUFA Why Use LUFA?
* - \subpage Page_LUFAvsAtmelStack How does LUFA compare to the Atmel USB AVR stack?
* - \subpage Page_AlternativeStacks Alternative USB AVR Stacks
* - \subpage Page_Licence Project licence
* - \subpage Page_Donating Donating to Support this Project
* - \subpage Page_Donating Donating to support this project
* - \subpage Page_LibraryApps Overview of included Demos, Bootloaders and Projects
*
* <small><i>Logo design by EDIGMA.COM</i></small>

@ -60,6 +60,39 @@ USB_ClassInfo_CDC_Device_t VirtualSerial_CDC_Interface =
},
};
/** Counter for the software PWM */
static volatile uint8_t SoftPWM_Count;
/** Duty cycle for the first software PWM channel */
static volatile uint8_t SoftPWM_Channel1_Duty;
/** Duty cycle for the second software PWM channel */
static volatile uint8_t SoftPWM_Channel2_Duty;
/** Duty cycle for the third software PWM channel */
static volatile uint8_t SoftPWM_Channel3_Duty;
/** Interrupt handler for managing the software PWM channels for the LEDs */
ISR(TIMER0_COMPA_vect, ISR_BLOCK)
{
uint8_t LEDMask = LEDS_ALL_LEDS;
if (++SoftPWM_Count == 0x1F)
SoftPWM_Count = 0;
if (SoftPWM_Count >= SoftPWM_Channel1_Duty)
LEDMask &= ~LEDS_LED1;
if (SoftPWM_Count >= SoftPWM_Channel2_Duty)
LEDMask &= ~LEDS_LED2;
if (SoftPWM_Count >= SoftPWM_Channel3_Duty)
LEDMask &= ~LEDS_LED3;
LEDs_SetAllLEDs(LEDMask);
}
/** Standard file stream for the CDC interface when set up, so that the virtual CDC COM port can be
* used like any regular character stream in the C APIs
*/
@ -77,11 +110,21 @@ int main(void)
for (;;)
{
/* Read next character - if a '1' turn on red led, if a '0' turn on green LED */
if (fgetc(&USBSerialStream) == '1')
LEDs_SetAllLEDs(LEDS_LED3);
else
LEDs_SetAllLEDs(LEDS_LED2);
/* Read in next LED colour command from the host */
uint8_t ColorUpdate = fgetc(&USBSerialStream);
/* Top 3 bits select the LED, bottom three control the brightness */
uint8_t Channel = (ColorUpdate & 0b11100000);
uint8_t Duty = (ColorUpdate & 0b00011111);
if (Channel & (1 << 5))
SoftPWM_Channel1_Duty = Duty;
if (Channel & (1 << 6))
SoftPWM_Channel2_Duty = Duty;
if (Channel & (1 << 7))
SoftPWM_Channel3_Duty = Duty;
CDC_Device_USBTask(&VirtualSerial_CDC_Interface);
USB_USBTask();
@ -101,15 +144,18 @@ void SetupHardware(void)
/* Hardware Initialization */
LEDs_Init();
USB_Init();
/* Timer Initialization */
OCR0A = 100;
TCCR0A = (1 << WGM01);
TCCR0B = (1 << CS00);
TIMSK0 = (1 << OCIE0A);
}
/** Event handler for the library USB Configuration Changed event. */
void EVENT_USB_Device_ConfigurationChanged(void)
{
LEDs_SetAllLEDs(LEDS_ALL_LEDS);
if (!(CDC_Device_ConfigureEndpoints(&VirtualSerial_CDC_Interface)))
LEDs_SetAllLEDs(LEDS_LED1 | LEDS_LED3);
CDC_Device_ConfigureEndpoints(&VirtualSerial_CDC_Interface);
}
/** Event handler for the library USB Unhandled Control Request event. */

@ -14,6 +14,8 @@ namespace TestWinForms
private MessengerAPI.Messenger Messenger;
private RegistryKey AppRegKey;
private const int LIGHT_MAX = 0x1F;
public MailNotifier()
{
InitializeComponent();
@ -34,7 +36,9 @@ namespace TestWinForms
private void MailNotifier_Load(object sender, EventArgs e)
{
Messenger.OnUnreadEmailChange += new MessengerAPI.DMessengerEvents_OnUnreadEmailChangeEventHandler(NewEmail);
NotifyLight(Messenger.get_UnreadEmailCount(MessengerAPI.MUAFOLDER.MUAFOLDER_INBOX) > 0);
bool UnreadMail = (Messenger.get_UnreadEmailCount(MessengerAPI.MUAFOLDER.MUAFOLDER_INBOX) > 0);
NotifyLight((!UnreadMail ? LIGHT_MAX : 0), (UnreadMail ? LIGHT_MAX : 0), 0);
Hide();
}
@ -48,18 +52,23 @@ namespace TestWinForms
private void NewEmail(MessengerAPI.MUAFOLDER folder, int amount, ref bool enableDefault)
{
if (folder == MessengerAPI.MUAFOLDER.MUAFOLDER_INBOX)
NotifyLight(amount > 0);
{
bool UnreadMail = (Messenger.get_UnreadEmailCount(MessengerAPI.MUAFOLDER.MUAFOLDER_INBOX) > 0);
NotifyLight((!UnreadMail ? LIGHT_MAX : 0), (UnreadMail ? LIGHT_MAX : 0), 0);
}
}
private void NotifyLight(bool ShowGreen)
private void NotifyLight(int Red, int Green, int Blue)
{
char[] buffer = new char[1];
buffer[0] = ShowGreen ? '0' : '1';
byte[] buffer = new byte[3];
buffer[0] = (byte)(0x80 | (Red & LIGHT_MAX));
buffer[1] = (byte)(0x40 | (Green & LIGHT_MAX));
buffer[2] = (byte)(0x20 | (Blue & LIGHT_MAX));
try
{
serSerialPort.Open();
serSerialPort.Write(buffer, 0, 1);
serSerialPort.Write(buffer, 0, buffer.Length);
serSerialPort.Close();
}
catch (Exception e)
@ -78,15 +87,20 @@ namespace TestWinForms
AppRegKey.SetValue("Port", cmbComPort.SelectedIndex + 1);
serSerialPort.PortName = cmbComPort.Text;
for (int i = 0; i < 5; i++)
for (int i = 1; i < 10; i++)
{
NotifyLight((LIGHT_MAX / i), (LIGHT_MAX / (i * 10)), 0);
System.Threading.Thread.Sleep(10);
}
for (int i = 10; i > 0; i--)
{
NotifyLight(true);
System.Threading.Thread.Sleep(20);
NotifyLight(false);
System.Threading.Thread.Sleep(20);
NotifyLight((LIGHT_MAX / i), (LIGHT_MAX / (i * 10)), 0);
System.Threading.Thread.Sleep(10);
}
NotifyLight(Messenger.get_UnreadEmailCount(MessengerAPI.MUAFOLDER.MUAFOLDER_INBOX) > 0);
bool UnreadMail = (Messenger.get_UnreadEmailCount(MessengerAPI.MUAFOLDER.MUAFOLDER_INBOX) > 0);
NotifyLight((!UnreadMail ? LIGHT_MAX : 0), (UnreadMail ? LIGHT_MAX : 0), 0);
}
private void btnMinimize_Click(object sender, EventArgs e)

Loading…
Cancel
Save