Skip to content

Commit 2e38d9c

Browse files
authored
Merge pull request #1 from voltaney/doc/refactor-readme
Enhanced the description in the Readme.md.
2 parents 529c3eb + 9b345b6 commit 2e38d9c

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

README.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,76 @@
11
# TouchSenderInterpreter
2+
3+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
4+
[![NuGet Version](https://img.shields.io/nuget/v/Voltaney.TouchSenderInterpreter)](https://www.nuget.org/packages/Voltaney.TouchSenderInterpreter/)
5+
[![CI](https://github.com/voltaney/TouchSenderInterpreter/actions/workflows/ci.yml/badge.svg)](https://github.com/voltaney/TouchSenderInterpreter/actions/workflows/ci.yml)
6+
![dotnet Version](https://img.shields.io/badge/.NET-8.0-blueviolet)
7+
8+
Parser library for data sent from the mobile application **Touch Sender**.
9+
10+
## Usage
11+
12+
Example of receiving data from **Touch Sender** via UDP and parsing its contents to display touch states.
13+
14+
```csharp
15+
using System.Net;
16+
using System.Net.Sockets;
17+
using TouchSenderInterpreter;
18+
19+
namespace ConsoleApp1;
20+
21+
class Program
22+
{
23+
static void Main(string[] args)
24+
{
25+
int port = 50000;
26+
IPEndPoint? senderEP = null;
27+
28+
// Ctrl + C to quit
29+
using (var udpClient = new UdpClient(port))
30+
{
31+
while (true)
32+
{
33+
var recievedData = udpClient.Receive(ref senderEP);
34+
// parse recieved data of Touch Sender
35+
var result = Interpreter.Read(recievedData);
36+
if (result.IsSuccess)
37+
{
38+
// print SingleTouchRatio
39+
Console.WriteLine(result.Payload?.SingleTouchRatio);
40+
}
41+
else
42+
{
43+
Console.WriteLine("Failed to parse Touch Sender data");
44+
Console.WriteLine(result.ErrorMessage);
45+
}
46+
}
47+
}
48+
}
49+
}
50+
```
51+
52+
## Result Structure
53+
54+
If the JSON data is successfully parsed, a result object with the following structure is obtained.
55+
56+
```json
57+
{
58+
"Payload": {
59+
"Id": 538,
60+
"DeviceInfo": {
61+
"Width": 360,
62+
"Height": 800
63+
},
64+
"SingleTouch": {
65+
"X": 248.33333333333334,
66+
"Y": 387
67+
},
68+
"SingleTouchRatio": {
69+
"X": 0.6898148148148149,
70+
"Y": 0.48375
71+
}
72+
},
73+
"IsSuccess": true,
74+
"ErrorMessage": null
75+
}
76+
```

0 commit comments

Comments
 (0)