Implemented most functionality
This commit is contained in:
parent
0319f66d39
commit
b1087b461d
@ -49,7 +49,7 @@ static int __init temp_monitor_init(void) {
|
|||||||
printk(KERN_ALERT "temp_monitor: Failed to register a major number\n");
|
printk(KERN_ALERT "temp_monitor: Failed to register a major number\n");
|
||||||
return major_number;
|
return major_number;
|
||||||
}
|
}
|
||||||
temp_monitor_class = class_create(THIS_MODULE, DEVICE_NAME);
|
temp_monitor_class = class_create(DEVICE_NAME);
|
||||||
if (IS_ERR(temp_monitor_class)) {
|
if (IS_ERR(temp_monitor_class)) {
|
||||||
unregister_chrdev(major_number, DEVICE_NAME);
|
unregister_chrdev(major_number, DEVICE_NAME);
|
||||||
printk(KERN_ALERT "temp_monitor: Failed to register device class\n");
|
printk(KERN_ALERT "temp_monitor: Failed to register device class\n");
|
||||||
@ -62,7 +62,7 @@ static int __init temp_monitor_init(void) {
|
|||||||
printk(KERN_ALERT "temp_monitor: Failed to create the device\n");
|
printk(KERN_ALERT "temp_monitor: Failed to create the device\n");
|
||||||
return PTR_ERR(temp_monitor_device);
|
return PTR_ERR(temp_monitor_device);
|
||||||
}
|
}
|
||||||
printk(KERN_INFO "temp_monitor: Device initialized\n");
|
printk(KERN_INFO "temp_monitor: Device initialized with major number %d\n", major_number); // Added this line
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,27 +3,22 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
|
|
||||||
#define DEVICE_NAME "/dev/temp_monitor"
|
|
||||||
#define IOCTL_GET_TEMP _IOR('t', 1, int)
|
#define IOCTL_GET_TEMP _IOR('t', 1, int)
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
int fd;
|
int fd, temp;
|
||||||
int temp;
|
fd = open("/dev/temp_monitor", O_RDWR);
|
||||||
|
|
||||||
fd = open(DEVICE_NAME, O_RDONLY);
|
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
perror("Failed to open the device");
|
perror("Failed to open the device");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ioctl(fd, IOCTL_GET_TEMP, &temp) < 0) {
|
if (ioctl(fd, IOCTL_GET_TEMP, &temp) == -1) {
|
||||||
perror("Failed to get temperature");
|
perror("Failed to get temperature");
|
||||||
close(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
printf("Current temperature: %d\n", temp);
|
||||||
printf("Current CPU Temperature: %d°C\n", temp);
|
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user