-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsensor.c
More file actions
75 lines (61 loc) · 1.55 KB
/
sensor.c
File metadata and controls
75 lines (61 loc) · 1.55 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "gpio.h"
#include "printf.h"
#include "i2c.h"
#include "LSM6DS33.h"
#include "sensor.h"
#include "gl.h"
#include "gpio_extra.h"
#include "uart.h"
#include "timer.h"
#include "armtimer.h"
#include "interrupts.h"
#include "ringbuffer.h"
#include <stdbool.h>
const unsigned int trigger = GPIO_PIN16;
const unsigned int echo = GPIO_PIN18;
extern int SCREENWIDTH;
extern int SCREENHEIGHT;
extern color_t PADDLE; //color of paddle
extern color_t BACKGROUND;
float prev_time = 0;
rb_t* rb; //ringbuffer for sensor values
int prev_angle = 0;
const unsigned lsm6ds33_address = 0b1101011;
extern sensor_object_t person2;
sensor_object_t sensor_init(const unsigned lsm6ds33_address){
lsm6ds33_init(lsm6ds33_address);
lsm6ds33_enable_gyroscope(lsm6ds33_address);
// rb = rb_new();
sensor_object_t player;
player.x = 0;
player.y = SCREENHEIGHT/2;
player.dx = 0;
player.dy = 0;
return player;
}
sensor_object_t updateposition(sensor_object_t player, const unsigned lsm6ds33_address){
int x;
bool success = rb_dequeue(rb, &x);
//dequeue until you are successful
while(!success) {
printf("nope");
success = rb_dequeue(rb, &x);
}
printf("dequeed\n");
printf("angle is %d deg\n", x);
sensor_object_t updatedplayer;
updatedplayer.dx = 0;
if (x>0){
updatedplayer.dy = -7;
}
else if (x < 0) {
updatedplayer.dy = +7;
}
else {
updatedplayer.dy = 0;
}
updatedplayer.x = player.x;
updatedplayer.y = player.y + updatedplayer.dy;
prev_time = timer_get_ticks();
return updatedplayer;
}