#include #include #include #include #include "led_ctl.h" void usage(const char *prog) { printf("Usage: %s [args]\n", prog); printf("Commands:\n"); printf(" color Set LED color\n"); printf(" heartoff turn off heart led\n"); printf(" blink [time] Set blink (time unit: 100ms, def: 5)\n"); printf(" status Show current heart_led status\n"); printf(" ac Show AC power status\n"); printf(" btn Show rst button status \n"); printf(" bat Show bat info \n"); printf(" batledsys [state] Control Bat led with state by system\n"); printf(" batledec Control Bat led by EC\n"); printf("\nExample:\n"); printf(" sudo %s color r (Set color to RED)\n", prog); printf(" sudo %s blink on 5 (Blink every 500ms)\n", prog); } int main(int argc, char *argv[]) { if (geteuid() != 0) { fprintf(stderr, "Error: Must run as root (sudo).\n"); return 1; } if (led_driver_init() < 0) { return 1; } if (argc < 2) { usage(argv[0]); return 1; } get_ec_version(); const char *cmd = argv[1]; if (strcmp(cmd, "color") == 0) { if (argc < 3) { fprintf(stderr, "Error: Missing color argument.\n"); return 1; } if (strcmp(argv[2], "r") == 0) { if (led_set_color(LED_RED) == 0) printf("OK: Color set to RED\n"); } else if (strcmp(argv[2], "g") == 0) { if (led_set_color(LED_GREEN) == 0) printf("OK: Color set to GREEN\n"); } else { fprintf(stderr, "Error: Unknown color '%s'\n", argv[2]); return 1; } } else if (strcmp(cmd, "blink") == 0) { if (argc < 3) { fprintf(stderr, "Error: Missing state argument.\n"); return 1; } if (strcmp(argv[2], "on") == 0) { int t = 5; // 500ms if (argc >= 4) t = atoi(argv[3]); if (t < 0 || t > 255) t = 5; if (led_set_blink(1, (uint8_t)t) == 0) printf("OK: Blink ON (Interval: %d00ms)\n", t); } else if (strcmp(argv[2], "off") == 0) { if (led_set_blink(0, 0) == 0) printf("OK: Blink OFF\n"); } else { fprintf(stderr, "Error: Unknown state '%s'\n", argv[2]); return 1; } } else if (strcmp(cmd, "status") == 0) { led_print_status(); } else if (strcmp(cmd, "heartoff") == 0) { heart_led_turn_off(); } else if (strcmp(cmd, "batledsys") == 0) { if (argc < 3) { fprintf(stderr, "Error: Missing color argument.\n"); return 1; } if (strcmp(argv[2], "0") == 0) { if (bat_led_set_color(0) == 1) printf("OK: Color set to green\n"); } else if (strcmp(argv[2], "1") == 0) { if (bat_led_set_color(1) == 1) printf("OK: Color set to red\n"); } else if (strcmp(argv[2], "2") == 0) { if (bat_led_set_color(2) == 1) printf("OK: Color set to green\n"); } else if (strcmp(argv[2], "3") == 0) { if (bat_led_set_color(3) == 1) printf("OK: Color set to red\n"); } else if (strcmp(argv[2], "4") == 0) { if (bat_led_set_color(4) == 1) printf("OK: turn off all \n"); } else { fprintf(stderr, "Error: Unknown color '%s'\n", argv[2]); return 1; } } else if (strcmp(cmd, "batledec") == 0) { bat_led_ctrl_by_ec(); } else if (strcmp(cmd, "bat") == 0) { get_bat_info(); ac_bat_state(); } else if (strcmp(cmd, "ac") == 0) { ac_present(); } else if (strcmp(cmd, "btn") == 0) { soft_rest_btn(); } else { usage(argv[0]); return 1; } return 0; }