Created
July 4, 2020 21:42
-
-
Save nikvoronin/389e4d27067f9542e1d43c9a384c15c9 to your computer and use it in GitHub Desktop.
Old stuff USB Webmail Notifier #LibUsbDotNet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using LibUsbDotNet.LibUsb; | |
using LibUsbDotNet.Main; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Threading; | |
namespace UsbWebmailNotifier | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
const ushort VID = 0x1294; | |
const ushort PID = 0x1320; | |
using IUsbContext usb = new UsbContext(); | |
var dev = usb.List() | |
.FirstOrDefault(device => device.ProductId == PID && device.VendorId == VID); | |
if (dev == null) { | |
Console.WriteLine("Webmail Notifier not found :("); | |
goto fin; | |
} | |
dev.Open(); | |
dev.ClaimInterface(dev.Configs[0].Interfaces[0].Number); | |
var writer = dev.OpenEndpointWriter(WriteEndpointID.Ep02); // (WriteEndpointID) 129 | |
var cmd = new Dictionary<string, byte[]> { | |
["off"] = new byte[]{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
["green"] = new byte[]{ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
["red"] = new byte[]{ 0x02, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
["blue"] = new byte[]{ 0x03, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
["cyan"] = new byte[]{ 0x04, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
["yellow"] = new byte[]{ 0x05, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
["magenta"] = new byte[]{ 0x06, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
["white"] = new byte[]{ 0x07, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
}; | |
while (!Console.KeyAvailable) { | |
we(cmd["off"]); | |
Thread.Sleep(500); | |
if (Console.KeyAvailable) | |
break; | |
we(cmd["red"]); | |
Thread.Sleep(500); | |
} | |
we(cmd["off"]); | |
dev.Close(); | |
fin: | |
Console.WriteLine("Press Enter to exit..."); | |
Console.ReadLine(); | |
void we(byte[] buffer) | |
{ | |
writer.Write(buffer, 100, out int writen); | |
Console.WriteLine($"Written {writen} bytes"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment