Skip to content

Commit 064d937

Browse files
author
Nico
committed
first running version of game
1 parent 156c9c7 commit 064d937

File tree

11 files changed

+436
-124
lines changed

11 files changed

+436
-124
lines changed
Binary file not shown.

MotionTest_Console/MotionData.cs

+15
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Linq;
55
using System.Text;
66
using System.Threading.Tasks;
7+
using System.Timers;
78

89
namespace BallInAMaze
910
{
@@ -32,6 +33,8 @@ public class MotionData
3233
// Start Condition that is sent to Board at startup
3334
private readonly byte[] StartCondition = new byte[2] { 0xAF, 0xFE };
3435

36+
private Timer timer;
37+
3538
/// <summary>
3639
/// CTOR
3740
/// </summary>
@@ -96,6 +99,18 @@ public MotionData(int PortNumber)
9699
StartUpFailed?.Invoke(this, EventArgs.Empty);
97100
return;
98101
}
102+
103+
timer = new Timer();
104+
timer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
105+
timer.Interval = 5000; // 1 sec
106+
timer.Enabled = true;
107+
timer.AutoReset = false;
108+
}
109+
110+
private void OnTimedEvent(object sender, ElapsedEventArgs e)
111+
{
112+
byte[] stop = { 0x01 };
113+
mPort.Write(stop, 0, 1);
99114
}
100115

101116
// THIS method can be exchanged if we are not longer

MotionTest_Console/TheGame.cs

+14-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,20 @@ private void Data_StartUpFailed(object sender, EventArgs e)
9898

9999
private void Data_NewDataArrived(object sender, EventArgs e)
100100
{
101-
Console.WriteLine("X: {0} Y: {1} Z: {2}", data.Axis_X.ToString().PadRight(8), data.Axis_Y.ToString().PadRight(8), data.Axis_Z.ToString().PadRight(8));
101+
// Calculate movement of ball
102+
int Diff_X = Old_Value_X + data.Axis_X;
103+
int Diff_Y = Old_Value_Y + data.Axis_Y;
104+
105+
double move_x = Diff_X / 5000.0;
106+
move_x = Math.Round(move_x, 1);
107+
double move_y = Diff_Y / 5000.0;
108+
move_y = Math.Round(move_y, 1);
109+
110+
// Save new values
111+
Old_Value_X = data.Axis_X;
112+
Old_Value_Y = data.Axis_Y;
113+
114+
Console.WriteLine("X: {0} Y: {1} Z: {2}", move_x.ToString().PadRight(8), move_y.ToString().PadRight(8), data.Axis_Z.ToString().PadRight(8));
102115

103116
// Kalibrierung nach StartUp
104117
// SetBallPosition + Überprüfung + Event an ModelView wenn Kugel in Loch oder Kugel in Ziel

Xilinx_Board/Ball_InAMaze_Game/src/main.c

+35-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
// to be used to BLOCK wait for UART data
2828
#define UART_RECV_BYTE() XUartPs_RecvByte(XPAR_PS7_UART_1_BASEADDR)
2929

30+
// to be used to clear RECV buffer of UART
31+
#define UART_CLEAR_RECV_BUF() XUartPs_WriteReg(XPAR_PS7_UART_1_BASEADDR, XUARTPS_CR_OFFSET, (u32)XUARTPS_CR_RXRST);
32+
3033
// START condition to be recieved from APPLICATION
3134
#define START_CONDITION 0xAFFE
3235

@@ -53,8 +56,22 @@ int main()
5356
LIS2DS12_Init();
5457

5558
START:
59+
// Discard all DATA in RECEIVE BUFFER
60+
UART_CLEAR_RECV_BUF();
61+
5662
// STARTUP PHASE --> ***BLOCKING*** until start condition is received
57-
if(StartUp_Phase() != SUCCESS) return FAILURE;
63+
if(StartUp_Phase() != SUCCESS)
64+
{
65+
// While USER has NOT pressed RESET button --> wake up every 100 ms and check
66+
while(!GPIO_Get_PS_Button())
67+
{
68+
// Send data every 100 ms (10 times in a second)
69+
usleep(100000);
70+
}
71+
72+
// Then go back to START
73+
goto START;
74+
}
5875

5976
// Prevent PROGRAM from EXITING
6077
while(1)
@@ -64,6 +81,23 @@ int main()
6481
goto START;
6582
}
6683

84+
// Check if Application sent command ...
85+
if(XUartPs_IsReceiveData(XPAR_PS7_UART_1_BASEADDR))
86+
{
87+
// DECODE COMMAND
88+
switch(UART_RECV_BYTE())
89+
{
90+
case 0x01:
91+
// STOP COMMAND --> go to START
92+
goto START;
93+
case 0x02:
94+
break;
95+
default:
96+
// Unknown COMMAND
97+
break;
98+
}
99+
}
100+
67101
// Read and Print Motion values
68102
motion = LIS2DS12_Get_Motion();
69103

Binary file not shown.

0 commit comments

Comments
 (0)