Show leds.c syntax highlighted
/* -*- Mode: C; tab-width: 4; c-basic-indent: 4; indent-tabs-mode: nil -*- */
/* ex: set tabstop=4 expandtab shiftwidth=4 softtabstop=4: */
/*
*
* Copyright (c) 2003 The Regents of the University of California. All
* rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Neither the name of the University nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <stdio.h>
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <sys/time.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <math.h>
#include <time.h>
#include "emtos_i.h"
char leds_cvsid[] = "";
static int leds_status_printable(status_context_t *info, buf_t *buf)
{
emtos_state_t *emt = (emtos_state_t *) sd_data(info);
bufprintf(buf,
"Current Leds Status:\n"
" Red = %01d\n"
" Green = %01d\n"
" Yellow = %01d\n",
emt->leds_status.red,
emt->leds_status.green,
emt->leds_status.yellow);
return STATUS_MSG_COMPLETE;
}
static int leds_status_binary(status_context_t *info, buf_t *buf)
{
emtos_state_t *emt = (emtos_state_t *) sd_data(info);
bufcpy(buf, &emt->leds_status, sizeof(leds_status_t));
return STATUS_MSG_COMPLETE;
}
void leds_status_init(emtos_state_t *emt)
{
status_dev_opts_t s_opts = {
device: {
device_info: emt,
},
printable: leds_status_printable,
binary: leds_status_binary,
};
s_opts.device.devname = emtos_name(TOS_LEDS_STATUS_DEV, emt->app_name);
if (emt->leds_status_ev != NULL) {
elog(LOG_WARNING, "Warning: trying to register an existing"
" Leds device.\nMake sure Leds.init() is called only"
" once.");
} else {
/* create the status device */
if (g_status_dev(&s_opts, &emt->leds_status_ev) < 0) {
elog(LOG_CRIT, "can't create status dev %s: %m",
s_opts.device.devname);
exit(1);
}
if (emt->leds_status.ledfd == 1) {
emt->leds_status.ledfd = open(STARGATE_LEDS, O_RDWR);
if (emt->leds_status.ledfd < 0) {
emt->leds_status.fdopen = 0;
} else {
emt->leds_status.fdopen = 1;
if (ioctl (emt->leds_status.ledfd, STARGATE_LED_STOP_AUTO) < 0) {
elog(LOG_ERR, "Error ioctl'ing stargate led device");
emt->leds_status.fdopen = 0;
}
}
}
}
}
See more files for this project here