@@ -36,18 +36,16 @@ IHUAnyThreadInterface* g_hu = nullptr;
3636std::atomic<bool > exiting;
3737
3838static void nightmode_thread_func (std::condition_variable &quitcv, std::mutex &quitmutex) {
39- char gpio_value[3 ];
40- int fd = open (" /sys/class/gpio/CAN_Day_Mode/value" , O_RDONLY);
41- if (-1 == fd) {
42- loge (" Failed to open CAN_Day_Mode gpio value for reading" );
43- } else {
44- // Offset so the GPS and NM thread are not perfectly in sync testing each second
45- std::this_thread::sleep_for (std::chrono::milliseconds (500 ));
46-
47- while (!exiting) {
48- if (-1 == read (fd, gpio_value, 3 )) {
49- loge (" Failed to read CAN_Day_Mode gpio value" );
50- }
39+ // Offset so the GPS and NM thread are not perfectly in sync testing each second
40+ std::this_thread::sleep_for (std::chrono::milliseconds (500 ));
41+
42+ while (!exiting) {
43+ char gpio_value[3 ];
44+ FILE *fd = fopen (" /sys/class/gpio/CAN_Day_Mode/value" , " r" );
45+ if (fd == nullptr ) {
46+ loge (" Failed to open CAN_Day_Mode gpio value for reading" );
47+ } else {
48+ fread (gpio_value, 1 , 2 , fd);
5149 int nightmodenow = !atoi (gpio_value);
5250
5351 if (nightmodenow) {
@@ -65,16 +63,16 @@ static void nightmode_thread_func(std::condition_variable &quitcv, std::mutex &q
6563
6664 s.hu_aap_enc_send_message (0 , AA_CH_SEN, HU_SENSOR_CHANNEL_MESSAGE::SensorEvent, sensorEvent);
6765 });
68- {
69- std::unique_lock<std::mutex> lk (quitmutex);
70- if (quitcv.wait_for (lk, std::chrono::milliseconds (1000 )) == std::cv_status::no_timeout) {
71- break ;
72- }
66+ }
67+ fclose (fd);
68+ {
69+ std::unique_lock<std::mutex> lk (quitmutex);
70+ if (quitcv.wait_for (lk, std::chrono::milliseconds (1000 )) == std::cv_status::no_timeout) {
71+ break ;
7372 }
7473 }
75- close (fd);
76- logd (" Exiting" );
7774 }
75+ logd (" Exiting" );
7876}
7977
8078
0 commit comments