2023-08-16 19:47:14 +02:00
|
|
|
/*
|
|
|
|
godotVmcSharp
|
|
|
|
Copyright (C) 2023 Cassandra de la Cruz-Munoz
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Affero General Public License as published
|
|
|
|
by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
using godotOscSharp;
|
|
|
|
using Godot;
|
2023-08-17 15:27:59 +02:00
|
|
|
using System.Collections.Generic;
|
2023-08-16 19:47:14 +02:00
|
|
|
|
|
|
|
namespace godotVmcSharp
|
|
|
|
{
|
|
|
|
public class VmcExtOk : VmcMessage
|
|
|
|
{
|
|
|
|
public int loaded { get; private set; }
|
|
|
|
public int? calibrationState { get; private set; }
|
|
|
|
public int? calibrationMode { get; private set; }
|
|
|
|
public int? trackingStatus { get; private set; }
|
|
|
|
|
|
|
|
public VmcExtOk(int _loaded) : base(new godotOscSharp.Address("/VMC/Ext/OK"))
|
|
|
|
{
|
2023-08-17 02:17:27 +02:00
|
|
|
if (_loaded < 0 || _loaded > 1)
|
|
|
|
{
|
|
|
|
GD.Print($"Invalid value for loaded status. Expected 0 or 1, received {_loaded}.");
|
2023-08-17 15:27:59 +02:00
|
|
|
return;
|
2023-08-17 02:17:27 +02:00
|
|
|
}
|
2023-08-16 19:47:14 +02:00
|
|
|
loaded = _loaded;
|
|
|
|
}
|
|
|
|
|
|
|
|
public VmcExtOk(int _loaded, int _calibrationState, int _calibrationMode) : base(new godotOscSharp.Address("/VMC/Ext/OK"))
|
|
|
|
{
|
2023-08-17 02:17:27 +02:00
|
|
|
if (_loaded < 0 || _loaded > 1)
|
|
|
|
{
|
|
|
|
GD.Print($"Invalid value for loaded status. Expected 0 or 1, received {_loaded}.");
|
2023-08-17 15:27:59 +02:00
|
|
|
return;
|
2023-08-17 02:17:27 +02:00
|
|
|
}
|
|
|
|
if (_calibrationState < 0 || _calibrationState > 3)
|
|
|
|
{
|
|
|
|
GD.Print($"Invalid value for calibration state. Expected 0-3, received {_calibrationState}");
|
2023-08-17 15:27:59 +02:00
|
|
|
return;
|
2023-08-17 02:17:27 +02:00
|
|
|
}
|
|
|
|
if (_calibrationMode < 0 || _calibrationMode > 2)
|
|
|
|
{
|
|
|
|
GD.Print($"Invalid value for calibration mode. Expected 0-2, received {_calibrationMode}");
|
2023-08-17 15:27:59 +02:00
|
|
|
return;
|
2023-08-17 02:17:27 +02:00
|
|
|
}
|
2023-08-16 19:47:14 +02:00
|
|
|
loaded = _loaded;
|
|
|
|
calibrationState = _calibrationState;
|
|
|
|
calibrationMode = _calibrationMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
public VmcExtOk(int _loaded, int _calibrationState, int _calibrationMode, int _trackingStatus) : base(new godotOscSharp.Address("/VMC/Ext/OK"))
|
|
|
|
{
|
2023-08-17 02:17:27 +02:00
|
|
|
if (_loaded < 0 || _loaded > 1)
|
|
|
|
{
|
|
|
|
GD.Print($"Invalid value for loaded status. Expected 0 or 1, received {_loaded}.");
|
2023-08-17 15:27:59 +02:00
|
|
|
return;
|
2023-08-17 02:17:27 +02:00
|
|
|
}
|
|
|
|
if (_calibrationState < 0 || _calibrationState > 3)
|
|
|
|
{
|
|
|
|
GD.Print($"Invalid value for calibration state. Expected 0-3, received {_calibrationState}");
|
2023-08-17 15:27:59 +02:00
|
|
|
return;
|
2023-08-17 02:17:27 +02:00
|
|
|
}
|
|
|
|
if (_calibrationMode < 0 || _calibrationMode > 2)
|
|
|
|
{
|
|
|
|
GD.Print($"Invalid value for calibration mode. Expected 0-2, received {_calibrationMode}");
|
2023-08-17 15:27:59 +02:00
|
|
|
return;
|
2023-08-17 02:17:27 +02:00
|
|
|
}
|
|
|
|
if (_trackingStatus < 0 || _trackingStatus > 1)
|
|
|
|
{
|
|
|
|
GD.Print($"Invalid value for tracking status. Expected 0-1, received {_trackingStatus}");
|
2023-08-17 15:27:59 +02:00
|
|
|
return;
|
2023-08-17 02:17:27 +02:00
|
|
|
}
|
2023-08-16 19:47:14 +02:00
|
|
|
loaded = _loaded;
|
|
|
|
calibrationState = _calibrationState;
|
|
|
|
calibrationMode = _calibrationMode;
|
|
|
|
trackingStatus = _trackingStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
public VmcExtOk(godotOscSharp.OscMessage m) : base(m.Address)
|
|
|
|
{
|
|
|
|
switch (m.Data.Count)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
OkParam0(m.Data[0]);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
OkParam1And2(m.Data[0], m.Data[1], m.Data[2]);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
OkParam3(m.Data[0], m.Data[1], m.Data[2], m.Data[3]);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
GD.Print($"Invalid number of arguments for /VMC/Ext/OK message. Expected 1, 3, or 4 but received {m.Data.Count}");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OkParam0(godotOscSharp.OscArgument arg)
|
|
|
|
{
|
|
|
|
if (arg.Type != 'i')
|
|
|
|
{
|
|
|
|
GD.Print($"Invalid argument type for /VMC/Ext/OK message. Expected int in argument 0, received {arg.Type}");
|
|
|
|
return;
|
|
|
|
}
|
2023-08-17 15:27:59 +02:00
|
|
|
if ((int)arg.Value < 0 && (int)arg.Value > 1)
|
2023-08-16 19:47:14 +02:00
|
|
|
{
|
|
|
|
GD.Print($"Invalid value for loaded status. Expected 0-1, received {(int)arg.Value}");
|
2023-08-17 15:27:59 +02:00
|
|
|
return;
|
2023-08-16 19:47:14 +02:00
|
|
|
}
|
2023-08-17 15:27:59 +02:00
|
|
|
loaded = (int)arg.Value;
|
2023-08-16 19:47:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void OkParam1And2(godotOscSharp.OscArgument arg0, godotOscSharp.OscArgument arg1, godotOscSharp.OscArgument arg2)
|
|
|
|
{
|
|
|
|
OkParam0(arg0);
|
|
|
|
if (arg1.Type != 'i')
|
|
|
|
{
|
|
|
|
GD.Print($"Invalid argument type for /VMC/Ext/OK message. Expected int in argument 1, received {arg1.Type}");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (arg2.Type != 'i')
|
|
|
|
{
|
|
|
|
GD.Print($"Invalid argument type for /VMC/Ext/OK message. Expected int in argument 2, received {arg2.Type}");
|
|
|
|
return;
|
|
|
|
}
|
2023-08-17 15:27:59 +02:00
|
|
|
if ((int)arg1.Value < 0 && (int)arg1.Value > 3)
|
2023-08-16 19:47:14 +02:00
|
|
|
{
|
|
|
|
GD.Print($"Invalid value for calibration state. Expected 0-3, received {(int)arg1.Value}");
|
2023-08-17 15:27:59 +02:00
|
|
|
return;
|
2023-08-16 19:47:14 +02:00
|
|
|
}
|
2023-08-17 15:27:59 +02:00
|
|
|
if ((int)arg2.Value < 0 && (int)arg2.Value > 2)
|
2023-08-16 19:47:14 +02:00
|
|
|
{
|
|
|
|
GD.Print($"Invalid value for calibration mode. Expected 0-2, received {(int)arg2.Value}");
|
2023-08-17 15:27:59 +02:00
|
|
|
return;
|
2023-08-16 19:47:14 +02:00
|
|
|
}
|
2023-08-17 15:27:59 +02:00
|
|
|
calibrationState = (int)arg1.Value;
|
|
|
|
calibrationMode = (int)arg2.Value;
|
2023-08-16 19:47:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void OkParam3(godotOscSharp.OscArgument arg0, godotOscSharp.OscArgument arg1, godotOscSharp.OscArgument arg2, godotOscSharp.OscArgument arg)
|
|
|
|
{
|
|
|
|
OkParam1And2(arg0, arg1, arg2);
|
|
|
|
if (arg.Type != 'i')
|
|
|
|
{
|
|
|
|
GD.Print($"Invalid argument type for /VMC/Ext/OK message. Expected int in argument 3, received {arg.Type}");
|
|
|
|
return;
|
|
|
|
}
|
2023-08-17 15:27:59 +02:00
|
|
|
if ((int)arg.Value < 0 && (int)arg.Value > 1)
|
2023-08-16 19:47:14 +02:00
|
|
|
{
|
|
|
|
GD.Print($"Invalid value for tracking status. Expected 0-1, received {(int)arg.Value}");
|
2023-08-17 15:27:59 +02:00
|
|
|
return;
|
2023-08-16 19:47:14 +02:00
|
|
|
}
|
2023-08-17 15:27:59 +02:00
|
|
|
trackingStatus = (int)arg.Value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public godotOscSharp.OscMessage ToMessage()
|
|
|
|
{
|
|
|
|
if (calibrationState == null)
|
|
|
|
{
|
|
|
|
return new godotOscSharp.OscMessage(addr, new List<godotOscSharp.OscArgument>{
|
|
|
|
new godotOscSharp.OscArgument(loaded, 'i')
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (trackingStatus == null)
|
|
|
|
{
|
|
|
|
return new godotOscSharp.OscMessage(addr, new List<godotOscSharp.OscArgument>{
|
|
|
|
new godotOscSharp.OscArgument(loaded, 'i'),
|
|
|
|
new godotOscSharp.OscArgument(calibrationState, 'i'),
|
|
|
|
new godotOscSharp.OscArgument(calibrationMode, 'i')
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return new godotOscSharp.OscMessage(addr, new List<godotOscSharp.OscArgument>{
|
|
|
|
new godotOscSharp.OscArgument(loaded, 'i'),
|
|
|
|
new godotOscSharp.OscArgument(calibrationState, 'i'),
|
|
|
|
new godotOscSharp.OscArgument(calibrationMode, 'i'),
|
|
|
|
new godotOscSharp.OscArgument(trackingStatus, 'i')
|
|
|
|
});
|
2023-08-16 19:47:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|