mirror of https://github.com/logchan/chuni-hands
support using chuniio.dll (maybe)
parent
c5d684db64
commit
20e50491d7
|
@ -0,0 +1,39 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.IO.MemoryMappedFiles;
|
||||||
|
using System.Security.Principal;
|
||||||
|
|
||||||
|
namespace chuni_hands {
|
||||||
|
internal static class ChuniIO {
|
||||||
|
public static MemoryMappedFile _buffer;
|
||||||
|
public static MemoryMappedViewAccessor _accessor;
|
||||||
|
|
||||||
|
private static bool _init = false;
|
||||||
|
|
||||||
|
public static void Send(IList<Sensor> sensors) {
|
||||||
|
if (!_init) {
|
||||||
|
Initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
var data = new byte[6];
|
||||||
|
for (var i = 0; i < 6; ++i) {
|
||||||
|
data[i] = (byte) (sensors[i].Active ? 0x80 : 0x00);
|
||||||
|
}
|
||||||
|
|
||||||
|
_accessor.WriteArray<byte>(0, data, 0, 6);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void Initialize() {
|
||||||
|
var security = new MemoryMappedFileSecurity();
|
||||||
|
var sid = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
|
||||||
|
var account = sid.Translate(typeof(NTAccount)) as NTAccount;
|
||||||
|
|
||||||
|
Debug.Assert(account != null);
|
||||||
|
security.AddAccessRule(new System.Security.AccessControl.AccessRule<MemoryMappedFileRights>(account.ToString(), MemoryMappedFileRights.FullControl, System.Security.AccessControl.AccessControlType.Allow));
|
||||||
|
_buffer = MemoryMappedFile.CreateOrOpen("Local\\BROKENITHM_SHARED_BUFFER", 1024, MemoryMappedFileAccess.ReadWrite, MemoryMappedFileOptions.None, security, System.IO.HandleInheritability.Inheritable);
|
||||||
|
_accessor = _buffer.CreateViewAccessor();
|
||||||
|
|
||||||
|
_init = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -81,10 +81,14 @@ namespace chuni_hands {
|
||||||
|
|
||||||
switch (_config.SendKeyMode) {
|
switch (_config.SendKeyMode) {
|
||||||
case "be": {
|
case "be": {
|
||||||
var airKeys = String.Concat(from sensor in _sensors select sensor.Active ? "1" : "0");
|
var airKeys = String.Concat(from sensor in _sensors select sensor.Active ? "1" : "0");
|
||||||
_http.GetAsync(_config.EndPoint + "?k=" + airKeys);
|
_http.GetAsync(_config.EndPoint + "?k=" + airKeys);
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
case "chuni_io": {
|
||||||
|
ChuniIO.Send(_sensors);
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
throw new Exception("unknown SendKeyMode");
|
throw new Exception("unknown SendKeyMode");
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,6 +89,7 @@
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
</ApplicationDefinition>
|
</ApplicationDefinition>
|
||||||
<Compile Include="ChuniCanvas.cs" />
|
<Compile Include="ChuniCanvas.cs" />
|
||||||
|
<Compile Include="ChuniIO.cs" />
|
||||||
<Compile Include="Config.cs" />
|
<Compile Include="Config.cs" />
|
||||||
<Compile Include="Helpers.cs" />
|
<Compile Include="Helpers.cs" />
|
||||||
<Compile Include="Logger.cs" />
|
<Compile Include="Logger.cs" />
|
||||||
|
|
Loading…
Reference in New Issue