-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRadioDataUtility.cs
More file actions
38 lines (27 loc) · 905 Bytes
/
RadioDataUtility.cs
File metadata and controls
38 lines (27 loc) · 905 Bytes
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
using System;
using Ship.Interface.Model.Parts.State;
namespace Radio;
public static class RadioDataUtility
{
public struct Indecies
{
public const int IsEnabledByte = 0;
}
public static byte[] RadioDataBytes(this LeverState state)
{
return BitConverter.GetBytes(state.LeverHeight);
}
public static bool IsRadioEnabled(this LeverState state)
{
byte isEnabledByte = state.RadioDataBytes()[Indecies.IsEnabledByte];
bool isEnabled = isEnabledByte != 0;
return isEnabled;
}
public static LeverState WithRadioEnabled(this LeverState state, bool isEnabled)
{
byte[] data = state.RadioDataBytes();
data[Indecies.IsEnabledByte] = isEnabled? (byte)1 : (byte)0;
float convertedData = BitConverter.ToSingle(data);
return new LeverState { LeverHeight = convertedData };
}
}