Skip to content

Commit

Permalink
Merge pull request #5 from lucidcode/update-parser
Browse files Browse the repository at this point in the history
Update data parser
  • Loading branch information
IAmCoder authored Sep 9, 2023
2 parents 21986f6 + 60e295d commit 009c633
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 61 deletions.
109 changes: 53 additions & 56 deletions Hypnodyne ZMax/PluginHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,10 @@ private static void startListening()
NetworkStream stream = tcpClient.GetStream();
byte[] request = System.Text.Encoding.UTF8.GetBytes("HELLO\r\n");
stream.Write(request, 0, request.Length);
stream.Flush();
request = System.Text.Encoding.UTF8.GetBytes("IDLEMODE_SENDBYTES 1 3 900 0 00-26-0B-03-0E-37-98\r\n");
stream.Write(request, 0, request.Length);
stream.Flush();

while (running)
{
Expand Down Expand Up @@ -148,73 +150,68 @@ private static void processData(String data)
{
try
{
if (!data.StartsWith("D")) return;
string[] stringSeparators = new string[] { "\r\n", "\r", "\n", "\n\r", "." };
string[] stringSeparators = new string[] { "\r\n", "\r", "\n", "\n\r" };
string[] lines = data.Split(stringSeparators, StringSplitOptions.None);
for (int i = 0; i < lines.Length; i++)
{
String line = lines[i];
if (line != "")
{
String dataline = line.Substring(1);
string[] parts = dataline.Split('.');
byte[] buf = HexToBytes(parts[1].Replace("-", ""));
if (buf.Length == 0)
{
continue;
}
if (line == "" || !line.StartsWith("D")) continue;

int packet_type = buf[0];
if ((packet_type >= 1) && (packet_type <= 11))
String dataline = line.Substring(1);
string[] parts = dataline.Split('.');
byte[] buf = HexToBytes(parts[1].Replace("-", ""));
if (buf.Length == 0) continue;

int packet_type = buf[0];
if ((packet_type >= 1) && (packet_type <= 11))
{
if (buf.Length == 40)
{
if (buf.Length == 40)
int eegrv = buf[1] * 256 + buf[2];
int eeglv = buf[3] * 256 + buf[4];
int dx = buf[5] * 256 + buf[6];
int dy = buf[7] * 256 + buf[8];
int dz = buf[9] * 256 + buf[10];
double scaled_eegr = ScaleEEG(eegrv);
double scaled_eegl = ScaleEEG(eeglv);
double scaled_dx = ScaleAccel(dx);
double scaled_dy = ScaleAccel(dy);
double scaled_dz = ScaleAccel(dz);

scaled_eegr += 500;
scaled_eegl += 500;

m_dblX = (scaled_dx + 2) * 250;
m_dblY = (scaled_dy + 2) * 250;
m_dblZ = (scaled_dz + 2) * 250;

if (ClearDisplay)
{
int eegrv = buf[1] * 256 + buf[2];
int eeglv = buf[3] * 256 + buf[4];
int dx = buf[5] * 256 + buf[6];
int dy = buf[7] * 256 + buf[8];
int dz = buf[9] * 256 + buf[10];
double scaled_eegr = ScaleEEG(eegrv);
double scaled_eegl = ScaleEEG(eeglv);
double scaled_dx = ScaleAccel(dx);
double scaled_dy = ScaleAccel(dy);
double scaled_dz = ScaleAccel(dz);

scaled_eegr += 500;
scaled_eegl += 500;

m_dblX = (scaled_dx + 2) * 250;
m_dblY = (scaled_dy + 2) * 250;
m_dblZ = (scaled_dz + 2) * 250;

if (ClearDisplay)
{
ClearDisplay = false;
DisplayValue = 0;
}
ClearDisplay = false;
DisplayValue = 0;
}

if (ClearHighscore)
{
ClearHighscore = false;
DisplayValue = 0;
}
if (ClearHighscore)
{
ClearHighscore = false;
DisplayValue = 0;
}

double raw = (scaled_eegr + scaled_eegl) / 2;
if (raw >= HighscoreValue)
{
HighscoreValue = (scaled_eegr + scaled_eegl) / 2;
}
double raw = (scaled_eegr + scaled_eegl) / 2;
if (raw >= HighscoreValue)
{
HighscoreValue = (scaled_eegr + scaled_eegl) / 2;
}

DisplayValue = (scaled_eegr + scaled_eegl) / 2;
DisplayValue = (scaled_eegr + scaled_eegl) / 2;

if (ZMaxEEGRChanged != null)
{
ZMaxEEGRChanged(null, new ZMaxChangedEventArgs(Convert.ToInt32(scaled_eegr)));
}
if (ZMaxEEGLChanged != null)
{
ZMaxEEGLChanged(null, new ZMaxChangedEventArgs(Convert.ToInt32(scaled_eegl)));
}
if (ZMaxEEGRChanged != null)
{
ZMaxEEGRChanged(null, new ZMaxChangedEventArgs(Convert.ToInt32(scaled_eegr)));
}
if (ZMaxEEGLChanged != null)
{
ZMaxEEGLChanged(null, new ZMaxChangedEventArgs(Convert.ToInt32(scaled_eegl)));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Hypnodyne ZMax/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.3.0")]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: AssemblyVersion("1.0.4.0")]
[assembly: AssemblyFileVersion("1.0.4.0")]
6 changes: 3 additions & 3 deletions Installer/Lucid Scribe Hypnodyne ZMax.vdproj
Original file line number Diff line number Diff line change
Expand Up @@ -929,15 +929,15 @@
{
"Name" = "8:Microsoft Visual Studio"
"ProductName" = "8:Lucid Scribe Hypnodyne ZMax"
"ProductCode" = "8:{59C097B8-BFFD-4095-BC78-88D9FE30E586}"
"PackageCode" = "8:{7361FD79-EAD2-46A5-8284-7BF90E0A176D}"
"ProductCode" = "8:{1ECD83C5-7B9B-4C53-BA21-42C25D89A8A0}"
"PackageCode" = "8:{6E02346B-E485-44D7-A348-CA2B94B4BCC9}"
"UpgradeCode" = "8:{D968DAE8-1754-45B3-992D-C4CC6A7615B8}"
"AspNetVersion" = "8:4.0.30319.0"
"RestartWWWService" = "11:FALSE"
"RemovePreviousVersions" = "11:TRUE"
"DetectNewerInstalledVersion" = "11:TRUE"
"InstallAllUsers" = "11:TRUE"
"ProductVersion" = "8:1.0.3"
"ProductVersion" = "8:1.0.4"
"Manufacturer" = "8:lucidcode"
"ARPHELPTELEPHONE" = "8:"
"ARPHELPLINK" = "8:http://www.lucidcode.com/Contact"
Expand Down

0 comments on commit 009c633

Please sign in to comment.