Created the user space code to interract with the module. Q4 done
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user