apÉndice j. cÓdigo del archivo form1.cs en...

23
70 APÉNDICE J. CÓDIGO DEL ARCHIVO FORM1.CS EN LENGUAJE C# Comprende: Interfaz gráfica de wiiMoCap. Obtención de las variables de los tres acelerómetros. Algoritmos de reconocimiento de posiciones. Inclinación en grados del muslo derecho, izquierdo y la parte superior del cuerpo. Historial de posiciones de la sesión activa. Posición actual. Activación y desactivación del modo vibrador. Activación de la alarma local (archivo de sonido). Activación de la llamada. //Form1.cs //Autor: Luis Alberto Reyes Ramírez, 2009 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Threading; using System.Net; using System.IO; using SKYPE4COMLib; using ZedGraph; using WiimoteLib; namespace WindowsFormsApplication4 {

Upload: others

Post on 25-Aug-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: APÉNDICE J. CÓDIGO DEL ARCHIVO FORM1.CS EN ...catarina.udlap.mx/u_dl_a/tales/documentos/lmt/reyes_r_la/...70 APÉNDICE J. CÓDIGO DEL ARCHIVO FORM1.CS EN LENGUAJE C# Comprende: Interfaz

70

APÉNDICE J. CÓDIGO DEL ARCHIVO FORM1.CS EN LENGUAJE C#

Comprende:

Interfaz gráfica de wiiMoCap.

Obtención de las variables de los tres acelerómetros.

Algoritmos de reconocimiento de posiciones.

Inclinación en grados del muslo derecho, izquierdo y la parte superior del

cuerpo.

Historial de posiciones de la sesión activa.

Posición actual.

Activación y desactivación del modo vibrador.

Activación de la alarma local (archivo de sonido).

Activación de la llamada.

//Form1.cs

//Autor: Luis Alberto Reyes Ramírez, 2009

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.Threading;

using System.Net;

using System.IO;

using SKYPE4COMLib;

using ZedGraph;

using WiimoteLib;

namespace WindowsFormsApplication4

