示例#1
0
文件: lcd.cpp 项目: FoxKyong/WinUAE
static int lcd_init (void)
{
	DWORD ret;
	lgLcdOpenContext octx;
	HBITMAP bmp;
	BITMAP binfo;
	HDC dc;
	int x, y;

	old_pri = 0;
	ret = lgLcdInit ();
	if (ret != ERROR_SUCCESS) {
		if (ret == RPC_S_SERVER_UNAVAILABLE || ret == ERROR_OLD_WIN_VERSION) {
			write_log (_T("LCD: Logitech LCD system not detected\n"));
			return 0;
		}
		write_log (_T("LCD: lgLcdInit() returned %d\n"), ret);
		return 0;
	}
	memset (&cctx, 0, sizeof (cctx));
	cctx.appFriendlyName = _T("WinUAE");
	cctx.isPersistent = TRUE;
	cctx.isAutostartable = FALSE;
	ret = lgLcdConnect (&cctx);
	if (ret != ERROR_SUCCESS) {
		write_log (_T("LCD: lgLcdConnect() returned %d\n"), ret);
		lcd_close ();
		return 0;
	}
	ret = lgLcdEnumerateEx (cctx.connection, 0, &desc);
	if (ret != ERROR_SUCCESS) {
		write_log (_T("LCD: lgLcdEnumerateEx() returned %d\n"), ret);
		lcd_close ();
		return 0;
	}
	lbh = (lgLcdBitmapHeader*)xcalloc (uae_u8, sizeof (lgLcdBitmapHeader) + desc.Width * (desc.Height + 20));
	lbh->Format = LGLCD_BMP_FORMAT_160x43x1;
	bitmap = (uae_u8*)lbh + sizeof (lgLcdBitmapHeader);
	origbitmap = xcalloc (uae_u8, desc.Width * desc.Height);
	memset (&octx, 0, sizeof (octx));
	octx.connection = cctx.connection;
	octx.index = 0;
	ret = lgLcdOpen (&octx);
	if (ret != ERROR_SUCCESS) {
		write_log (_T("LCD: lgLcdOpen() returned %d\n"), ret);
		lcd_close ();
		return 0;
	}
	device = octx.device;

	bmp = LoadBitmap (hInst, MAKEINTRESOURCE(IDB_LCD160X43));
	dc = CreateCompatibleDC (NULL);
	SelectObject (dc, bmp);
	GetObject (bmp, sizeof (binfo), &binfo);
	for (y = 0; y < binfo.bmHeight; y++) {
		for (x = 0; x < binfo.bmWidth; x++) {
			bitmap[y * binfo.bmWidth + x] = GetPixel (dc, x, y) == 0 ? 0xff : 0;
		}
	}
	numbers = bitmap + desc.Width * desc.Height;
	memcpy (origbitmap, bitmap, desc.Width * desc.Height);
	DeleteDC (dc);

	write_log (_T("LCD: '%s' enabled\n"), desc.deviceDisplayName);
	return 1;
}
示例#2
0
/***********************************************************************
 *
 * Function: c_entry
 *
 * Purpose: Application entry point from the startup code
 *
 * Processing:
 *     See function.
 *
 * Parameters: None
 *
 * Outputs: None
 *
 * Returns: Always returns 1, or <0 on an error
 *
 * Notes: None
 *
 **********************************************************************/
