/* * File: dellAlsCtl.c * Author: yelo3 * * Created on 2 marzo 2009, 9.51 */ /* SMI Interface: cbClass: 17 cbSelect: 10 Name: Ambient Light Sensor Status and Control On entry: cbARG1, byte 0: Function to perform: 0 Get ALS Status 1 Control ALS 2 Get Brightness Table If cbARG1, byte 0 is 1 (Control ALS): cbARG2, byte 0: Command 0 Disable ALS 1 Enable ALS cbARG2, byte 1: ALS low limit to set cbARG2, byte 2: ALS high limit to set On return: cbRES1: Return code 0 Completed successfully -1 Completed with error -2 Function not supported If cbARG1 byte 0 was 0 (Get ALS Status): cbRES2, byte 0: Current ALS Status 0 Disabled 1 Enabled cbRES3, byte 0: Current ALS low limit cbRES3, byte 1: Current ALS high limit cbRES3, byte 2: Absolute ALS low limit cbRES3, byte 3: Absolute ALS high limit If cbARG1 byte 0 was 2 (Get Brightness Table): cbRES2: Bytes 3..0 of the brightness table cbRES3: Bytes 7..4 of the brightness table */ #include #include #include #include #include #define ALS_CB_CLASS 17 #define ALS_CB_SELECT 10 int parse_result(int r, u32 res_0) { if (r == -1) { perror("You need root access"); } else if (r != 0) { perror("Error"); } else if (res_0 == -1) { fprintf(stderr, "Completed with error\n"); exit(-1); } else if (res_0 == -2) { fprintf(stderr, "Function not supported\n"); exit(-2); } if (r != 0) exit(EXIT_FAILURE); } void print_current_status() { u32 args[1] = {0}; u32 res[4]; int r = dell_simple_ci_smi(ALS_CB_CLASS, ALS_CB_SELECT, args, res); parse_result(r, res[0]); printf("ALS enabled: %d\n", res[1] % 256); /* * commented because it's always 0 printf("Current ALS low limit: %d\n", res[2] % 256); printf("Current ALS high limit: %d\n", ( res[2] >> 1*8 ) % 256); printf("Absolute ALS low limit: %d\n", ( res[2] >> 2*8 ) % 256); printf("Absolute ALS high limit: %d\n", ( res[2] >> 3*8 ) % 256); */ } void set_current_status(bool enabled) { u32 args[2] = {1, 0}; u32 res[4]; printf("Changing status to %d\n", enabled); if (enabled == true) { args[1] = 1; } int r = dell_simple_ci_smi(ALS_CB_CLASS, ALS_CB_SELECT, args, res); parse_result(r, res[0]); } /* * */ int main(int argc, char** argv) { if (argc != 2) { printf("usage options:\n" "--status\t\tPrints current ambient light sensor status\n" "--enable\t\tEnable the ambient light sensor\n" "--disable\t\tDisable the ambient light sensor\n" ); exit(EXIT_FAILURE); } int enable; if (strcmp(argv[1], "--status") == 0) enable = -1; if (strcmp(argv[1], "--enable") == 0) enable = 1; else if (strcmp(argv[1], "--disable") == 0) enable = 0; if (enable == -1) { print_current_status(); } else if (enable == 1) { set_current_status(true); print_current_status(); } else if (enable == 0) { set_current_status(false); print_current_status(); } return (EXIT_SUCCESS); }