-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathProgram.cs
More file actions
127 lines (92 loc) · 2.54 KB
/
Program.cs
File metadata and controls
127 lines (92 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
using System;
using System.Net.NetworkInformation;
using System.Threading;
using System.Net;
using Android.OS;
using PCLAppConfig;
namespace Joycon
{
// Custom timer class because system timers have a limit of 15.6ms
class HighResTimer
{
double interval = 0;
double frequency = 0;
Thread thread;
public delegate void ActionDelegate();
ActionDelegate func;
bool run = false;
public HighResTimer(double f, ActionDelegate a)
{
frequency = f;
interval = 1.0 / f;
func = a;
}
public void Start()
{
run = true;
thread = new Thread(new ThreadStart(Run));
thread.IsBackground = true;
thread.Start();
}
void Run()
{
while (run)
{
func();
int timeToSleep = (int)(interval * 1000);
Thread.Sleep(timeToSleep);
}
}
public void Stop()
{
run = false;
}
}
public class Program
{
public static PhysicalAddress btMAC = new PhysicalAddress(new byte[] { 0, 0, 0, 0, 0, 0 });
public static UdpServer server;
static double pollsPerSecond = 120.0;
//private static readonly HttpClient client = new HttpClient();
public static JoyconManager mgr;
static HighResTimer timer;
static string pid;
static MainActivity mActivity;
static public bool useHIDG = Boolean.Parse(ConfigurationManager.AppSettings["UseHIDG"]);
//private static WindowsInput.Events.Sources.IKeyboardEventSource keyboard;
//private static WindowsInput.Events.Sources.IMouseEventSource mouse;
public static void Start(MainActivity m)
{
Program.mActivity = m;
pid = Process.MyPid().ToString(); // get current process id for HidCerberus.Srv
foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
{
// Get local BT host MAC
if (nic.NetworkInterfaceType != NetworkInterfaceType.FastEthernetFx && nic.NetworkInterfaceType != NetworkInterfaceType.Wireless80211)
{
if (nic.Name.Split()[0] == "Bluetooth")
{
btMAC = nic.GetPhysicalAddress();
}
}
}
mgr = new JoyconManager();
mgr.mActivity = mActivity;
mgr.Awake();
mgr.CheckForNewControllers();
mgr.Start();
server = new UdpServer(mgr.j);
server.mActivity = mActivity;
server.Start(IPAddress.Parse(ConfigurationManager.AppSettings["IP"]), Int32.Parse(ConfigurationManager.AppSettings["Port"]));
timer = new HighResTimer(pollsPerSecond, new HighResTimer.ActionDelegate(mgr.Update));
timer.Start();
mActivity.console.Append("All systems go\r\n");
}
public static void Stop()
{
server.Stop();
timer.Stop();
mgr.OnApplicationQuit();
}
}
}