From 37ba32b0bbb368a392d2e10b11e45fbde3126e69 Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Wed, 11 Jul 2018 11:05:55 +0800 Subject: Manual mode added. Quit gracefully. Multiple code clean-ups in the Sensor class. --- brightness_ctrl.cpp | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'brightness_ctrl.cpp') diff --git a/brightness_ctrl.cpp b/brightness_ctrl.cpp index f8e0407..21c54e7 100644 --- a/brightness_ctrl.cpp +++ b/brightness_ctrl.cpp @@ -1,3 +1,5 @@ +//Chris Xiong 2018 +//3-Clause BSD License #include "brightness_ctrl.hpp" #include "utils.hpp" #include @@ -11,7 +13,7 @@ void BrightnessControl::_brightness_slide(int p) if(p<0)p=0; int pbr=maxbr*p/100; if(pbr%d/%d\n",br,pbr,maxbr); + LOG('I',"brightness adjust: %d->%d/%d",br,pbr,maxbr); int d=1;if(pbr0&&br+round(d*dd)<=pbr||d<0&&br+round(d*dd)>=pbr) { @@ -37,8 +39,8 @@ void BrightnessControl::set_path(filesystem::path p) maxbr=readint(maxbrpath.c_str()); br=readint(brpath.c_str()); } -void BrightnessControl::set_thresh(std::vector _th){thresh=_th;} -void BrightnessControl::set_value(std::vector _v){value=_v;} +void BrightnessControl::set_thresh(const std::vector &_th){thresh=_th;} +void BrightnessControl::set_value(const std::vector &_v){value=_v;} void BrightnessControl::set_delay(int _d){delay=_d;} void BrightnessControl::set_trigrange(int _tr){tr=_tr;} void BrightnessControl::set_minabr(int _mbr){minabr=_mbr;} @@ -50,6 +52,31 @@ void BrightnessControl::set_offset(int rel,int off) if(offset<-100)offset=-100; brightness_slide(value[cur]); } +void BrightnessControl::set_frozen(bool frozen) +{ + if(frozen) + { + doffset=offset; + offset=value[cur]+offset; + if(offset>100)offset=100; + if(offset<0)offset=0; + } + else + { + offset=doffset; + force_adjust(); + } +} +int BrightnessControl::get_offset(){return offset;} +int BrightnessControl::get_brightness() +{ + //FIXME??: On some devices there are EC-controlled key combinations + //that bypasses lightsd entirely (e.g. Fn+Space on ThinkPad for + //keyboard backlight). So we may have to turn to sysfs for this... + //Screw it, just read from sysfs. + if(brpath.empty())return 0; + return round(readint(brpath.c_str())*100./maxbr); +} void BrightnessControl::force_adjust() { -- cgit v1.2.3