Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions gui/latency_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

import DataPlotter # Accepts a .csv file of a LagBox measurement and returns a dataplot and statistical data

import RPi.GPIO as GPIO


class Constants:
UI_FILE = 'latency_gui_800x480.ui'
Expand All @@ -41,7 +39,7 @@ class Constants:

TEXT_INPUT_MAX_CHARS = 64 # Max number of chars of the input fields

GPIO_PIN_ID = 7 # ID of the GPIO Pin where the optocoupler is connected to the Raspberry Pi
GPIO_PIN_ID = 21 # ID of the GPIO Pin where the optocoupler is connected to the Raspberry Pi


class LatencyGUI(QtWidgets.QWizard):
Expand Down Expand Up @@ -70,15 +68,10 @@ class LatencyGUI(QtWidgets.QWizard):

def __init__(self):
super().__init__()
self.reset_gpio_pins()
self.init_ui()

# Make sure that the GPIO pin where the raspberry Pi is connected to the optocoupler is set to LOW on startup
# Otherwise this could cause unwanted button presses.
def reset_gpio_pins(self):
GPIO.setmode(GPIO.BCM)
GPIO.setup(Constants.GPIO_PIN_ID, GPIO.OUT)
GPIO.output(Constants.GPIO_PIN_ID, GPIO.LOW)

def init_ui(self):
self.ui = uic.loadUi(Constants.UI_FILE, self)
Expand Down Expand Up @@ -228,7 +221,14 @@ def display_progress(self, line_id, line):
if int(line_id) == Constants.NUM_TEST_ITERATIONS:
self.ui.label_press_button_again.setText('Measurement finished. Analysing and saving data...')

def reset_page_three(self):
self.ui.label_press_button_again.setText("Press the button of your device one more time to start the measurement")
self.ui.progressBar.setValue(0)
self.ui.label_progress.setText("0/100")
self.ui.label_last_measured_time.setText("0.0ms")

def thread_finished(self):
self.reset_page_three()
print('Thread finished')

@pyqtSlot('QString')
Expand Down Expand Up @@ -260,20 +260,21 @@ def init_ui_page_four(self):

# User interface for page five (Page that askes the user if he wants to upload the measurements)
def init_ui_page_five(self):
self.ui.setButtonText(QtWidgets.QWizard.NextButton, 'Continue to Upload Results')
self.ui.setButtonText(QtWidgets.QWizard.NextButton, 'Upload Results')
self.ui.button(QtWidgets.QWizard.NextButton).clicked.disconnect(self.init_ui_page_five)
self.ui.button(QtWidgets.QWizard.NextButton).clicked.connect(self.init_ui_page_six)

self.ui.setButtonText(QtWidgets.QWizard.CancelButton, 'Exit application without uploading results')
self.ui.setButtonText(QtWidgets.QWizard.CancelButton, 'Exit without uploading')

#TODO: Add custom button to restart the application to conduct a new measurement
#self.setOption(QtWidgets.QWizard.HaveCustomButton1, True)
#self.ui.setButtonText(QtWidgets.QWizard.CustomButton1, 'Start a new measurement without uploading results')
#self.button(QtWidgets.QWizard.CustomButton1).clicked.connect(self.restart_application)
self.setOption(QtWidgets.QWizard.HaveCustomButton1, True)
self.ui.setButtonText(QtWidgets.QWizard.CustomButton1, 'Restart without uploading')
self.button(QtWidgets.QWizard.CustomButton1).clicked.connect(self.restart_application)

def restart_application(self):
self.ui.button(QtWidgets.QWizard.NextButton).clicked.disconnect(self.init_ui_page_six)
self.setOption(QtWidgets.QWizard.HaveCustomButton1, False)
self.reset_all_data()
self.init_ui_page_one()
QtWidgets.QWizard.restart(self)

Expand Down
4 changes: 2 additions & 2 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ CFLAGS=-Wall

main: inputLatencyMeasureTool.c
-mkdir ../bin
$(CC) -Wall -c inputLatencyMeasureTool.c -lwiringPi -lrt -o ../bin/inputLatencyMeasureTool.o -std=gnu99
$(CC) -Wall -c inputLatencyMeasureTool.c -lgpiod -lrt -o ../bin/inputLatencyMeasureTool.o -std=gnu99
$(CC) -Wall -c joystickControl.c -o ../bin/joystickControl.o -std=c99
$(CC) -Wall -c fileLog.c -o ../bin/fileLog.o -std=c99
$(CC) ../bin/inputLatencyMeasureTool.o ../bin/joystickControl.o ../bin/fileLog.o -lm -lwiringPi -lrt -lpthread -o ../bin/inputLatencyMeasureTool
$(CC) ../bin/inputLatencyMeasureTool.o ../bin/joystickControl.o ../bin/fileLog.o -lm -lgpiod -lrt -lpthread -o ../bin/inputLatencyMeasureTool

