[問題] linux使用notifier如何call其他function
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
Linux
問題(Question):
最近在學習Linux kernel,想要notifier傳回的狀態與USB狀態決定Led的亮暗
但因為目前看得power_supply_led的燈號更改只根據USB狀態來改變
想要做出x=1的情況LED才會亮
static int fb_notifier_callback(struct notifier_block *self,
unsigned long event, void *data)
{
struct fb_event *evdata = data;
int *blank;
if (evdata && evdata->data ) {
if (event == FB_EVENT_BLANK) {
blank = evdata->data;
{
if (*blank == FB_BLANK_POWERDOWN )
x=0;
// power_supply_update_gen_leds(struct power_supply *psy)
else if (*blank == FB_BLANK_UNBLANK )
x=1;
// power_supply_update_gen_leds(struct power_supply *psy)
else
x=0;
}
}
}
return 0;
}
這裡是notifier傳回的值 會有兩種情況 x=0 or x=1
static void power_supply_update_gen_leds(struct power_supply *psy)
{
//add
unsigned long delay_on = 0;
unsigned long delay_off = 0;
//add end
union power_supply_propval online;
if (psy->get_property(psy, POWER_SUPPLY_PROP_ONLINE, &online))
return;
dev_dbg(psy->dev, "%s %d\n", __func__, online.intval);
if (online.intval)
{
if (x==1)
led_trigger_event(psy->online_trig, LED_FULL);
else if (x==0)
led_trigger_event(psy->online_trig, LED_OFF);
}
else
led_trigger_event(psy->online_trig, LED_OFF);
}
這裡是根據usb插拔狀態決定Led的燈亮滅
目前確認過x的值的確會根據該backlight狀態而改變
我想試著在 fb_notifier_callback中的event裡加上更新LED狀態的部分
但不知怎麼引入power_supply *psy
想請問有甚麼作法嗎?
希望能給一點提示
非常感謝
錯誤結果(Wrong Output):
目前的情況會是因為led的更新只根據usb狀態改變 若usb插著但x的值改變不會亮滅
程式碼(Code):(請善用置底文網頁, 記得排版)
完整程式碼 http://codepad.org/NQr5EAKj
這個是程式中用到powr_supply_core struct power_supply *psy在這裡create
http://tinyurl.com/me25bou
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 111.81.208.22
→
01/29 05:15, , 1F
01/29 05:15, 1F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章