int c_entry(void)
{
  SWIM_WINDOW_T win1;
  COLOR_T *fblog;
  INT_32 lcddev;

  /* Disable interrupts in ARM core */
  disable_irq_fiq();

  /* Setup miscellaneous board functions */
  phy3250_board_init();

  /* Set virtual address of MMU table */
  cp15_set_vmmu_addr((void *)
                     (IRAM_BASE + (256 * 1024) - (16 * 1024)));

  /* Initialize interrupt system */
  int_initialize(0xFFFFFFFF);

  /* Install standard IRQ dispatcher at ARM IRQ vector */
  int_install_arm_vec_handler(IRQ_VEC, (PFV) lpc32xx_irq_handler);

  /* Install RTC interrupt handler as a IRQ interrupts */
  int_install_irq_handler(IRQ_RTC, (PFV) rtc_user_interrupt);

  /* Open RTC */
  rtcdev = rtc_open(RTC, 0);
  if (rtcdev == 0)
  {
    /* Error */
    return -1;
  }

  /* Set a 1s match rate */
  secs = lsecs = 0;
  mstp.match_num      = 0;
  mstp.use_match_int  = TRUE;
  mstp.enable_onsw    = FALSE;
  mstp.match_tick_val = secs + 1;
  rtc_ioctl(rtcdev, RTC_ENABLE, 0);
  rtc_ioctl(rtcdev, RTC_SET_COUNT, 0);
  rtc_ioctl(rtcdev, RTC_CLEAR_INTS, RTC_MATCH0_INT_STS);
  rtc_ioctl(rtcdev, RTC_SETUP_MATCH, (INT_32) &mstp);

  /* Setup LCD muxing for STN Color 16BPP */
  clkpwr_setup_lcd(CLKPWR_LCDMUX_TFT16, 1);

  /* Enable clock to LCD block (HCLK_EN)*/
  clkpwr_clk_en_dis(CLKPWR_LCD_CLK, 1);

  /* Setup LCD paramaters in the LCD controller */
  lcddev = lcd_open(CLCDC, (INT_32) & LCD_DISPLAY);

  /* Upper Panel Frame Base Address register */
  lcd_ioctl(lcddev, LCD_SET_UP_FB, PHY_LCD_FRAME_BUF);

  /* Enable LCD controller and power signals */
  lcd_ioctl(lcddev, LCD_PWENABLE, 1);

  /* Enable LCD backlight */
  phy3250_lcd_backlight_enable(TRUE);

  /* Enable LCD power */
  phy3250_lcd_power_enable(TRUE);

  /* Set frame buffer address */
  fblog = (COLOR_T *) cp15_map_physical_to_virtual(PHY_LCD_FRAME_BUF);

  /* Create a SWIM window */
  swim_window_open(&win1, LCD_DISPLAY.pixels_per_line,
                   LCD_DISPLAY.lines_per_panel, fblog, 0, 0,
                   (LCD_DISPLAY.pixels_per_line - 1), (LCD_DISPLAY.lines_per_panel - 1),
                   1, WHITE, BLACK, BLACK);
  swim_put_ltext(&win1, "RTC example: This example will print the message "
                 "TICK whenever an RTC interrupt occurs (1 second intervals). It will "
                 "quit after 10 seconds\n");

  /* Enable RTC (starts counting) */
  rtc_ioctl(rtcdev, RTC_ENABLE, 1);

  /* Enable RTC interrupt in the interrupt controller */
  int_enable(IRQ_RTC);

  /* Enable IRQ interrupts in the ARM core */
  enable_irq();

  /* Loop for 10 seconds and let interrupts toggle the LEDs */
  while (secs < 10)
  {
    if (lsecs < secs)
    {
      swim_put_ltext(&win1, "TICK\n");
      lsecs = secs;
    }
  }
  /* Disable RTC interrupt in the interrupt controller */
  int_disable(IRQ_RTC);

  /* Disable interrupts in ARM core */
  disable_irq_fiq();

  /* Prior to closing the RTC, the ONSW key value is set. This will
     allow the RTC to keep it's value across resets as long as RTC
   power is maintained */
  rtc_ioctl(rtcdev, RTC_SETCLR_KEY, 1);

  /* Close RTC and LCD */
  rtc_close(rtcdev);
  lcd_close(lcddev);

  return 1;
}
示例#3
0
int main(int argc, char* argv[])
{

 	#ifdef __linux__
 	struct sigaction sig_struct;
	sig_struct.sa_handler = sig_handler;
	sig_struct.sa_flags = 0;
	sigemptyset(&sig_struct.sa_mask);

	if (sigaction(SIGINT, &sig_struct, NULL) == -1)
    {
		cout << "Problem with sigaction" << endl;
		exit(1);
	}
	#endif // __linux__


/// ===    File read needed if moving something from PC to here
//    myFP = fopen(netname, "a+");
//    if(myFP == NULL)
//        {
//        cout<<"ERROR opening"<<endl;
//        exit(1);
//        }
//    fread(read_buf, 1, 100, myFP);
//    int buffersize = strlen(read_buf);
//    fclose(myFP);
//    cout<<"read the file: "<<read_buf<<endl;
// =============================================================

    int lcdp=lcd_open();
    int adcp=ADS1015_Init("/dev/i2c-1");

    PCA9685 myPCA={0x40, 0, 69, 0, 0, 0x11, 0x4, 50, 0x79,}; // control structure
    myPCA.file=PCA_Init("/dev/i2c-1");
    PCA9685_start(myPCA.file);

    //adcresult=read_convert_register(adcp);
    //sprintf(dis_buf, "ADC: %6.3f V", adcresult);
    //lcd_write(dis_buf);


	lcd_write("Hello from Steve's\nLCD stuff");
	lcd_clear();
	get_NIST();

	mcp23s17_enable_interrupts(GPIO_INTERRUPT_PIN);
	//mcp23s17_enable_interrupts(SW_GPIO_INTERRUPT_PIN);

	cout.setf(ios::fixed);
	//=== SET CURRENT TIME ==========================
	struct tm *newtime;								//--- for time now
	time_t long_time;								//--- Get time as long integer.
	double DeltaT=0.0;								//--- time since is in minutes

	Observer PLACENTIA={"Yorba Linda",Rad(33.909),Rad(-117.782),30.0,0};
	//Observer PHILLY={"Philly",Rad(40.0),Rad(-75.0),0.0,0};
	double sdctime;
	SATELSET Eset;
	SATPOS satpos;
	//ELLIPSE myEllipse;
	//double SP,JDG,E2JD,JDN;
	double JDG,E2JD,JDN;
	VectorIJK test,test1;           //ptest;
	//VectLook testlook;
	SATSUB SB;

	clock_t goal;
	clock_t wait=(clock_t)2 * CLOCKS_PER_SEC;       // change the 2 for update rate, 2= about 2 seconds

	Read_TLE(argv[1], Eset);                        // read the 2 line data

	do
	{
		time( &long_time );
		newtime=gmtime( &long_time );                   // time, expressed as a UTC time, GMT timezone
		JDN=JD_Now(newtime);							//--- JD based on system clock as GMT
		JDG=ThetaG_JD(JDN);								//--- in radians
		E2JD=Epoch2JD(Eset.iEpochYear,Eset.dEpochDay);	//--- JD based on TLE epoch
		double local_time=0.0;
		double test_time=0.0;

        local_time=newtime->tm_yday+1+(newtime->tm_hour+(newtime->tm_min+newtime->tm_sec/60.0)/60.0)/24.0;
        test_time=local_time-Eset.dEpochDay;
        //cout<<"test_time delta days "<<test_time<<endl;
        test_time*=1440.0;
        //cout<<"test_time delta minutes "<<test_time<<endl;

/**************************************
 local_time minus Eset.dEpochDay matches JDN-E2JD.
 And is easier to check and calculate and no need for
 all the JD and JD0 code.
*************************************/
		sdctime=JDN-E2JD;								//--- delta days
		sdctime*=1440.0;                                // delta minutes
		//sdctime=fmod(sdctime,60);
        //cout<<"Current sdctime "<<sdctime<<endl;

		DeltaT=sdctime;

        //satpos=SatPos(DeltaT, &Eset);				    //--- get satellite position
		satpos=clean_SatPos(DeltaT, &Eset);

		cout<<"=====Satellite ECI position============================\n"<<satpos;

		test=Obs_Position(PLACENTIA,JDG);				//--- get observer position
		//test1=Obs_to_ECI(PHILLY,JDG);                 //-- test data from TS Kelso
		test1=Obs_to_ECI(PLACENTIA,JDG);
		testlook=LookAngles(satpos, PLACENTIA,JDG);		//--- get look angles
		SB= SatSubPoint(satpos,JDG);

		cout<<"=====Observer ECI====================\n"<<test1;
		cout<<"=====Observer Look angles============\n"<<testlook; // for antenna tracker
		cout<<"=====Sat Sub Point===================\n"<<SB;



/// used before
    //int s_count=read_convert_register_count(adcp);
    //set_count(myPCA.file, 0, 5, s_count); // file channel, start count, end count




/// LCD setup and stuff

    adcresult=read_convert_register_volts(adcp);
    sprintf(dis_buf, "ADC: %6.3f V", adcresult);
    lcd_write(dis_buf);

    /// aztovolts is the target reference position
    double aztovolts = (Deg(testlook.AZ)) * (3.2/360.0);

    /// wtf is the difference of the pot input, adcresults, and reference
    double wtf = aztovolts - adcresult; /// double - float

    printf("\nVOLTS ADC: %6.3f V\n",adcresult);
    printf("AZ Degrees: %6.3f \n",Deg(testlook.AZ));
    printf("AZ to volts: %6.3f V\n",aztovolts);
    printf("DELTA: %6.3f \n",wtf);

    /**
    volts   0       1.6     3.2
    count   200     320     450
            max left    no motion   max right
            1 ms    1.5 ms  2ms
            50 hz timing
    **/

    /// for applying delta Vin
    //float PCAcount = (wtf*80)+320;   ///this is for  0 - 3.2 Vin
    float PCAcount = (wtf*80)+300;   ///this is for  0 - 3.2 Vin, 340 from measurements

    if(wtf< -1.25)
        PCAcount = 240;
    else if(wtf> 1.25)
            PCAcount = 425;


    //set_count(myPCA.file, 0, 5, PCAcount); // file channel, start count, end count
    set_count(myPCA.file, 0, 1, PCAcount); // file channel, start count, end count
    //set_count(myPCA.file, 1, 1, PCAcount); // file channel, start count, end count

    printf("MOTOR count: %6.3f \n",PCAcount);



//#define TRACK 0
//#define LOCATION 1
//#define SATDATA 2
//#define NIST 3

    if(display_count < 5)
    {
        display_control(TRACK, PLACENTIA, SB, Eset, testlook);
        display_count++;
        LED_off(GPIO_INTERRUPT_PIN);
    }
    else
    {
        display_control(LOCATION, PLACENTIA, SB, Eset, testlook);
        display_count++;
        LED_on(GPIO_INTERRUPT_PIN);
    }

    if(display_count > 10)
    {
        display_count = 0;
	}

        /**
            ====================
            Look angles:visible
            AZ:123456 EL:123456
            Sat LAT/LONG
            LT:123456 LG:123456
            ====================
            Location Yorba Linda
            LT:123456 LG:123456
            Range: 123456

            ====================
            Tracking:ISS (ZARYA)
            Incl:12345
            MM: 123456
            MA: 123456

        **/
/// LCD done

		goal = wait + clock();
		while( goal > clock() );

        #ifdef __linux__
        if(ctrl_c_pressed)
            {
                cout << "Ctrl^C Pressed" << endl;
                cout << "unexporting pins" << endl;
                //gpio26->unexport_gpio();
                //gpio16->unexport_gpio();
                mcp23s17_disable_interrupts(GPIO_INTERRUPT_PIN);
                //mcp23s17_disable_interrupts(SW_GPIO_INTERRUPT_PIN);

                cout << "deallocating GPIO Objects" << endl;
                //delete gpio26;
                //gpio26 = 0;
                //delete gpio16;
                //gpio16 =0;
                break;

            }
        #endif // __linux__
	}

	#ifdef __linux__
    	while(1);
    #elif _WIN32
        while(!(_kbhit()));
    #else
    #endif

	//while(1);
    //while(!(_kbhit()));

		//pthread_exit(NULL);
		set_all(myPCA.file, 0, 0);      /// kill the servos
		lcd_close();                    /// kill the LCD

	return 0;
}
示例#4
0
文件: lcd.c 项目: abyman/garage
int main(int argc, char *argv[]) { 
   //Set our Logging Mask and open the Log
   setlogmask(LOG_UPTO(LOG_ERR));
   openlog(DAEMON_NAME, LOG_CONS | LOG_NDELAY | LOG_PERROR | LOG_PID, LOG_USER);
   syslog(LOG_INFO, "Entering Daemon");
   pid_t pid, sid;

   //Fork the Parent Process
   pid = fork();
   if (pid < 0) { exit(EXIT_FAILURE); }

   //We got a good pid, Close the Parent Process
   if (pid > 0) { exit(EXIT_SUCCESS); }

   //Change File Mask
   umask(0);

   //Create a new Signature Id for our child
   sid = setsid();
   if (sid < 0) { exit(EXIT_FAILURE); }

   //Change Directory
   //If we cant find the directory we exit with failure.
   if ((chdir("/")) < 0) { exit(EXIT_FAILURE); }

   // Ensure only one copy 
   char *pidfile = PIDFILE;
   int pidFilehandle = open(pidfile, O_RDWR|O_CREAT, 0600);
   if (pidFilehandle == -1 )
   {
      // Couldn't open lock file 
      syslog(LOG_ERR, "Could not open PID lock file %s, exiting", pidfile);
      exit(EXIT_FAILURE);
   }

   // Try to lock file 
   if (lockf(pidFilehandle,F_TLOCK,0) == -1)
   {
      // Couldn't get lock on lock file 
      syslog(LOG_ERR, "Could not lock PID lock file %s, exiting", pidfile);
      exit(EXIT_FAILURE);
   }
   // Get and format PID 
   char str[10];
   sprintf(str,"%d\n",getpid());
   // write pid to lockfile 
   write(pidFilehandle, str, strlen(str));
   syslog(LOG_INFO, "created pid file %s with content %s", pidfile, str);

   //Close Standard File Descriptors
   close(STDIN_FILENO);
   close(STDOUT_FILENO);
   close(STDERR_FILENO);

   // Main code
   mraa_init();
   mraa_gpio_context gpio[6];
   char l1[16] = "LCD Daemon";
   char l2[16] = " Started ";
   char T[5], H[5];
   int numReads = 0;
   time_t now = time(NULL);
   struct tm *t = localtime(&now);
   lcd_init(gpio);
   lcd_text(gpio, l1, 1);
   lcd_text(gpio, l2, 2);
   sleep(1);
   while(1) {
      // Read LOGFILE to retrieve Temp and Humidity
      FILE *f = fopen(LOGFILE, "r");
      if (f == NULL)
         return(1);
      numReads = fscanf(f, "%s", T);
      numReads += fscanf(f, "%s", H);
      fclose(f);
      if(numReads > 1) {
         sprintf(l1, "  %sC  %s%%", T, H);
         lcd_text(gpio, l1, 1);
      }
      // Grab and display the date and time on the second line
      time(&now);
      t = localtime(&now);
      strftime(l2, sizeof(l2), " %d.%m.%y %H:%M", t);
      lcd_text(gpio, l2, 2); 
      // Sleep for a minute
      sleep(58);
   }
   
   lcd_close(gpio);
	return MRAA_SUCCESS;
}
示例#5
0
int main(int argc, const char *argv[])
{
	uint8_t ret;
	uint8_t init = 1;
	cfg_t *cfg;

       	int32_t adc_channel = -1;
	uint32_t val_cur[MCP32XX_MAX_CHANNEL], val_old[MCP32XX_MAX_CHANNEL];
	int32_t diff;

	struct mcp32xx_dev mcp_dev;
	struct volume_handle v_handle = {0};
	struct mpd_handle m_handle = {0};
	struct lcd_handle l_handle = {0};

	useconds_t sleep_usec;
	uint8_t song_update_count_max;
	uint8_t song_update_count = 0;

	cfg_opt_t opts[] = {
		CFG_INT("UpdateInterval", 300000, CFGF_NONE),
		CFG_INT("SongUpdateInterval", 2000000, CFGF_NONE),
		CFG_INT("ChannelUsed", 2, CFGF_NONE),
		CFG_INT("VolumeChannel", 0, CFGF_NONE),
		CFG_INT("TunerChannel", 1, CFGF_NONE),
		CFG_INT("MaxLineChar", 16, CFGF_NONE),
		CFG_INT("MaxLineBuf", 80, CFGF_NONE),
		CFG_STR("HostName", "localhost", CFGF_NONE),
		CFG_INT("Port", 6600, CFGF_NONE),
		CFG_INT("MaxTunerPos", 12, CFGF_NONE),
		CFG_INT("MaxVolSteps", 50, CFGF_NONE),
		CFG_STR("RadioPlaylistName", "stations", CFGF_NONE),
		CFG_INT("LCD-Pin_RS", 25, CFGF_NONE),
		CFG_INT("LCD-Pin_E", 24, CFGF_NONE),
		CFG_INT("LCD-Pin_DB4", 23, CFGF_NONE),
		CFG_INT("LCD-Pin_DB5", 17, CFGF_NONE),
		CFG_INT("LCD-Pin_DB6", 27, CFGF_NONE),
		CFG_INT("LCD-Pin_DB7", 22, CFGF_NONE),
		CFG_STR("FillPatternFirstLine", " ++ ", CFGF_NONE),
		CFG_STR("FillPatternSecondLine", " ** ", CFGF_NONE),
		CFG_INT("MaxLineLength", 16, CFGF_NONE),
		CFG_INT("MaxLineBufferLength", 80, CFGF_NONE),
        	CFG_END()
	};

	cfg = cfg_init(opts, CFGF_NONE);

	ret = cfg_parse(cfg, "/etc/radioberry.conf");
	if(ret == CFG_FILE_ERROR) {
		perror("/etc/radioberry.conf");
		printf("WARN: could not read /etc/radioberry.conf,"
				" process with default values\n");
	} else if (ret == CFG_PARSE_ERROR) {
		printf("configuration parse error\n");
		goto out;
	}

	/* get configuration values */
	channel_used = (uint8_t)cfg_getint(cfg, "ChannelUsed");
	volume_chan = (uint8_t)cfg_getint(cfg, "VolumeChannel");
	tuner_chan = (uint8_t)cfg_getint(cfg, "TunerChannel");

	sleep_usec = cfg_getint(cfg, "UpdateInterval") / channel_used;
	printf("sleep_usec %d\n", sleep_usec);
	song_update_count_max = cfg_getint(cfg, "SongUpdateInterval")
		/ sleep_usec;
	/* pass over pointer to handles of mpd, lcd and volume */
	m_handle.lh = &l_handle;
	v_handle.mh = &m_handle;

	m_handle.cfg = cfg;
	l_handle.cfg = cfg;

	signal(SIGINT, sigintterm_handler);
	signal(SIGTERM, sigintterm_handler);

	ret = lcd_init(&l_handle);
	if (ret) {
		printf("failed to initialize lcd, lcd control disabled \n");
		lcd_control_enabled = 0;
	}

	if (lcd_control_enabled) {
		lcd_print_string("Radioberry");
		lcd_move_cursor_down();
		lcd_print_string("=== Welcome ===");
	}

	ret = mcp32xx_init(&mcp_dev);
	if (ret) {
		printf("failed to initialize spi device, analog control"
				" devices disabled\n");
		tuner_control_enabled = 0;
		vol_control_enabled = 0;
	}

	ret = init_mpd_handle(&m_handle);
	if (ret) {
		printf("could not initialize mpd client,"
				" tuner control disabled\n");
		tuner_control_enabled = 0;
	}

	/* disable tuner control if we cannot get any station at all. If one
	 * station fails, let's process and wait for tuner changes */
	ret = load_stations_playlist(&m_handle);
	if (ret == 1) {
		printf("could not load radio stations list,"
				" tuner control disabled\n");
		tuner_control_enabled = 0;
	}

	ret = init_vol_control(&v_handle);
	if (ret) {
		printf("could not initialize volume control,"
				" volumen control disabled\n");
		vol_control_enabled = 0;
	}

	running = 1;

	while ( running ) {
		usleep(sleep_usec);

		if (adc_channel + 1 == channel_used) {
			adc_channel = 0;
			mpd_status_update(m_handle.mpd_obj);
			/* detect if initial loop is done. Start update lcd
			 * after initial loop */
			if (init)
				init = 0;
			else {
				if (lcd_control_enabled)
					lcd_update_screen(&l_handle);
			}
		} else
			adc_channel++;

		if (song_update_count == song_update_count_max) {
			update_song_info(&m_handle);
			song_update_count = 0;
		} else
			song_update_count++;

		/* loop over all channels in singel ended mode
		 * and reset counter in the last loop. */
		val_cur[adc_channel] = mcp32xx_get_val(&mcp_dev, adc_channel);

		/* fill the old value buffer and intialize the player with
		 * current settings*/
		if (init) {
			val_old[adc_channel] = val_cur[adc_channel];

			ret = process_value(&v_handle, &m_handle,
					val_cur[adc_channel], adc_channel);

			/* skip comparing old/new values while intializing */
			if (ret) {
				printf("unrecoverable error, quit now\n");
				break;
			}
			else
				continue;
		}

		diff = val_old[adc_channel] - val_cur[adc_channel];

#ifdef DEBUG
		printf("adc_channel: %u, old %u, new %u, diff %d\n",
				adc_channel, val_cur[adc_channel],
			       	val_old[adc_channel], diff);
#endif

		if (abs(diff) < TOLERANT_THRESHOLD)
			continue;
#ifdef DEBUG
		if (diff > 0)
			printf("Poti %u was turned left, current val: %d\n",
				adc_channel + 1, val_cur[adc_channel]);
		else
			printf("Poti %u was turned right, current Pos: %d\n",
				adc_channel + 1, val_cur[adc_channel]);
#endif
		process_value(&v_handle, &m_handle, val_cur[adc_channel],
				adc_channel);
		val_old[adc_channel] = val_cur[adc_channel];
	}
out:
	lcd_clear_screen();
	lcd_close(&l_handle);
	mcp32xx_close(&mcp_dev);
	close_vol_ctl(&v_handle);
	close_mpd_handle(&m_handle);

	exit(ret);
}