{

Page 2: APÉNDICE J. CÓDIGO DEL ARCHIVO FORM1.CS EN ...catarina.udlap.mx/u_dl_a/tales/documentos/lmt/reyes_r_la/...70 APÉNDICE J. CÓDIGO DEL ARCHIVO FORM1.CS EN LENGUAJE C# Comprende: Interfaz

Apéndice J 71

public partial class Form1 : Form

{

public static DataSet ds1;

public static DataRow dRow;

public static System.Data.OleDb.OleDbConnection db;

public static System.Data.OleDb.OleDbDataAdapter da1;

public static String sql1;

public static int numberpatients;

public Skype skype = new Skype();

public Call cl = new Call();

// Starting time in milliseconds

int tickStart = 0;

//Sample rate for graphics (in ms)

int sampleRate = 50;

//Double false

public double fallLag = 0;

public double walkLag = 0;

public Boolean fall = false;

public Boolean walk = false;

//Save 1200 points. At 50 ms sample rate, equals to 1min...

//For Left Thigh

RollingPointPairList listLeftX = new

RollingPointPairList(1200);

RollingPointPairList listLeftY = new

RollingPointPairList(1200);

RollingPointPairList listLeftZ = new

RollingPointPairList(1200);

//For Right Thigh

RollingPointPairList listRightX = new

RollingPointPairList(1200);

RollingPointPairList listRightY = new

RollingPointPairList(1200);

RollingPointPairList listRightZ = new

RollingPointPairList(1200);

//For Chest

Page 3: APÉNDICE J. CÓDIGO DEL ARCHIVO FORM1.CS EN ...catarina.udlap.mx/u_dl_a/tales/documentos/lmt/reyes_r_la/...70 APÉNDICE J. CÓDIGO DEL ARCHIVO FORM1.CS EN LENGUAJE C# Comprende: Interfaz

Apéndice J 72

RollingPointPairList listChestX = new

RollingPointPairList(1200);

RollingPointPairList listChestY = new

RollingPointPairList(1200);

RollingPointPairList listChestZ = new

RollingPointPairList(1200);

private Wiimote wm = new Wiimote();

private WiimoteCollection wc = new WiimoteCollection();

public double margin = 0.5;

public double time = 0;

//For storing normalized values

public double NormalXL = 0;

public double NormalYL = 0;

public double NormalZL = 0;

public double YawL = 0;

public double NormalXR = 0;

public double NormalYR = 0;

public double NormalZR = 0;

public double YawR = 0;

public double NormalXU = 0;

public double NormalYU = 0;

public double NormalZU = 0;

public double YawU = 0;

//For storing corporal positions

public String current = "";

public String previous = "";

public String pre = "";

public static String log = "";

//For storing both log name and phone from user

public static String name = "Guest";

public static String phone = "";

//For use in walking time

public double prevtime = 0;

public Form1()

{

InitializeComponent();

Page 4: APÉNDICE J. CÓDIGO DEL ARCHIVO FORM1.CS EN ...catarina.udlap.mx/u_dl_a/tales/documentos/lmt/reyes_r_la/...70 APÉNDICE J. CÓDIGO DEL ARCHIVO FORM1.CS EN LENGUAJE C# Comprende: Interfaz

Apéndice J 73

wc.FindAllWiimotes();

Thread th = new Thread(new ThreadStart(DoSplash));

th.Start();

Thread.Sleep(3000);

th.Abort();

Thread.Sleep(1000);

}

public void DoSplash()

{

WiiSplash sp = new WiiSplash();

sp.ShowDialog();

}

void Form1_Load(object sender, System.EventArgs e)

{

//For connecting to the MS Access database

db = new System.Data.OleDb.OleDbConnection();

db.ConnectionString =

"Provider=Microsoft.ACE.OLEDB.12.0;Data

Source=|DataDirectory|\\elderly01.accdb";

db.Open();

//DataAdapter for comunication with database and DataSet to

store data

sql1 = "SELECT * From elderly";

da1 = new System.Data.OleDb.OleDbDataAdapter(sql1, db);

ds1 = new DataSet();

//Table1

da1.Fill(ds1, "elderly");

da1.Update(ds1, "elderly");

//For tracking number of patients in the database

numberpatients = ds1.Tables["elderly"].Rows.Count;

//For connecting two wiimotes

foreach (Wiimote wm in wc)

{

CheckForIllegalCrossThreadCalls = false;

wm.SetReportType(InputReport.ExtensionAccel, true);

wm.Connect();

Page 5: APÉNDICE J. CÓDIGO DEL ARCHIVO FORM1.CS EN ...catarina.udlap.mx/u_dl_a/tales/documentos/lmt/reyes_r_la/...70 APÉNDICE J. CÓDIGO DEL ARCHIVO FORM1.CS EN LENGUAJE C# Comprende: Interfaz

Apéndice J 74

wm.WiimoteChanged += wm_WiimoteChanged;

wm.WiimoteExtensionChanged +=

wm_WiimoteExtensionChanged;

wm.SetRumble(false);

}

//For setting both leds and reports

wc[0].SetLEDs(true, false, false, false);

wc[1].SetLEDs(false, true, false, false);

wc[0].SetReportType(InputReport.ExtensionAccel, true);

wc[1].SetReportType(InputReport.ButtonsAccel, true);

//Create zadGraphControl1 (Left Thigh) with main title and

axis titles

GraphPane LeftChart = zedGraphControl1.GraphPane;

LeftChart.Title.Text = "Normalized Movement of Left Thigh";

LeftChart.XAxis.Title.Text = "Time, Seconds";

LeftChart.YAxis.Title.Text = "Normalized Values";

//Create zadGraphControl2 (Right Thigh) with main title and

axis titles

GraphPane RightChart = zedGraphControl2.GraphPane;

RightChart.Title.Text = "Normalized Movement of Right

Thigh";

RightChart.XAxis.Title.Text = "Time, Seconds";

RightChart.YAxis.Title.Text = "Normalized Values";

//Create zadGraphControl3 (Chest) with main title and axis

titles

GraphPane ChestChart = zedGraphControl3.GraphPane;

ChestChart.Title.Text = "Normalized Movement of Chest";

ChestChart.XAxis.Title.Text = "Time, Seconds";

ChestChart.YAxis.Title.Text = "Normalized Values";

//Initially, curves are added with no data points...

//For Left Thigh

LineItem curveLeftX = LeftChart.AddCurve("X", listLeftX,

Color.Blue, SymbolType.None);

LineItem curveLeftY = LeftChart.AddCurve("Y", listLeftY,

Color.Red, SymbolType.None);

LineItem curveLeftZ = LeftChart.AddCurve("Z", listLeftZ,

Color.Green, SymbolType.None);

Page 6: APÉNDICE J. CÓDIGO DEL ARCHIVO FORM1.CS EN ...catarina.udlap.mx/u_dl_a/tales/documentos/lmt/reyes_r_la/...70 APÉNDICE J. CÓDIGO DEL ARCHIVO FORM1.CS EN LENGUAJE C# Comprende: Interfaz

Apéndice J 75

//For Right Thigh

LineItem curveRightX = RightChart.AddCurve("X", listRightX,

Color.Blue, SymbolType.None);

LineItem curveRightY = RightChart.AddCurve("Y", listRightY,

Color.Red, SymbolType.None);

LineItem curveRightZ = RightChart.AddCurve("Z", listRightZ,

Color.Green, SymbolType.None);

//For Left Thigh

LineItem curveChestX = ChestChart.AddCurve("X", listChestX,

Color.Blue, SymbolType.None);

LineItem curveChestY = ChestChart.AddCurve("Y", listChestY,

Color.Red, SymbolType.None);

LineItem curveChestZ = ChestChart.AddCurve("Z", listChestZ,

Color.Green, SymbolType.None);

// Sample at 50ms intervals

timer1.Interval = sampleRate;

timer1.Enabled = true;

timer1.Start();

// Just manually control the X axis range on both charts so

it scrolls continuously

// instead of discrete step-sized jumps

LeftChart.XAxis.Scale.Min = 0;

LeftChart.XAxis.Scale.Max = 30;

LeftChart.XAxis.Scale.MinorStep = 1;

LeftChart.XAxis.Scale.MajorStep = 5;

RightChart.XAxis.Scale.Min = 0;

RightChart.XAxis.Scale.Max = 30;

RightChart.XAxis.Scale.MinorStep = 1;

RightChart.XAxis.Scale.MajorStep = 5;

ChestChart.XAxis.Scale.Min = 0;

ChestChart.XAxis.Scale.Max = 30;

ChestChart.XAxis.Scale.MinorStep = 1;

ChestChart.XAxis.Scale.MajorStep = 5;

// Scale the axes for all charts

zedGraphControl1.AxisChange();

zedGraphControl2.AxisChange();

zedGraphControl3.AxisChange();

Page 7: APÉNDICE J. CÓDIGO DEL ARCHIVO FORM1.CS EN ...catarina.udlap.mx/u_dl_a/tales/documentos/lmt/reyes_r_la/...70 APÉNDICE J. CÓDIGO DEL ARCHIVO FORM1.CS EN LENGUAJE C# Comprende: Interfaz

Apéndice J 76

// Save the beginning time for reference

tickStart = Environment.TickCount;

}

void wm_WiimoteExtensionChanged(object sender,

WiimoteExtensionChangedEventArgs args)

{

//To change report type when an extension is either plugged

or unplugged from wiimote1

if (args.Inserted)

wc[0].SetReportType(InputReport.ExtensionAccel, true);

// return extension data

else

wc[0].SetReportType(InputReport.ExtensionAccel, true);

// back to original mode

}

void wm_WiimoteChanged(object sender, WiimoteChangedEventArgs

args) //Function fires on wiimotes change state change

{

//Assign guest name when app is first opened.

label6.Text = name;

//Assign wm... to a set of variables.

NormalXL = wc[0].WiimoteState.AccelState.Values.X;

NormalYL = wc[0].WiimoteState.AccelState.Values.Y;

NormalZL = wc[0].WiimoteState.AccelState.Values.Z;

NormalXU =

wc[0].WiimoteState.NunchukState.AccelState.Values.X;

NormalYU =

wc[0].WiimoteState.NunchukState.AccelState.Values.Y;

NormalZU =

wc[0].WiimoteState.NunchukState.AccelState.Values.Z;

NormalXR = wc[1].WiimoteState.AccelState.Values.X;

NormalYR = wc[1].WiimoteState.AccelState.Values.Y;

NormalZR = wc[1].WiimoteState.AccelState.Values.Z;

//Get angle from left thigh

if (NormalXL >= 0 && NormalXL <= 1)

YawL = -Math.Round(Math.Acos(NormalYL) * 180 / Math.PI,

3);

Page 8: APÉNDICE J. CÓDIGO DEL ARCHIVO FORM1.CS EN ...catarina.udlap.mx/u_dl_a/tales/documentos/lmt/reyes_r_la/...70 APÉNDICE J. CÓDIGO DEL ARCHIVO FORM1.CS EN LENGUAJE C# Comprende: Interfaz

Apéndice J 77

else if (NormalXL < 0 && NormalXL >= -1)

YawL = 360 - Math.Round(360 - Math.Acos(NormalYL) * 180

/ Math.PI, 3);

//Get angle from right thigh

if (NormalXR >= 0 && NormalXR <= 1)

YawR = Math.Round(Math.Acos(NormalYR) * 180 / Math.PI,

3);

else if (NormalXR < 0 && NormalXR >= -1)

YawR = -360 + Math.Round(360 - Math.Acos(NormalYR) *

180 / Math.PI, 3);

//Get angle from chest

if (NormalXU >= 0 && NormalXU <= 1)

YawU = Math.Round(Math.Acos(NormalYU) * 180 / Math.PI,

3);

else if (NormalXU < 0 && NormalXU >= -1)

YawU = 360 - Math.Round(360 - Math.Acos(NormalYU) * 180

/ Math.PI, 3);

//For setting angles to labels, exception may arise if

frequency is too high

try

{

label1.Text = YawL.ToString();

label3.Text = YawR.ToString();

label4.Text = YawU.ToString();

}

catch (Exception excep) { }

//---BRAND NEW MODELS

//If a fall has ocurred

if (NormalXL > 2 || NormalXL < -2 || NormalYL > 2 ||

NormalYL < -2 || NormalZL > 2 || NormalZL < -2 ||

NormalXR > 2 || NormalXR < -2 || NormalYR > 2 ||

NormalYR < -2 || NormalZR > 2 || NormalZR < -2 ||

NormalXU > 2 || NormalXU < -2 || NormalYU > 2 ||

NormalYU < -2 || NormalZU > 2 || NormalZU < -2)

{

if (time > 1 && fallLag == 0)

{

Page 9: APÉNDICE J. CÓDIGO DEL ARCHIVO FORM1.CS EN ...catarina.udlap.mx/u_dl_a/tales/documentos/lmt/reyes_r_la/...70 APÉNDICE J. CÓDIGO DEL ARCHIVO FORM1.CS EN LENGUAJE C# Comprende: Interfaz

Apéndice J 78

fall = true;

fallLag = DateTime.Now.TimeOfDay.TotalSeconds;

pre = "Fallen ";

wc[1].SetRumble(true);

}

}

//In person hasn't recovered or call it off

if (fall == true)

{

label5.Text =

((int)(DateTime.Now.TimeOfDay.TotalSeconds -

fallLag)).ToString();

if (DateTime.Now.TimeOfDay.TotalSeconds - fallLag > 10)

{

fall = false;

fallLag = 0;

rumbleOff();

makeCall();

}

}

//If both left and right leg are horizontal (either he's

seated or laying down)

else if (NormalXL > -1.5 && NormalXL < -0.5 && NormalYL > -

0.2 && NormalYL < 0.3 && NormalZL > -0.5 && NormalZL < 0.5

&& NormalXR > 0.5 && NormalXR < 1.5 && NormalYR > -0.2 &&

NormalYR < 0.3 && NormalZR > -0.5 && NormalZR < 0.5)

{

//If person is laying down facing up

if (NormalXU > -0.2 && NormalXU < 0.3 && NormalYU > 0.5

&& NormalYU < 1.5 && NormalZU > 0.5 && NormalZU <

1.5)

pre = "Laying down facing up ";

//If person is seated

else

{

pre = "Seated ";

Page 10: APÉNDICE J. CÓDIGO DEL ARCHIVO FORM1.CS EN ...catarina.udlap.mx/u_dl_a/tales/documentos/lmt/reyes_r_la/...70 APÉNDICE J. CÓDIGO DEL ARCHIVO FORM1.CS EN LENGUAJE C# Comprende: Interfaz

Apéndice J 79

inclination();

cancelCall();

}

}

//If left leg is horizontal and right leg is crossed

else if (NormalXL > -1.5 && NormalXL < -0.5 && NormalYL > -

0.2 && NormalYL < 0.3 && NormalZL > -0.5 && NormalZL < 0.5

&& NormalXR > 0 && NormalXR < 1.4 && NormalYR > -0.7 &&

NormalYR < -0.2 && NormalZR > -1 && NormalZR < 0)

{

pre = "Seated with right leg crossed ";

inclination();

cancelCall();

}

//If left leg is crossed and right leg is horizontal

else if (NormalXL > -1.4 && NormalXL < 0 && NormalYL > -

0.7 && NormalYL < -0.2 && NormalZL > -1 && NormalZL < 0 &&

NormalXR > 0.5 && NormalXR < 1.5 && NormalYR > -0.2 &&

NormalYR < 0.3 && NormalZR > -0.5 && NormalZR < 0.5)

{

pre = "Seated with left leg crossed ";

inclination();

cancelCall();

}

//If both legs are crossed

else if (NormalXL > -1.4 && NormalXL < 0 && NormalYL > -0.7

&& NormalYL < -0.2 && NormalZL > -1 && NormalZL < 0 &&

NormalXR > 0 && NormalXR < 1.4 && NormalYR > -0.7 &&

NormalYR < -0.2 && NormalZR > -1 && NormalZR < 0)

{

pre = "Seated with both legs crossed ";

inclination();

cancelCall();

}

//If left leg is horizontal and right knee is bent up

else if (NormalXL > -1.5 && NormalXL < -0.5 && NormalYL > -

0.2 && NormalYL < 0.3 && NormalZL > -0.5 && NormalZL < 0.5

Page 11: APÉNDICE J. CÓDIGO DEL ARCHIVO FORM1.CS EN ...catarina.udlap.mx/u_dl_a/tales/documentos/lmt/reyes_r_la/...70 APÉNDICE J. CÓDIGO DEL ARCHIVO FORM1.CS EN LENGUAJE C# Comprende: Interfaz

Apéndice J 80

&& NormalXR > 0 && NormalXR < 1 && NormalYR > -1.5 &&

NormalYR < -0.7 && NormalZR > -0.5 && NormalZR < 0.5)

{

pre = "Seated bending right knee up ";

inclination();

cancelCall();

}

//If left knee is bent up and right leg is horizontal

else if (NormalXL > -1.5 && NormalXL < -0.5 && NormalYL > -

0.2 && NormalYL < 0.3 && NormalZL > -0.5 && NormalZL < 0.5

&& NormalXR > -1 && NormalXR < 0 && NormalYR > -1.5 &&

NormalYR < -0.7 && NormalZR > -0.5 && NormalZR < 0.5)

{

pre = "Seated bending left knee up ";

inclination();

cancelCall();

}

//If both legs are vertical

else if (NormalXL > -0.5 && NormalXL < 0.5 && NormalYL >

0.5 && NormalYL < 1.5 && NormalZL > -0.5 && NormalZL < 0.5

&& NormalXR > -0.5 && NormalXR < 0.5 && NormalYR > 0.5 &&

NormalYR < 1.5 && NormalZR > -0.5 && NormalZR < 0.5)

{

walkLag = DateTime.Now.TimeOfDay.TotalSeconds -

walkLag;

if ((NormalXL < -0.3 && (NormalXR > 0 && NormalXR <

0.3)) || ((NormalXL > -0.3 && NormalXL < 0) &&

NormalXR > 0.3) && (walkLag == 0 && walk == false))

{

walkLag = DateTime.Now.TimeOfDay.TotalSeconds;

walk = true;

pre = "Walking ";

inclination();

cancelCall();

}

else if ((walk == true) && (walkLag > 0 && walkLag < 2)

&& ((NormalXL < -0.3 && (NormalXR > 0 && NormalXR <

Page 12: APÉNDICE J. CÓDIGO DEL ARCHIVO FORM1.CS EN ...catarina.udlap.mx/u_dl_a/tales/documentos/lmt/reyes_r_la/...70 APÉNDICE J. CÓDIGO DEL ARCHIVO FORM1.CS EN LENGUAJE C# Comprende: Interfaz

Apéndice J 81

0.3)) || ((NormalXL > -0.3 && NormalXL < 0) &&

NormalXR > 0.3)))

{

walk = true;

pre = "Walking ";

inclination();

cancelCall();

}

else if ((walkLag > 2 && walkLag < 3) && walk == true)

{

walk = false;

walkLag = 0;

pre = "Walking ";

inclination();

cancelCall();

}

//If person is standing

else if ((walkLag == 0 || walkLag > 2) && walk ==

false)

{

walk = false;

walkLag = 0;

pre = "Standing up ";

inclination();

cancelCall();

}

}

//If standing on right foot

else if (NormalXL > -1.5 && NormalXL < -0.5 && NormalYL > -

0.2 && NormalYL < 0.3 && NormalZL > -0.5 && NormalZL < 0.5

&& NormalXR > -0.5 && NormalXR < 0.5 && NormalYR > 0.5 &&

NormalYR < 1.5 && NormalZR > -0.5 && NormalZR < 0.5)

{

pre = "Standing on right foot ";

inclination();

cancelCall();

}

Page 13: APÉNDICE J. CÓDIGO DEL ARCHIVO FORM1.CS EN ...catarina.udlap.mx/u_dl_a/tales/documentos/lmt/reyes_r_la/...70 APÉNDICE J. CÓDIGO DEL ARCHIVO FORM1.CS EN LENGUAJE C# Comprende: Interfaz

Apéndice J 82

//If standing on left foot

else if (NormalXL > -0.5 && NormalXL < 0.5 && NormalYL >

0.5 && NormalYL < 1.5 && NormalZL > -0.5 && NormalZL < 0.5

&& NormalXR > 0.5 && NormalXR < 1.5 && NormalYR > -0.2 &&

NormalYR < 0.3 && NormalZR > -0.5 && NormalZR < 0.5)

{

pre = "Standing on right foot ";

inclination();

cancelCall();

}

//If both legs are inclined while seated

else if (NormalXL > -1.5 && NormalXL < -0.5 && NormalYL >

0.3 && NormalYL < 1 && NormalZL > -0.5 && NormalZL < 0.5

&& NormalXR > 0.5 && NormalXR < 1.5 && NormalYR > 0.3 &&

NormalYR < 1 && NormalZR > -0.5 && NormalZR < 0.5)

{

pre = "Seated strechting both legs ";

inclination();

cancelCall();

}

//If left leg is strechted while seated

else if (NormalXL > -1.5 && NormalXL < -0.5 && NormalYL >

0.3 && NormalYL < 1 && NormalZL > -0.5 && NormalZL < 0.5

&& NormalXR > 0.5 && NormalXR < 1.5 && NormalYR > -0.2 &&

NormalYR < 0.3 && NormalZR > -0.5 && NormalZR < 0.5)

{

pre = "Seated strechting left leg ";

inclination();

cancelCall();

}

//If right leg is strechted while seated

else if (NormalXL > -1.5 && NormalXL < -0.5 && NormalYL > -

0.2 && NormalYL < 0.3 && NormalZL > -0.5 && NormalZL < 0.5

&& NormalXR > 0.5 && NormalXR < 1.5 && NormalYR > 0.3 &&

NormalYR < 1 && NormalZR > -0.5 && NormalZR < 0.5)

{

pre = "Seated strechting right legs ";

Page 14: APÉNDICE J. CÓDIGO DEL ARCHIVO FORM1.CS EN ...catarina.udlap.mx/u_dl_a/tales/documentos/lmt/reyes_r_la/...70 APÉNDICE J. CÓDIGO DEL ARCHIVO FORM1.CS EN LENGUAJE C# Comprende: Interfaz

Apéndice J 83

inclination();

cancelCall();

}

//If both legs are bent while laying

else if (NormalXL > -1.5 && NormalXL < -0.5 && NormalYL > -

0.2 && NormalYL < 0.3 && NormalZL > -0.5 && NormalZL < 0.5

&& NormalXR > 0 && NormalXR < 1 && NormalYR > -1.5 &&

NormalYR < -0.7 && NormalZR > -0.5 && NormalZR < 0.5)

{

if (NormalXU > -0.5 && NormalXU < 0.5 && NormalYU > 0.5

&& NormalYU < 1.5 && NormalZU > -0.5 && NormalZU <

0.5)

pre = "Laying down facing up bending both legs ";

}

//If only left leg is bent

else if (NormalXL > -1.5 && NormalXL < -0.5 && NormalYL > -

0.2 && NormalYL < 0.3 && NormalZL > -0.5 && NormalZL < 0.5

&& NormalXR > 0.5 && NormalXR < 1.5 && NormalYR > -0.2 &&

NormalYR < 0.3 && NormalZR > -0.5 && NormalZR < 0.5)

{

if (NormalXU > -0.5 && NormalXU < 0.5 && NormalYU > 0.5

&& NormalYU < 1.5 && NormalZU > -0.5 && NormalZU <

0.5)

pre = "Laying down facing up bending left leg ";

}

//If only right leg is bent

else if (NormalXL > -1.5 && NormalXL < -0.5 && NormalYL > -

0.2 && NormalYL < 0.3 && NormalZL > -0.5 && NormalZL < 0.5

&& NormalXR > 0 && NormalXR < 1 && NormalYR > -1.5 &&

NormalYR < -0.7 && NormalZR > -0.5 && NormalZR < 0.5)

{

if (NormalXU > -0.5 && NormalXU < 0.5 && NormalYU > 0.5

&& NormalYU < 1.5 && NormalZU > -0.5 && NormalZU <

0.5)

pre = "Laying down facing up bending right leg ";

}

//If person is laying down facing down

Page 15: APÉNDICE J. CÓDIGO DEL ARCHIVO FORM1.CS EN ...catarina.udlap.mx/u_dl_a/tales/documentos/lmt/reyes_r_la/...70 APÉNDICE J. CÓDIGO DEL ARCHIVO FORM1.CS EN LENGUAJE C# Comprende: Interfaz

Apéndice J 84

else if (NormalXL > 0.5 && NormalXL < 1.5 && NormalYL > -

0.5 && NormalYL < 0.5 && NormalZL > -0.5 && NormalZL < 0.5

&& NormalXR > -1.5 && NormalXR < -0.5 && NormalYR > -0.5

&& NormalYR < 0.5 && NormalZR > -0.5 && NormalZR < 0.5 &&

NormalXU > -0.5 && NormalXU < 0.5 && NormalYU > -1.5 &&

NormalYU < -0.5 && NormalZU > -0.5 && NormalZU < 0.5)

{

pre = "Laying down facing down";

label2.Text = pre;

}

//If laying down facing left

else if (NormalXL > -0.5 && NormalXL < 0.5 && NormalYL > -

0.5 && NormalYL < 0.5 && NormalZL > -1.5 && NormalZL < -

0.5 && NormalXR > -0.5 && NormalXR < 0.5 && NormalYR > -

0.5 && NormalYR < 0.5 && NormalZR > 0.5 && NormalZR < 1.5

&& NormalXU > 0.5 && NormalXU < 1.5 && NormalYU > -0.5 &&

NormalYU < 0.5 && NormalZU > -0.5 && NormalZU < 0.5)

{

pre = "Laying down facing left";

label2.Text = pre;

}

//If laying down facing right

else if (NormalXL > -0.5 && NormalXL < 0.5 && NormalYL > -

0.5 && NormalYL < 0.5 && NormalZL > 0.5 && NormalZL < 1.5

&& NormalXR > -0.5 && NormalXR < 0.5 && NormalYR > -0.5 &&

NormalYR < 0.5 && NormalZR > -1.5 && NormalZR < -0.5 &&

NormalXU > -1.5 && NormalXU < -0.5 && NormalYU > -0.5 &&

NormalYU < 0.5 && NormalZU > -0.5 && NormalZU < 0.5)

{

pre = "Laying down facing right";

label2.Text = pre;

}

else

pre = "Unknown position";

label2.Text = pre;

current = label2.Text;

if (current == previous)

Page 16: APÉNDICE J. CÓDIGO DEL ARCHIVO FORM1.CS EN ...catarina.udlap.mx/u_dl_a/tales/documentos/lmt/reyes_r_la/...70 APÉNDICE J. CÓDIGO DEL ARCHIVO FORM1.CS EN LENGUAJE C# Comprende: Interfaz

Apéndice J 85

prevtime = DateTime.Now.TimeOfDay.TotalSeconds;

else

{

if (DateTime.Now.TimeOfDay.TotalSeconds > prevtime + 5

&& current != previous)

{

log = DateTime.Now + " .. " + current + "\r\n" +

log;

textBox1.Text = log;

prevtime = DateTime.Now.TimeOfDay.TotalSeconds;

previous = current;

}

}

if ((wc[1].WiimoteState.ButtonState.A))

cancelCall();

if ((wc[1].WiimoteState.ButtonState.Home))

Close();

}

private void rumbleOn()

{

wc[1].SetRumble(true);

}

private void rumbleOff()

{

wc[1].SetRumble(false);

}

private void button1_Click(object sender, EventArgs e)

{

Close();

}

private void inclination()

{

//If inclination is normal center

if(NormalXU > -0.2 && NormalXU < 0.3 && NormalYU > -0.3 &&

NormalYU < 0.5 && NormalZU > 0.5 && NormalZU < 1.5)

pre = pre + "";

Page 17: APÉNDICE J. CÓDIGO DEL ARCHIVO FORM1.CS EN ...catarina.udlap.mx/u_dl_a/tales/documentos/lmt/reyes_r_la/...70 APÉNDICE J. CÓDIGO DEL ARCHIVO FORM1.CS EN LENGUAJE C# Comprende: Interfaz

Apéndice J 86

//If inclination is normal left

else if(NormalXU > 0.3 && NormalXU < 1.5 && NormalYU > -0.2

&& NormalYU < 0.5 && NormalZU > 0.3 && NormalZU < 1)

pre = pre + "to the left";

//If inclination is normal right

else if(NormalXU > -1.5 && NormalXU < -0.2 && NormalYU > -

0.3 && NormalYU < 0.5 && NormalZU > 0.3 && NormalZU < 1)

pre = pre + "to the right";

//If inclination is forward center

else if(NormalXU > -0.2 && NormalXU < 0.3 && NormalYU > -

0.9 && NormalYU < -0.3 && NormalZU > 0.5 && NormalZU <

1.5)

pre = pre + "leaning forward";

//If inclination is forward left

else if(NormalXU > 0.3 && NormalXU < 1.5 && NormalYU > -0.9

&& NormalYU < -0.3 && NormalZU > 0.3 && NormalZU < 1)

pre = pre + "leaning forward to the left";

//If inclination is forward right

else if(NormalXU > -1.5 && NormalXU < -0.2 && NormalYU > -

0.9 && NormalYU < -0.3 && NormalZU > 0.3 && NormalZU < 1)

pre = pre + "leaning forward to the right";

//If inclination is horizontal center

else if(NormalXU > -0.2 && NormalXU < 0.3 && NormalYU > -

1.3 && NormalYU < -0.9 && NormalZU > -0.5 && NormalZU <

0.3)

pre = pre + "leaning horizontal";

//If inclination is horizontal left

else if(NormalXU > 0.3 && NormalXU < 1.5 && NormalYU > -1.3

&& NormalYU < -0.9 && NormalZU > -0.5 && NormalZU < 0.3)

pre = pre + "leaning horizontal to the left";

//If inclination is horizontal right

else if(NormalXU > -1.5 && NormalXU < -0.2 && NormalYU > -

1.3 && NormalYU < -0.9 && NormalZU > -0.5 && NormalZU <

0.3)

pre = pre + "leaning horizontal to the right";

//If inclination is backwards center

Page 18: APÉNDICE J. CÓDIGO DEL ARCHIVO FORM1.CS EN ...catarina.udlap.mx/u_dl_a/tales/documentos/lmt/reyes_r_la/...70 APÉNDICE J. CÓDIGO DEL ARCHIVO FORM1.CS EN LENGUAJE C# Comprende: Interfaz

Apéndice J 87

else if(NormalXU > -0.2 && NormalXU < 0.3 && NormalYU > 0.5

&& NormalYU < 1 && NormalZU > 0.5 && NormalZU < 1)

pre = pre + "leaning backwards";

//If inclination is backwards left

else if(NormalXU > 0.3 && NormalXU < 1.5 && NormalYU > 0.5

&& NormalYU < 1 && NormalZU > 0.5 && NormalZU < 1)

pre = pre + "leaning backwards to the left";

//If incliantion is backwards right

else if (NormalXU > -1.5 && NormalXU < -0.2 && NormalYU >

0.5 && NormalYU < 1 && NormalZU > 0 && NormalZU < 0.5)

pre = pre + "leaning backwards to the right";

//If inclination is unknown

else

pre = "Unknown position";

//Send position final name to label

label2.Text = pre;

}

void Form1_FormClosing(object sender,

System.Windows.Forms.FormClosingEventArgs e)

{

foreach (Wiimote wm in wc)

{

wm.SetLEDs(false, false, false, false);

wm.SetRumble(false);

}

}

void Form1_FormClosed(object sender,

System.Windows.Forms.FormClosedEventArgs e)

{

//Disconnect both wiimotes

foreach (Wiimote wm in wc)

{

wm.SetLEDs(false, false, false, false);

wm.SetRumble(false);

wm.Disconnect();

}

//Close database

Page 19: APÉNDICE J. CÓDIGO DEL ARCHIVO FORM1.CS EN ...catarina.udlap.mx/u_dl_a/tales/documentos/lmt/reyes_r_la/...70 APÉNDICE J. CÓDIGO DEL ARCHIVO FORM1.CS EN LENGUAJE C# Comprende: Interfaz

Apéndice J 88

db.Close();

}

private void timer1_Tick(object sender, EventArgs e)

{

// Make sure that the curvelist has at least one curve

if (zedGraphControl1.GraphPane.CurveList.Count <= 0)

return;

if (zedGraphControl2.GraphPane.CurveList.Count <= 0)

return;

if (zedGraphControl3.GraphPane.CurveList.Count <= 0)

return;

// Get the Left curves in the graph

LineItem curveLeftX =

zedGraphControl1.GraphPane.CurveList[0] as LineItem;

LineItem curveLeftY =

zedGraphControl1.GraphPane.CurveList[1] as LineItem;

LineItem curveLeftZ =

zedGraphControl1.GraphPane.CurveList[2] as LineItem;

// Get the Right curves in the graph

LineItem curveRightX =

zedGraphControl2.GraphPane.CurveList[0] as LineItem;

LineItem curveRightY =

zedGraphControl2.GraphPane.CurveList[1] as LineItem;

LineItem curveRightZ =

zedGraphControl2.GraphPane.CurveList[2] as LineItem;

// Get the Chest curves in the graph

LineItem curveChestX =

zedGraphControl3.GraphPane.CurveList[0] as LineItem;

LineItem curveChestY =

zedGraphControl3.GraphPane.CurveList[1] as LineItem;

LineItem curveChestZ =

zedGraphControl3.GraphPane.CurveList[2] as LineItem;

// Time is measured in seconds

Page 20: APÉNDICE J. CÓDIGO DEL ARCHIVO FORM1.CS EN ...catarina.udlap.mx/u_dl_a/tales/documentos/lmt/reyes_r_la/...70 APÉNDICE J. CÓDIGO DEL ARCHIVO FORM1.CS EN LENGUAJE C# Comprende: Interfaz

Apéndice J 89

time = (Environment.TickCount - tickStart) / 1000.0;

//Add 3 left values to the lists

listLeftX.Add(time, NormalXL);

listLeftY.Add(time, NormalYL);

listLeftZ.Add(time, NormalZL);

//Add 3 left values to the lists

listRightX.Add(time, NormalXR);

listRightY.Add(time, NormalYR);

listRightZ.Add(time, NormalZR);

//Add 3 left values to the lists

listChestX.Add(time, NormalXU);

listChestY.Add(time, NormalYU);

listChestZ.Add(time, NormalZU);

// Keep the X scale at a rolling 30 second interval, with

one

// major step between the max X value and the end of the

axis

Scale scaleXLeft = zedGraphControl1.GraphPane.XAxis.Scale;

Scale scaleXRight = zedGraphControl2.GraphPane.XAxis.Scale;

Scale scaleXChest = zedGraphControl3.GraphPane.XAxis.Scale;

if (time > scaleXLeft.Max - scaleXLeft.MajorStep)

{

scaleXLeft.Max = time + scaleXLeft.MajorStep;

scaleXLeft.Min = scaleXLeft.Max - 30.0;

}

if (time > scaleXRight.Max - scaleXRight.MajorStep)

{

scaleXRight.Max = time + scaleXRight.MajorStep;

scaleXRight.Min = scaleXRight.Max - 30.0;

}

if (time > scaleXChest.Max - scaleXChest.MajorStep)

{

Page 21: APÉNDICE J. CÓDIGO DEL ARCHIVO FORM1.CS EN ...catarina.udlap.mx/u_dl_a/tales/documentos/lmt/reyes_r_la/...70 APÉNDICE J. CÓDIGO DEL ARCHIVO FORM1.CS EN LENGUAJE C# Comprende: Interfaz

Apéndice J 90

scaleXChest.Max = time + scaleXChest.MajorStep;

scaleXChest.Min = scaleXChest.Max - 30.0;

}

// Make sure the Y axis is rescaled to accommodate actual

data

zedGraphControl1.AxisChange();

zedGraphControl2.AxisChange();

zedGraphControl3.AxisChange();

// Force a redraw

zedGraphControl1.Invalidate();

zedGraphControl2.Invalidate();

zedGraphControl3.Invalidate();

}

public void cancelCall()

{

fall = false;

fallLag = 0;

label5.Text = "0";

rumbleOff();

}

private void makeCall()

{

System.Diagnostics.Process.Start("Siren.mp3");

try

{

skype.Client.Start(false, true);

skype.Attach(6, true);

skype.CallStatus += new

SKYPE4COMLib._ISkypeEvents_CallStatusEventHandler(Sky

pe_CallStatus);

skype.ActiveCalls.Add(cl);

//Call general number

if (label6.Text == "Guest")

cl = skype.PlaceCall("+5212221345574", null, null,

null);

Page 22: APÉNDICE J. CÓDIGO DEL ARCHIVO FORM1.CS EN ...catarina.udlap.mx/u_dl_a/tales/documentos/lmt/reyes_r_la/...70 APÉNDICE J. CÓDIGO DEL ARCHIVO FORM1.CS EN LENGUAJE C# Comprende: Interfaz

Apéndice J 91

//Call proper user phone number

else

cl = skype.PlaceCall(phone, null, null, null);

}

//If connection couldn't be established

catch (Exception exc)

{

skype.Convert.CallFailureReasonToText(cl.FailureReaso

n);

}

}

public void Skype_CallStatus(Call cl, TCallStatus status)

{

if ((cl.Type == TCallType.cltOutgoingPSTN) && (status ==

TCallStatus.clsInProgress))

{

//16 khz 16 bit sample PCM format

cl.set_InputDevice(TCallIoDeviceType.callIoDeviceType

File, @"C:\Users\Luis\Desktop\test.wav");

}

}

private void label7_Click(object sender, EventArgs e)

{

patientEdit pEdit = new patientEdit();

pEdit.ShowDialog();

}

private void button2_Click(object sender, EventArgs e)

{

TextWriter tw = new StreamWriter(DateTime.Today.Day + "_" +

DateTime.Today.Month + "_" + DateTime.Today.Year + "_" +

label6.Text + ".txt");

tw.WriteLine(log);

tw.Close();

Page 23: APÉNDICE J. CÓDIGO DEL ARCHIVO FORM1.CS EN ...catarina.udlap.mx/u_dl_a/tales/documentos/lmt/reyes_r_la/...70 APÉNDICE J. CÓDIGO DEL ARCHIVO FORM1.CS EN LENGUAJE C# Comprende: Interfaz

Apéndice J 92

System.Diagnostics.Process.Start(DateTime.Today.Day + "_" +

DateTime.Today.Month + "_" + DateTime.Today.Year + "_" +

label6.Text + ".txt");

}

}

}