Site Tools


Hotfix release available: 2024-02-06b "Kaos". upgrade now! [55.2] (what's this?)
Hotfix release available: 2024-02-06a "Kaos". upgrade now! [55.1] (what's this?)
New release available: 2024-02-06 "Kaos". upgrade now! [55] (what's this?)
Hotfix release available: 2023-04-04b "Jack Jackrum". upgrade now! [54.2] (what's this?)
Hotfix release available: 2023-04-04a "Jack Jackrum". upgrade now! [54.1] (what's this?)
New release available: 2023-04-04 "Jack Jackrum". upgrade now! [54] (what's this?)
Hotfix release available: 2022-07-31b "Igor". upgrade now! [53.1] (what's this?)
Hotfix release available: 2022-07-31a "Igor". upgrade now! [53] (what's this?)
New release available: 2022-07-31 "Igor". upgrade now! [52.2] (what's this?)
New release candidate 2 available: rc2022-06-26 "Igor". upgrade now! [52.1] (what's this?)
New release candidate available: 2022-06-26 "Igor". upgrade now! [52] (what's this?)
Hotfix release available: 2020-07-29a "Hogfather". upgrade now! [51.4] (what's this?)
New release available: 2020-07-29 "Hogfather". upgrade now! [51.3] (what's this?)
New release candidate 3 available: 2020-06-09 "Hogfather". upgrade now! [51.2] (what's this?)
New release candidate 2 available: 2020-06-01 "Hogfather". upgrade now! [51.1] (what's this?)
New release candidate available: 2020-06-01 "Hogfather". upgrade now! [51] (what's this?)
Hotfix release available: 2018-04-22c "Greebo". upgrade now! [50.3] (what's this?)
Hotfix release available: 2018-04-22b "Greebo". upgrade now! [50.2] (what's this?)
Hotfix release available: 2018-04-22a "Greebo". upgrade now! [50.1] (what's this?)
New release available: 2018-04-22 "Greebo". upgrade now! [50] (what's this?)
Hotfix release available: 2017-02-19g "Frusterick Manners". upgrade now! [49.7] (what's this?)
Hotfix release available: 2017-02-19f "Frusterick Manners". upgrade now! [49.6] (what's this?)
Hotfix release available: 2017-02-19e "Frusterick Manners". upgrade now! [49.5] (what's this?)
Hotfix release available fixing CVE-2017-12979 and CVE-2017-12980: 2017-02-19d "Frusterick Manners". upgrade now! [49.4] (what's this?)
Hotfix release available fixing CVE-2017-12583: 2017-02-19c "Frusterick Manners". upgrade now! [49.3] (what's this?)
led_api

API Application Example

API Header File

#ifndef	__LED_H__
#define	__LED_H__

#include	<stdint.h>		/* uint??_t */
#include	<stdbool.h>		/* Bool */

/***************************************************************************/
/*	For LED
*/
/***************************************************************************/
//	#define	DEVICE_LED_DEBUG_MESSAGE

#define	DEVICE_LED_B14		"/sys/class/leds/b14/brightness"
#define	DEVICE_LED_A25		"/sys/class/leds/a25/brightness"
#define	DEVICE_LED_C21		"/sys/class/leds/c21/brightness"
#define	DEVICE_LED_B15		"/sys/class/leds/b15/brightness"

#define	DEVICE_LED_OIL_STATION_HANDY_READY		DEVICE_LED_B14
#define	DEVICE_LED_OIL_STATION_HANDY_PROCESS	DEVICE_LED_A25
#define	DEVICE_LED_OIL_STATION_HANDY_COLPLETE	DEVICE_LED_C21
#define	DEVICE_LED_OIL_STATION_HANDY_ERROR		DEVICE_LED_B15

#define	DEVICE_LED_OIL_STATION_AP_STATUS		DEVICE_LED_B14
#define	DEVICE_LED_OIL_STATION_AP_ERROR			DEVICE_LED_B15

#define	DEVICE_LED_OIL_STATION_PRINTER_BUSY		DEVICE_LED_B14
#define	DEVICE_LED_OIL_STATION_PRINTER_READY	DEVICE_LED_A25
#define	DEVICE_LED_OIL_STATION_PRINTER_NO_PAPER	DEVICE_LED_B15


/*	LED On/Off
Input
	true = LED On
	false= LED Off
Return
	0	= Opened
	-1	= Input Parameter Error
	-2	= Fail to Access Device
	-3	= Fail to Operation
*/
extern	int	led_switch(uint8_t *pDeviceName, bool Switch/*true=on, false=Off*/);


/*	get LED state
Return
	0	= Opened
	-1	= Input Parameter Error
	-2	= Fail to Access Device
	-3	= Fail to Operation

*pIsOn	: true = LED is On, false = LED is Off
*/
extern	int	led_get(uint8_t *pDeviceName, bool *pIsOn);

#endif	/* __LED_H__ */

API Source File

#include	<stdio.h>
#include	<stdint.h>		/* uint??_t */
#include	<stdbool.h>		/* bool */
#include	<stdlib.h>		/* strtoul */
#include	<string.h>		/* for memset */
#include	<unistd.h>		/* for open/close .. */
#include	<fcntl.h>		/* for O_RDWR */
#include	<sys/ioctl.h>	/* for ioctl */
#include	<sys/fcntl.h>	/* for O_RDWR */

#include	"LED.h"


/*	LED On/Off
Input
	true = LED On
	false= LED Off
Return
	0	= Opened
	-1	= Input Parameter Error
	-2	= Fail to Access Device
	-3	= Fail to Operation
*/
int	led_switch(uint8_t *pDeviceName, bool Switch/*true=on, false=Off*/)
{
	FILE *	pDeviceFile;
	char	pString[2] = { 0, 0 };
	int		StringLength;

	if ( pDeviceName == (uint8_t *)0 )
	{
#ifdef	DEVICE_LED_DEBUG_MESSAGE
		printf("led_switch : Input Parameter error\n");
#endif	/* DEVICE_LED_DEBUG_MESSAGE */
		return	-1;
	}

	pDeviceFile = fopen ( pDeviceName, "w+");
	if ( pDeviceFile == (FILE *)0 )
	{
#ifdef	DEVICE_LED_DEBUG_MESSAGE
		printf ( "led_switch : failed to open LED device : %s\n", pDeviceName );
#endif	/* DEVICE_LED_DEBUG_MESSAGE */
		return	-2;
	}

	if ( Switch == true )
	{
		pString[0] = '1';
	}
	else
	{
		pString[0] = '0';
	}
	StringLength = (int)strlen(pString);
	if ( fwrite ( pString, StringLength, 1, pDeviceFile ) < 0 )
	{
#ifdef	DEVICE_LED_DEBUG_MESSAGE
		printf ( "led_switch : failed to operation LED device : %s\n", pDeviceName );
#endif	/* DEVICE_LED_DEBUG_MESSAGE */
		return	-3;
	}

	fclose ( pDeviceFile );

	return	0;
}


/*	get LED state
Return
	0	= Opened
	-1	= Input Parameter Error
	-2	= Fail to Access Device
	-3	= Fail to Operation

*pIsOn	: true = LED is On, false = LED is Off
*/
int	led_get(uint8_t *pDeviceName, bool *pIsOn)
{
	FILE *	pDeviceFile;
	char	pCommand[128] = {0};
	char	pString[10] = {0};
	int		Value;

	if ( ( pDeviceName == (uint8_t *)0 ) || ( pIsOn == (bool *)0 ) )
	{
#ifdef	DEVICE_LED_DEBUG_MESSAGE
		printf("led_get : Input Parameter error\n");
#endif	/* DEVICE_LED_DEBUG_MESSAGE */
		return	-1;
	}

	sprintf(pCommand, "cat %s", pDeviceName);
	pDeviceFile = popen(pCommand, "r");
	if ( pDeviceFile == (FILE *)0 )
	{
#ifdef	DEVICE_LED_DEBUG_MESSAGE
		printf("led_get : device open fail\n");
#endif	/* DEVICE_LED_DEBUG_MESSAGE */
		return	-2;
	}

	while( fgets (pString, 10, pDeviceFile) );
	Value = (uint32_t)strtoul ( pString, NULL, 10 );
	fclose (pDeviceFile);

	*pIsOn = ((Value == 0) ? false:true);

	return	0;
}
led_api.txt · Last modified: 2017/09/25 22:53 by 1.241.172.144