mirror of
https://github.com/maker-community/ElectronBot.DotNet.git
synced 2026-10-21 16:36:33 +08:00
112 lines
6.1 KiB
C#
112 lines
6.1 KiB
C#
// See https://aka.ms/new-console-template for more information
|
|
using Google.Protobuf;
|
|
using HelloWordKeyboard.DotNet;
|
|
using HidApi;
|
|
using SixLabors.ImageSharp;
|
|
using SixLabors.ImageSharp.PixelFormats;
|
|
using SixLabors.ImageSharp.Processing;
|
|
using UsbComm;
|
|
|
|
//byte[] byteArray = new byte[128 * 36 / 8] { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xcf, 0xff, 0x81, 0xff, 0xff, 0xe0, 0x7f, 0xff, 0xe7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8f, 0xfe, 0x0, 0x7f, 0xff, 0x80, 0x1f, 0xff, 0xc7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf, 0xfc, 0x0, 0x3f, 0xff, 0x0, 0xf, 0xff, 0x87, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xf, 0xf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ff, 0xff, 0xff, 0xff, 0x8f, 0xe3, 0xff, 0x1f, 0xfc, 0x7f, 0xe3, 0x0, 0x0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8f, 0xe3, 0xff, 0x1f, 0xfc, 0x7f, 0xe3, 0x0, 0x0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8f, 0xf1, 0xff, 0x1f, 0xfe, 0x3f, 0xc7, 0x0, 0x0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8f, 0xf1, 0xfe, 0x3f, 0xfe, 0x3f, 0xc7, 0xff, 0xc7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8f, 0xf8, 0x7c, 0x3f, 0xfe, 0xf, 0x7, 0xff, 0xc7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8f, 0xf8, 0x0, 0x7e, 0x3f, 0x0, 0xf, 0xff, 0xc7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8f, 0xfc, 0x0, 0xfe, 0x3f, 0x80, 0x1f, 0xff, 0xc7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8f, 0xff, 0x3, 0xfe, 0x3f, 0xe0, 0x7f, 0xff, 0xc7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
|
|
|
|
byte[] byteArray = new byte[128 * 296 / 8];
|
|
|
|
//using (var image = Image.Load<Rgba32>("default.jpg"))
|
|
//{
|
|
// // 应用灰度和二值化处理
|
|
// image.Mutate(x => x.Grayscale().BinaryThreshold(0.5f));
|
|
|
|
// // 保存处理后的图片
|
|
// image.Save("output.jpg");
|
|
// // 将处理后的图片转换为字节数组
|
|
// //using (MemoryStream ms = new MemoryStream())
|
|
// //{
|
|
// // image.Save(ms, new JpegEncoder());
|
|
// // byteArray = ms.ToArray();
|
|
// //}
|
|
|
|
// image.CopyPixelDataTo(byteArray);
|
|
//}
|
|
|
|
|
|
//using (Image<Rgba32> image = new Image<Rgba32>(128, 36))
|
|
//{
|
|
// image.Mutate(x => x.BackgroundColor(Color.Black));
|
|
|
|
// using (Image<L8> grayImage = image.CloneAs<L8>())
|
|
// {
|
|
// image.CopyPixelDataTo(byteArray);
|
|
// // 将图像转换为字节数组
|
|
// using (MemoryStream ms = new MemoryStream())
|
|
// {
|
|
// grayImage.SaveAsBmp(ms);
|
|
// byte[] bytes1 = ms.ToArray();
|
|
|
|
// // 计算二值图像的字节数
|
|
// int byteCount = grayImage.Width * grayImage.Height / 8;
|
|
// Console.WriteLine($"Expected byte count: {byteCount}");
|
|
// Console.WriteLine($"Actual byte count: {bytes1.Length}");
|
|
// }
|
|
// }
|
|
|
|
|
|
//}
|
|
|
|
var hidDevice = new Hw75DynamicDevice();
|
|
|
|
hidDevice.Open();
|
|
|
|
var data111 = hidDevice.SetEInkImage(byteArray, 0, 0, 128, 296, false);
|
|
|
|
for (int i = 0; i < byteArray.Length; i++)
|
|
{
|
|
byteArray[i] = 0xff;
|
|
}
|
|
|
|
Thread.Sleep(2000);
|
|
|
|
var data11122 = hidDevice.SetEInkImage(byteArray, 0, 0, 128, 296, false);
|
|
|
|
//var data = hidDevice.GetVersion();
|
|
//var data11 = hidDevice.GetMotorState();
|
|
Console.ReadKey();
|
|
|
|
var device = new Device("\\\\?\\hid#vid_1d50&pid_615e&mi_01#8&a8a6dc9&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}"); //Fill vendor id and product id
|
|
|
|
Console.WriteLine(device.GetManufacturer());
|
|
|
|
Console.WriteLine(device.GetDeviceInfo());
|
|
|
|
//device.SetNonBlocking(true);
|
|
|
|
var hidMesage = new UsbComm.MessageH2D
|
|
{
|
|
Action = UsbComm.Action.Version
|
|
};
|
|
|
|
var bytes = hidMesage.ToByteArray();
|
|
|
|
var listByte = new List<byte>();
|
|
listByte.Add(1);
|
|
listByte.Add((byte)(bytes.Length + 1));
|
|
listByte.Add((byte)(bytes.Length));
|
|
listByte.AddRange(bytes);
|
|
|
|
|
|
listByte.AddRange(new byte[64 - listByte.Count]);
|
|
|
|
var buffer = listByte.ToArray();
|
|
|
|
device.Write(buffer);
|
|
|
|
Task.Delay(20);
|
|
var read = device.Read(64);
|
|
|
|
var result = read[3..(read[2] + 3)];
|
|
|
|
|
|
//var data = MessageD2H.Parser.ParseFrom(result);
|
|
//Console.WriteLine(data);
|
|
|
|
//Hid.Exit(); //Call at the end of your program
|