clean:
-rm -rf ../bin
30 changes: 20 additions & 10 deletions src/inputLatencyMeasureTool.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@
#include <pthread.h>
#include <math.h>

// apt install libgpiod
#include <gpiod.h>

// Project includes
#include "inputLatencyMeasureTool.h"
#include "joystickControl.h"
#include <wiringPi.h>
#include "fileLog.h"

enum INPUT_DEVICES inputDevice;
Expand All @@ -57,6 +59,10 @@ const char* DEVICE_TYPES[3] = {
"Keyboard"
};

const char *chipname = "gpiochip0";
struct gpiod_chip *chip;
struct gpiod_line *lineAutoMode;

int g_iChannelCircId = -1;
int g_iButtonCode = 0; // ID of GP button which will be tested

Expand Down Expand Up @@ -98,7 +104,7 @@ void autoMode(struct AutoModeData *results, unsigned int iterations)
for (int i = 0; i < iterations; i++)
{
debug("iteration %d \n", i);
digitalWrite(PIN_AUTO_MODE, LOW);
gpiod_line_set_value(lineAutoMode, 0);


while (1)
Expand All @@ -116,7 +122,7 @@ void autoMode(struct AutoModeData *results, unsigned int iterations)
usleep(delayList[i]);

dStartTime = getCurTime_microseconds(CLOCK_REALTIME);
digitalWrite(PIN_AUTO_MODE, HIGH);
gpiod_line_set_value(lineAutoMode, 1);

while (1)
{
Expand All @@ -134,7 +140,7 @@ void autoMode(struct AutoModeData *results, unsigned int iterations)

results[i] = data;

//digitalWrite(PIN_AUTO_MODE, LOW); //clear pin
//gpiod_line_set_value(lineAutoMode, 0); //clear pin
break;
}

Expand All @@ -148,7 +154,7 @@ void autoMode(struct AutoModeData *results, unsigned int iterations)
usleep(10);
}

digitalWrite(PIN_AUTO_MODE, LOW);
gpiod_line_set_value(lineAutoMode, 0);
}

int checkButtonState(long long* timestamp)
Expand Down Expand Up @@ -254,18 +260,20 @@ void testPin(int pin)
{
for(int i = 0; i < 1000; i++)
{
digitalWrite(pin, HIGH);
gpiod_line_set_value(lineAutoMode, 1);
usleep(1000000);
digitalWrite(pin, LOW);
gpiod_line_set_value(lineAutoMode, 0);
usleep(1000000);
}
}

void setupPins()
{
debug("setting up pins...\n");
pinMode(PIN_AUTO_MODE, OUTPUT);
digitalWrite(PIN_AUTO_MODE, LOW);

lineAutoMode = gpiod_chip_get_line(chip, PIN_AUTO_MODE);
gpiod_line_request_output(lineAutoMode, "foo", 0);
gpiod_line_set_value(lineAutoMode, 1);
}

// swap array elements
Expand Down Expand Up @@ -327,9 +335,11 @@ void debug(const char* format, ...)

int main(int argc, char *argv[])
{
printf("foo");
srand(time(NULL));

wiringPiSetup();
// Open GPIO chip
chip = gpiod_chip_open_by_name(chipname);

setupPins();

Expand Down
4 changes: 3 additions & 1 deletion src/inputLatencyMeasureTool.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#define inputLatencyMeasureTool_h__

#include <pthread.h>
#include <gpiod.h>


// Defines
// MCP Params
Expand All @@ -19,7 +21,7 @@
#define CHANNEL_BUTTON_RIGHT 4
#define SPI_CHANNEL 0

#define PIN_AUTO_MODE 11 //pin used for auto-mode
#define PIN_AUTO_MODE 21 //pin used for auto-mode
#define POLARITY_THRESHOLD 500 //Threshold for checking the logic of a game-pad

#define AF_BASE 100
Expand Down
1 change: 1 addition & 0 deletions src/joystickControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/joystick.h>
Expand Down