Created the user space code to interract with the module. Q4 done

This commit is contained in:
2024-12-25 10:08:20 +01:00
parent 6ddb10c4a5
commit 8aeece620d
2 changed files with 102 additions and 12 deletions
-6
View File
@@ -25,17 +25,11 @@ static int dev_open(struct inode *, struct file *);
static ssize_t dev_read(struct file *filep, char __user *buffer, size_t len, loff_t *offset){
int joystick_status[5] = {UP,DOWN,LEFT,RIGHT,BUTTON};
int data_len = 5*sizeof(int);
// Ensure we only send data once
if (*offset > 0)
return 0; // End of file
// Copy data to user-space buffer
if (copy_to_user(buffer, joystick_status, data_len)) {
pr_err("Failed to send data to user\n");
return -EFAULT;
}
// Update the file offset
*offset += data_len;
return 0;
}