1#!/usr/bin/env python3

2#

3# Written by:

4# Kunyang Fan <kunyang_fan@aaeon.com.tw>

5

6 import os

7 import sys

8

9

10 def led_brightness_write(led, brightness):

11 print("{} brightness -> {}".format(led, brightness), flush=True)

12 # test led devices exist

13 if not os.path.exists("/sys/class/leds/{}/brightness".format(led)):

14 raise SystemExit("External LED {} not exist".format(led))

15

16 with open("/sys/class/leds/{}/brightness".format(led), "wt") as f:

17 f.write("{}\n".format(brightness))

18

19

20 def led_arrays(model_name):

21 led_data = os.path.expandvars(

22 "$PLAINBOX_PROVIDER_DATA/led-brightness.{}.in".format(model_name)

23 )

24 if not os.path.exists(led_data):

25 raise SystemExit(

26 "ERROR: no led information found at: {}".format(led_data)

27 )

28 with open(led_data, "r") as f:

29 for line in f:

30 if line.startswith("#"):

31 continue

32 yield line.strip()

33

34

35 def main():

36 if len(sys.argv) < 3:

37 raise SystemExit("Usage: led_syfs_brightness.py MODEL_NAME on/off")

38 model_name = sys.argv[1]

39 if sys.argv[2] == "on":

40 brightness = 255

41 else:

42 brightness = 0

43 for led in led_arrays(model_name):

44 led_brightness_write(led, brightness)

45

46

47 if __name__ == "__main__":

48 main()