/* Open port, then Set LED display on/off.  

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2, or (at your option)
   any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software Foundation,
   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 

    File level history (record changes for this file here.)

    led.c   
    
    v 0.0.0  1 January 2016 by Cindy Huang
   
*/
   
#include <stdio.h>
#include <stdlib.h>
#include "msw.h"

#define iTalkVersion	15
#define DisableHB  "echo none > /sys/class/leds/beaglebone::usr0/trigger"
#define RunLED_OFF "echo 1 >/sys/class/leds/beaglebone::usr0/brightness"
#define RunLED_ON  "echo 0 >/sys/class/leds/beaglebone::usr0/brightness"

int main(int argc, char **argv)
{
	int  addr, wRetVal ;
	char value;
  
	if (argc != 2) {
		printf("ICPDAS iTalk utility v%d\n",iTalkVersion);
		printf("Function: led\n");
		printf("Description: Set RunLED ON or OFF \n");
		printf("Usage: led  value\n");
		printf("Range: value: 1->ON ; 0->OFF  \n");
		printf("Example: led  1 \n");
		printf("Set RunLED ON\n");
		return FAILURE;
	}
	
	system(DisableHB); //Disable hardbit
  value=atoi(argv[1]);
  
  switch (value)
  {
    case 0:
    system(RunLED_OFF); //RUN LED ON
    break;
    
    case 1:
    system(RunLED_ON); //RUN LED ON
    break;
  }
 
	return 0;
}
