mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-08-22 16:53:45 +08:00
openpilot release
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
CC = clang
|
||||
CXX = clang++
|
||||
|
||||
|
||||
PHONELIBS = ../../phonelibs
|
||||
|
||||
WARN_FLAGS = -Werror=implicit-function-declaration \
|
||||
-Werror=incompatible-pointer-types \
|
||||
-Werror=int-conversion \
|
||||
-Werror=return-type \
|
||||
-Werror=format-extra-args
|
||||
|
||||
CFLAGS = -std=gnu11 -g -fPIC -O2 $(WARN_FLAGS)
|
||||
CXXFLAGS = -std=c++11 -g -fPIC -O2 $(WARN_FLAGS)
|
||||
|
||||
ZMQ_FLAGS = -I$(PHONELIBS)/zmq/aarch64/include
|
||||
ZMQ_LIBS = -L$(PHONELIBS)/zmq/aarch64/lib \
|
||||
-l:libczmq.a -l:libzmq.a \
|
||||
-lgnustl_shared
|
||||
|
||||
CEREAL_CFLAGS = -I$(PHONELIBS)/capnp-c/include
|
||||
CEREAL_LIBS = -L$(PHONELIBS)/capnp-c/aarch64/lib -l:libcapn.a
|
||||
CEREAL_OBJS = ../../cereal/gen/c/log.capnp.o
|
||||
|
||||
NANOVG_FLAGS = -I$(PHONELIBS)/nanovg
|
||||
|
||||
OPENGL_LIBS = -lGLESv3
|
||||
|
||||
FRAMEBUFFER_LIBS = -lutils -lgui -lEGL
|
||||
|
||||
OBJS = ui.o \
|
||||
touch.o \
|
||||
../common/visionipc.o \
|
||||
../common/framebuffer.o \
|
||||
$(PHONELIBS)/nanovg/nanovg.o \
|
||||
$(CEREAL_OBJS)
|
||||
|
||||
DEPS := $(OBJS:.o=.d)
|
||||
|
||||
all: ui
|
||||
|
||||
ui: $(OBJS)
|
||||
@echo "[ LINK ] $@"
|
||||
$(CXX) -fPIC -o '$@' $^ \
|
||||
$(FRAMEBUFFER_LIBS) \
|
||||
$(CEREAL_LIBS) \
|
||||
$(ZMQ_LIBS) \
|
||||
-L/system/vendor/lib64 \
|
||||
$(OPENGL_LIBS) \
|
||||
-lcutils -lm -llog
|
||||
|
||||
../common/framebuffer.o: ../common/framebuffer.cc
|
||||
@echo "[ CXX ] $@"
|
||||
$(CXX) $(CXXFLAGS) -MMD \
|
||||
-I$(PHONELIBS)/android_frameworks_native/include \
|
||||
-I$(PHONELIBS)/android_system_core/include \
|
||||
-I$(PHONELIBS)/android_hardware_libhardware/include \
|
||||
-c -o '$@' '$<'
|
||||
|
||||
%.o: %.c
|
||||
@echo "[ CC ] $@"
|
||||
$(CC) $(CFLAGS) -MMD \
|
||||
-I.. -I../.. \
|
||||
$(NANOVG_FLAGS) \
|
||||
$(ZMQ_FLAGS) \
|
||||
$(CEREAL_CFLAGS) \
|
||||
-c -o '$@' '$<'
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -f ui $(OBJS) $(DEPS)
|
||||
|
||||
-include $(DEPS)
|
||||
@@ -0,0 +1,63 @@
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <assert.h>
|
||||
#include <sys/poll.h>
|
||||
#include <linux/input.h>
|
||||
|
||||
#include "touch.h"
|
||||
|
||||
void touch_init(TouchState *s) {
|
||||
// synaptics touch screen on oneplus 3
|
||||
s->fd = open("/dev/input/event4", O_RDONLY);
|
||||
assert(s->fd >= 0);
|
||||
}
|
||||
|
||||
int touch_poll(TouchState *s, int* out_x, int* out_y) {
|
||||
assert(out_x && out_y);
|
||||
bool up = false;
|
||||
while (true) {
|
||||
struct pollfd polls[] = {{
|
||||
.fd = s->fd,
|
||||
.events = POLLIN,
|
||||
}};
|
||||
int err = poll(polls, 1, 0);
|
||||
if (err < 0) {
|
||||
return -1;
|
||||
}
|
||||
if (!(polls[0].revents & POLLIN)) {
|
||||
break;
|
||||
}
|
||||
|
||||
struct input_event event;
|
||||
err = read(polls[0].fd, &event, sizeof(event));
|
||||
if (err < sizeof(event)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
switch (event.type) {
|
||||
case EV_ABS:
|
||||
if (event.code == ABS_MT_POSITION_X) {
|
||||
s->last_x = event.value;
|
||||
} else if (event.code == ABS_MT_POSITION_Y) {
|
||||
s->last_y = event.value;
|
||||
}
|
||||
break;
|
||||
case EV_KEY:
|
||||
if (event.code == BTN_TOOL_FINGER && event.value == 0) {
|
||||
// finger up
|
||||
up = true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (up) {
|
||||
// adjust for landscape
|
||||
*out_x = 1920 - s->last_y;
|
||||
*out_y = s->last_x;
|
||||
}
|
||||
return up;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
#ifndef TOUCH_H
|
||||
#define TOUCH_H
|
||||
|
||||
typedef struct TouchState {
|
||||
int fd;
|
||||
int last_x, last_y;
|
||||
} TouchState;
|
||||
|
||||
void touch_init(TouchState *s);
|
||||
int touch_poll(TouchState *s, int *out_x, int *out_y);
|
||||
|
||||
#endif
|
||||
+1325
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user