#include "msw.h"
#include "am335x.h"
 
#define VERSION "1.0 20150721"

void help()
{
	printf("function : led\n");
	printf("LP-5231 set LED display ON/OFF \n");
	printf("Example :led -l1 -g1 -r0\n");
	printf("Set LED1 Green ON and Red OFF\n");
	printf("Example :led -l2 -g1 \n");
	printf("Set LED2 Green ON\n");
}

int main(int argc,char **argv)
{
	int c;
	int led = -1;
	int green = -1;
	int red = -1;
	int show_ver = 0;

	if (argc < 2)
        {
		help();
		return FAILURE;
	}


	while((c=getopt(argc, argv, "hl:g:r:v")) != -1)
	{
		switch(c)
		{
			case 'h':
				help();
				break;

			case 'l':
				led = atoi(optarg);

				if(led != 1 && led != 2)
				{
					printf("command(l) out of range\n");
					return FAILURE;
				}
				break;

			case 'g':
				green = atoi(optarg);

				if(green != 1 && green != 0)
				{
					printf("command(g) out of range\n");
					return FAILURE;
				}
				break;

			case 'r':
				red = atoi(optarg);

				if(red != 1 && red != 0)
				{
					printf("command(r) out of range\n");
					return FAILURE;
				}
				break;

			case 'v':
				show_ver = 1;
				break;

			case '?':
				help();
				return FAILURE;

			default:
				help();
				return NOERROR;
				
		}
	}


	if(show_ver)
		printf("led version %s\n", VERSION);

	lp5231_set_led(led, green, red);

	return NOERROR;
}

