@ -20,8 +20,26 @@
# include <log/log.h>
# include <log/log.h>
# include <utils/SystemClock.h>
# include <utils/SystemClock.h>
# include <fstream>
# include <cmath>
# 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 ) {
static bool readBool ( int fd , bool seek ) {
char c ;
char c ;
int rc ;
int rc ;
@ -262,6 +280,10 @@ SysfsPollingOneShotSensor::~SysfsPollingOneShotSensor() {
void SysfsPollingOneShotSensor : : activate ( bool enable , bool notify , bool lock ) {
void SysfsPollingOneShotSensor : : activate ( bool enable , bool notify , bool lock ) {
std : : unique_lock < std : : mutex > runLock ( mRunMutex , std : : defer_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 ) {
if ( lock ) {
runLock . lock ( ) ;
runLock . lock ( ) ;
}
}
@ -278,6 +300,10 @@ void SysfsPollingOneShotSensor::activate(bool enable, bool notify, bool lock) {
if ( lock ) {
if ( lock ) {
runLock . unlock ( ) ;
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 ) {
void SysfsPollingOneShotSensor : : activate ( bool enable ) {
@ -310,6 +336,9 @@ void SysfsPollingOneShotSensor::run() {
}
}
if ( mPolls [ 1 ] . revents = = mPolls [ 1 ] . events & & readBool ( mPollFd , true /* seek */ ) ) {
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 ) ;
activate ( false , false , false ) ;
mCallback - > postEvents ( readEvents ( ) , isWakeUpSensor ( ) ) ;
mCallback - > postEvents ( readEvents ( ) , isWakeUpSensor ( ) ) ;
} else if ( mPolls [ 0 ] . revents = = mPolls [ 0 ] . events ) {
} else if ( mPolls [ 0 ] . revents = = mPolls [ 0 ] . events ) {