[問題] 要如何使一般user也能使用device?
雖然我問過相關的問題,不過遇到瓶頸只好再問詳細點
我寫了一個module想用rpi的gpio控制一個含3個LED的小電路
/dev 下也有LED_0 LED_1 LED_2
我希望一般user可以寫入這三個file(用0或1)去控制LED的開關
程式碼如下:
https://gist.github.com/gnitnaw/b116f358fa688897fe00
之前不管是用一般user還是root都不能改變/dev/LED_(0,1,2)
改掉一些bug以後,用root可以control了,一般user還是不行
(寫到現在還沒開始ioctl...唉...我的學習速度真慢)
之後可能在kernel學習過程中會有更多問題要上來請教,希望不會違反板規
然後我也會回饋自己所學(拙作請勿見怪)。
我寫了個小程式嘗試去write /dev/LDE_0 :
int main(void)
{
char path[PATH_SIZE], buf[BUF_SIZE];
int i = 0, fd = 0;
snprintf(path, sizeof(path), "/dev/LED_0");
fd = open(path, O_WRONLY);
if (fd < 0) {
perror("Error opening GPIO pin");
exit(EXIT_FAILURE);
}
printf("Set GPIO pins to output, logic level :\n");
strncpy(buf, "1", 1);
buf[1] = '\0';
if (write(fd, buf, sizeof(buf)) < 0) {
perror("write, set pin output");
exit(EXIT_FAILURE);
}
return EXIT_SUCCESS;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 90.41.242.229
※ 文章網址: https://www.ptt.cc/bbs/LinuxDev/M.1434447670.A.3A4.html
→
06/16 18:00, , 1F
06/16 18:00, 1F
→
06/16 18:37, , 2F
06/16 18:37, 2F
→
06/16 18:37, , 3F
06/16 18:37, 3F
→
06/16 22:23, , 4F
06/16 22:23, 4F
→
06/16 22:25, , 5F
06/16 22:25, 5F
抱歉,我把code改了,現在root可以work,但是一般user不行
※ 編輯: wtchen (90.41.242.229), 06/16/2015 23:00:47
→
06/17 08:56, , 6F
06/17 08:56, 6F
→
06/17 15:52, , 7F
06/17 15:52, 7F
→
06/17 15:52, , 8F
06/17 15:52, 8F
→
06/17 18:18, , 9F
06/17 18:18, 9F
→
06/17 20:39, , 10F
06/17 20:39, 10F
LinuxDev 近期熱門文章
PTT數位生活區 即時熱門文章