/*
  v 1.0 By Winson 2017.4.7
  Create first version
  This demo for LX-Series PAC only.
  Control three led once a time.
*/
/*
#include <stdio.h>
#include "msw.h"

int main(int argc, char **argv)
{
	int led, status;

	if(argc != 3)
	{
        	printf("led 0 -> RUN   status 0 -> OFF\n    1 -> L1           1 -> ON\n    2 -> L2\n");
		printf("Usage: ./led_signal 0 1\n");
		return 0;
	}

	led = atoi(argv[1]);
	status = atoi(argv[2]);

	if(led > 2 || led < 0 || status > 1 || status < 0)
	{
		printf("Invalid parameters\n");
		return -1;
	}

	SetLED_Single(led, status);
	return 0;
}
*/


#include <stdio.h>
#include <getopt.h>
#include "msw.h"

void usage();
char* const short_options = "hvs";
struct option long_options[] = {
	{"help", 0, NULL, 'h'},
	{"version", 0, NULL, 'v'},
	{"support", 0, NULL, 's'},
	{0, 0, 0, 0},
};

int main(int argc, char **argv)
{
	int led, status, c;

	if(argc == 2)
	{
		while((c = getopt_long (argc, argv, short_options, long_options, NULL)) != -1)
        	{
	                switch (c)
        	        {
	                        case 'h':
        	                        usage();
                	                return 0;
	                        case 'v':
        	                        printf("SDK version = %s \n",GetSDKversion());
                	                return 0;
	                        case 's':
        	                        printf("Support LX-8X31 LX-9X71 LX-9X81\n");
                	                return 0;
	                        default:
        	                        printf("Try `read_sn -h' for more information.\n");
                	                return 0;
	                        break;
        	        }
	        }
	}
	else if(argc != 3)
        {
                printf("led 0 -> RUN   status 0 -> OFF\n    1 -> L1           1 -> ON\n    2 -> L2\n");
                printf("Usage: ./led_signal 0 1\n");
		printf("Usage: ./led_signal -h\n");
                return 0;
        }

	led = atoi(argv[1]);
	status = atoi(argv[2]);

	if(led > 2 || led < 0 || status > 1 || status < 0)
	{
		printf("Invalid parameters\n");
		return -1;
	}

	SetLED_Single(led, status);
	return 0;
}

void usage()
{
        printf("Control single led.\n");
        printf("-h,     display this help and exit\n");
        printf("-v,     output SDK version and exit\n");
        printf("-s,     support LinPAC platform\n");
}


