2 * Copyright (C) 2008 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 #include <hardware_legacy/led.h>
17 #include <sys/types.h>
24 const char* const CADENCE_FILE = "/sys/class/leds/left/cadence";
25 const char* const COLOR_FILE = "/sys/class/leds/left/color";
26 const char* const BT_WIFI_FILE = "/sys/class/leds/right/brightness";
29 write_string(const char* file, const char* string, int len)
34 fd = open(file, O_RDWR);
39 amt = write(fd, string, len+1);
42 return amt >= 0 ? 0 : errno;
45 int sardine_set_led_state(unsigned colorARGB, int onMS, int offMS)
49 int red, green, color;
51 // alpha of 0 or color of 0 (ignoring blue) means off
52 if ((colorARGB & 0xff000000) == 0 || (colorARGB & 0x00ffff00) == 0) {
58 if ((colorARGB & 0x00ffff00) == 0 && (colorARGB & 0x000000ff) != 0) {
59 colorARGB |= (colorARGB & 0x000000ff) << 8;
63 // this color conversion isn't really correct, but it's better to
64 // have the light come bright on when asked for low intensity than to
65 // not come on at all. we have no blue
66 red = (colorARGB & 0x00ff0000) ? 1 : 0;
67 green = (colorARGB & 0x0000ff00) ? 2 : 0;
68 color = (red | green) - 1;
70 len = sprintf(buf, "%d", color);
71 write_string(COLOR_FILE, buf, len);
74 len = sprintf(buf, "%d,%d", onMS, offMS);
75 write_string(CADENCE_FILE, buf, len);