@ -20,8 +20,26 @@
# include <log/log.h>
# include <utils/SystemClock.h>
# include <fstream>
# include <cmath>
# define TSP_ENABLED_PATH " / sys / class / sec / tsp / input / enabled"
template < typename T >
static void set ( const std : : string & path , const T & value ) {
std : : ofstream file ( path ) ;
file < < value ;
}
template < typename T >
static T get ( const std : : string & path , const T & def ) {
std : : ifstream file ( path ) ;
T result ;
file > > result ;
return file . fail ( ) ? def : result ;
}
static bool readBool ( int fd , bool seek ) {
char c ;
int rc ;
@ -262,6 +280,10 @@ SysfsPollingOneShotSensor::~SysfsPollingOneShotSensor() {
void SysfsPollingOneShotSensor : : activate ( bool enable , bool notify , bool lock ) {
std : : unique_lock < std : : mutex > runLock ( mRunMutex , std : : defer_lock ) ;
if ( ! enable & & strcmp ( get < std : : string > ( TSP_ENABLED_PATH , " 0 " ) . c_str ( ) , " 0 " ) = = 0 ) {
set ( TSP_ENABLED_PATH , " 1 " ) ;
}
if ( lock ) {
runLock . lock ( ) ;
}
@ -278,6 +300,10 @@ void SysfsPollingOneShotSensor::activate(bool enable, bool notify, bool lock) {
if ( lock ) {
runLock . unlock ( ) ;
}
if ( enable & & strcmp ( get < std : : string > ( TSP_ENABLED_PATH , " 0 " ) . c_str ( ) , " 1 " ) = = 0 ) {
set ( TSP_ENABLED_PATH , " 0 " ) ;
}
}
void SysfsPollingOneShotSensor : : activate ( bool enable ) {
@ -310,6 +336,9 @@ void SysfsPollingOneShotSensor::run() {
}
if ( mPolls [ 1 ] . revents = = mPolls [ 1 ] . events & & readBool ( mPollFd , true /* seek */ ) ) {
if ( strcmp ( get < std : : string > ( TSP_ENABLED_PATH , " 0 " ) . c_str ( ) , " 0 " ) = = 0 ) {
set ( TSP_ENABLED_PATH , " 1 " ) ;
}
activate ( false , false , false ) ;
mCallback - > postEvents ( readEvents ( ) , isWakeUpSensor ( ) ) ;
} else if ( mPolls [ 0 ] . revents = = mPolls [ 0 ] . events ) {