mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Created Adding a non-keyboard device yourself (markdown)
parent
0ea21d9007
commit
9147363a54
92
Adding-a-non-keyboard-device-yourself.md
Normal file
92
Adding-a-non-keyboard-device-yourself.md
Normal file
@ -0,0 +1,92 @@
|
||||
Adding a new RGB device to Artemis is relatively simple. This guide assumes you already have some C# knowledge and got Artemis to compile in Visual Studio.
|
||||
|
||||
### Step 1
|
||||
Create a new folder in the DeviceProviders folder, in this case called MyDevice
|
||||

|
||||
|
||||
### Step 2
|
||||
Inside the folder create a new class called MyDeviceGeneric, if you're adding a mouse name it MyDeviceMouse etc.
|
||||
|
||||
### Step 3
|
||||
Make this new class public and implement DeviceProvider so you end up with something like this:
|
||||
```cs
|
||||
using System;
|
||||
using System.Drawing;
|
||||
|
||||
namespace Artemis.DeviceProviders.MyDevice
|
||||
{
|
||||
public class MyDeviceGeneric : DeviceProvider
|
||||
{
|
||||
public override void UpdateDevice(Bitmap bitmap)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override bool TryEnable()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void Disable()
|
||||
{
|
||||
// Disable doesn't need to be implemented since this isn't a keyboard (this may change)
|
||||
throw new NotSupportedException("Can only disable a keyboard");
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Step 4
|
||||
Implement the methods. You can do this however you like, just keep in mind that UpdateDevice is called 25 times a second, or ever 40 ms, so make sure it's quick.
|
||||
|
||||
A super simple untested example using a serial port to talk to an Arduino:
|
||||
```cs
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.IO.Ports;
|
||||
|
||||
namespace Artemis.DeviceProviders.MyDevice
|
||||
{
|
||||
public class MyDeviceGeneric : DeviceProvider
|
||||
{
|
||||
private SerialPort _port;
|
||||
|
||||
public override void UpdateDevice(Bitmap bitmap)
|
||||
{
|
||||
if (bitmap == null)
|
||||
return;
|
||||
|
||||
// If the device that's being implemented only has one LED, simply take the color
|
||||
// of the pixel in the middle of the bitmap
|
||||
var color = bitmap.GetPixel(bitmap.Width / 2, bitmap.Height / 2);
|
||||
|
||||
// Write the color to the device
|
||||
_port.WriteLine(color.ToString());
|
||||
}
|
||||
|
||||
public override bool TryEnable()
|
||||
{
|
||||
// Do a check here to see if your device is available. Make sure you set CanUse so
|
||||
// Artemis knows it's available.
|
||||
CanUse = true;
|
||||
|
||||
// Lets open a COM1 connection, this could be an Arduino or something similar
|
||||
if (CanUse)
|
||||
{
|
||||
_port = new SerialPort("COM1", 9600);
|
||||
_port.Open();
|
||||
}
|
||||
|
||||
return CanUse;
|
||||
}
|
||||
|
||||
public override void Disable()
|
||||
{
|
||||
// Disable doesn't need to be implemented since this isn't a keyboard (this may change)
|
||||
throw new NotSupportedException("Can only disable a keyboard");
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
If you have something that works well and is useful for others, please consider making a pull request! :)
|
||||
Loading…
x
Reference in New Issue
Block a user