- 我就是来点个灯,源码如下。有可以测试的就测试一下吧。
- /* Copyright -20220809- shen All Rights Reserved. */
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdint.h>
- #include <stdbool.h>
- #include <string.h>
- #include <getopt.h>
- #include <signal.h>
- #include <unistd.h>
- #include <errno.h>
- #include <libgen.h>
- /* Get array size */
- #define ARRAY_SIZE(array) sizeof(array) / sizeof(array[0])
- /* Exit flag */
- volatile bool g_quit = false;
- /* User-operable LEDs */
- static char *g_leds[1] =
- {
- "/sys/class/leds/blue"
- };
- void sig_handle(int arg)
- {
- g_quit = true;
- }
- int main(int argc, char **argv)
- {
- int i = 0;
- int c = 0;
- int num = 0;
- int flag = 0;
- char cmd[64] = {0};
- while (!g_quit)
- {
- /* Turn on LEDs */
- {
- /* Set the LED brightness value to 0 to turn on the led */
- snprintf(cmd, 64, "echo 0 > %s/brightness", g_leds[0]);
- if (system(cmd) != 0)
- {
- fprintf(stderr, "Error: Failed to turn on %s\n", g_leds[0]);
- exit(EXIT_FAILURE);
- }
- else
- {
- fprintf(stderr, "LED:%s LED_ON \n", g_leds[0]);
- }
- }
- /* Keep the LEDs on for 1000 ms */
- usleep(1000 * 1000);
- /* Turn off LEDs */
- {
- /* Set the LED brightness value to 1 to turn off the LED */
- snprintf(cmd, 64, "echo 1 > %s/brightness", g_leds[i]);
- if (system(cmd) != 0)
- {
- fprintf(stderr, "Error: Failed to turn off %s\n", g_leds[0]);
- exit(EXIT_FAILURE);
- }
- else
- {
- fprintf(stderr, "LED:%s LED_OFF \n", g_leds[0]);
- }
- }
- /* Keep the LEDs off for 1000 ms */
- usleep(1000 * 1000);
- }
- printf("Exit\n");
- return 0;
- }
热门资料
热门活动
全部回复 0
暂无评论,快来抢沙发吧