@@ -71,23 +71,45 @@ light_changed (gpointer user_data)
71
71
return G_SOURCE_CONTINUE ;
72
72
}
73
73
74
+ static char *
75
+ get_illuminance_channel_path (GUdevDevice * device ,
76
+ const char * suffix )
77
+ {
78
+ const char * channels [] = {
79
+ "in_illuminance" ,
80
+ "in_illuminance0"
81
+ };
82
+ char * path = NULL ;
83
+ guint i ;
84
+
85
+ for (i = 0 ; i < G_N_ELEMENTS (channels ); i ++ ) {
86
+ path = g_strdup_printf ("%s/%s_%s" ,
87
+ g_udev_device_get_sysfs_path (device ),
88
+ channels [i ],
89
+ suffix );
90
+ if (g_file_test (path , G_FILE_TEST_EXISTS ))
91
+ return path ;
92
+ g_clear_pointer (& path , g_free );
93
+ }
94
+ return NULL ;
95
+ }
96
+
74
97
static guint
75
98
get_interval (GUdevDevice * device )
76
99
{
77
- gdouble time ;
100
+ gdouble time = DEFAULT_POLL_TIME ;
78
101
char * path , * contents ;
79
102
80
- path = g_build_filename ( g_udev_device_get_sysfs_path ( device ),
81
- "in_illuminance_integration_time" ,
82
- NULL ) ;
103
+ path = get_illuminance_channel_path ( device , "integration_time" );
104
+ if (! path )
105
+ goto out ;
83
106
if (g_file_get_contents (path , & contents , NULL , NULL )) {
84
107
time = g_ascii_strtod (contents , NULL );
85
108
g_free (contents );
86
- } else {
87
- time = DEFAULT_POLL_TIME ;
88
109
}
89
110
g_free (path );
90
111
112
+ out :
91
113
return (time * 1000 );
92
114
}
93
115
@@ -124,17 +146,19 @@ iio_poll_light_open (GUdevDevice *device,
124
146
drv_data -> user_data = user_data ;
125
147
126
148
drv_data -> interval = get_interval (device );
127
- drv_data -> input_path = g_build_filename (g_udev_device_get_sysfs_path (device ),
128
- "in_illuminance_input" ,
129
- NULL );
130
- if (!g_file_test (drv_data -> input_path , G_FILE_TEST_EXISTS )) {
131
- g_free (drv_data -> input_path );
132
- drv_data -> input_path = g_build_filename (g_udev_device_get_sysfs_path (device ),
133
- "in_illuminance_raw" ,
134
- NULL );
135
- }
149
+ drv_data -> input_path = get_illuminance_channel_path (device , "input" );
150
+ if (!drv_data -> input_path )
151
+ drv_data -> input_path = get_illuminance_channel_path (device , "raw" );
152
+ if (!drv_data -> input_path )
153
+ return FALSE;
136
154
137
- drv_data -> scale = g_udev_device_get_sysfs_attr_as_double (device , "in_illuminance_scale" );
155
+ if (g_str_has_prefix (drv_data -> input_path , "in_illuminance0" )) {
156
+ drv_data -> scale = g_udev_device_get_sysfs_attr_as_double (device ,
157
+ "in_illuminance0_scale" );
158
+ } else {
159
+ drv_data -> scale = g_udev_device_get_sysfs_attr_as_double (device ,
160
+ "in_illuminance_scale" );
161
+ }
138
162
if (drv_data -> scale == 0.0 )
139
163
drv_data -> scale = 1.0 ;
140
164
0 commit comments