From e18b7b21c2fe0788e6cf1a1a055a25c2e5bc2dd8 Mon Sep 17 00:00:00 2001 From: The Android Open Source Project Date: Wed, 18 Mar 2009 17:39:47 -0700 Subject: auto import from //branches/cupcake_rel/...@140373 --- led/led_trout.c | 115 -------------------------------------------------------- 1 file changed, 115 deletions(-) delete mode 100644 led/led_trout.c (limited to 'led/led_trout.c') diff --git a/led/led_trout.c b/led/led_trout.c deleted file mode 100644 index b129ec9..0000000 --- a/led/led_trout.c +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include -#include -#include -#include -#include -#include -#include - -#define LOG_TAG "LED" -#include - -const char* const AMBER_BRIGHTNESS_FILE = "/sys/class/leds/amber/brightness"; -const char* const RED_BRIGHTNESS_FILE = "/sys/class/leds/red/brightness"; -const char* const GREEN_BRIGHTNESS_FILE = "/sys/class/leds/green/brightness"; -const char* const BLUE_BRIGHTNESS_FILE = "/sys/class/leds/blue/brightness"; -const char* const BLINK_ENABLE_FILE = "/sys/class/leds/red/device/blink"; -const char* const BLINK_FREQ_FILE = "/sys/class/leds/red/device/grpfreq"; -const char* const BLINK_PWM_FILE = "/sys/class/leds/red/device/grppwm"; - -static int -write_string(const char* file, const char* string, int len) -{ - int fd; - ssize_t amt; - - fd = open(file, O_RDWR); - if (fd < 0) { - LOGE("open failed errno: %d\n", errno); - return errno; - } - - amt = write(fd, string, len); - if (amt < 0) { - LOGE("write failed errno: %d\n", errno); - } - - close(fd); - return amt >= 0 ? 0 : errno; -} - -int trout_set_led_state(unsigned colorARGB, int onMS, int offMS) -{ - int len; - char buf[30]; - int alpha, red, green, blue; - int blink, freq, pwm; - - LOGV("set_led_state colorARGB=%08X, onMS=%d, offMS=%d\n", colorARGB, onMS, offMS); - - // alpha of 0 or color of 0 means off - if ((colorARGB & 0xff000000) == 0 || (colorARGB & 0x00ffffff) == 0) { - onMS = 0; - offMS = 0; - } - - red = (colorARGB >> 16) & 0xFF; - green = (colorARGB >> 8) & 0xFF; - blue = colorARGB & 0xFF; - - len = sprintf(buf, "%d", red); - write_string(RED_BRIGHTNESS_FILE, buf, len); - len = sprintf(buf, "%d", green); - write_string(GREEN_BRIGHTNESS_FILE, buf, len); - len = sprintf(buf, "%d", blue); - write_string(BLUE_BRIGHTNESS_FILE, buf, len); - - if (onMS > 0 && offMS > 0) { - int totalMS = onMS + offMS; - - // the LED appears to blink about once per second if freq is 20 - // 1000ms / 20 = 50 - freq = totalMS / 50; - // pwm specifies the ratio of ON versus OFF - // pwm = 0 -> always off - // pwm = 255 => always on - pwm = (onMS * 255) / totalMS; - - // the low 4 bits are ignored, so round up if necessary - if (pwm > 0 && pwm < 16) - pwm = 16; - - blink = 1; - } else { - blink = 0; - freq = 0; - pwm = 0; - } - - if (blink) { - len = sprintf(buf, "%d", freq); - write_string(BLINK_FREQ_FILE, buf, len); - len = sprintf(buf, "%d", pwm); - write_string(BLINK_PWM_FILE, buf, len); - } - - len = sprintf(buf, "%d", blink); - write_string(BLINK_ENABLE_FILE, buf, len); - - return 0; -} -- cgit v1.1