thermferm/lcd-pcf8574.c

Thu, 02 May 2024 15:49:16 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Thu, 02 May 2024 15:49:16 +0200
changeset 716
5c30c8ef83a8
parent 426
e54611453d29
permissions
-rw-r--r--

Version 0.9.19b3. The simulator thread can be paused to be able to add and delete simulators. Added simulated door and PSU status. Devices can now fully use multiple simulators. Better rounding of simulated temperature values. The server SIMULATOR DEL and ADD commands pause the simulator when the linked list is manipulated. Fixed SIGSEGV when a simulator is added. Added socket SO_REUSEADDR again to the server socket.

/*
 * lcd-pcf8574.c:
 *	Text-based LCD driver library code
 *	This is designed to drive the HD44780U LCD display connected via
 *	a "LCM1602 IIC  A0 A1 A2" board with a PCF8574 I2C controller.
 *
 * Copyright (c) 2012-2013 Gordon Henderson.
 * Copyright (c) 2014 Michiel Broek.
 ***********************************************************************
 *
 *    mbsePi is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU Lesser General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    mbsePi 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 Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public License
 *    along with wiringPi.  If not, see <http://www.gnu.org/licenses/>.
 ***********************************************************************
 */

#include "thermferm.h"
#include "lcd-pcf8574.h"
#include "slcd.h"


int			lcdHandle;
int			slcdHandle;


#ifdef HAVE_WIRINGPI_H
struct lcdDataStruct
{
    int bits, rows, cols ;
    int rsPin, strbPin ;
    int dataPins [8] ;
    int cx, cy ;
};

extern struct lcdDataStruct	*lcds [MAX_LCDS];
#endif
extern sys_config       	Config;
extern uint16_t			leds;


/*
 * setBacklight:
 *********************************************************************************
 */
void setBacklight(int value)
{
#ifdef HAVE_WIRINGPI_H
    pinMode (AF_BACKLIGHT, OUTPUT) ;
    digitalWrite (AF_BACKLIGHT, (value & 1)) ;
#endif
    if (value) {
	leds |= SLED_LCD;
    } else {
	leds &= ~SLED_LCD;
    }
    slcdLEDs(slcdHandle);
}


/*
 * initLCD:
 *********************************************************************************
 */

int initLCD(int cols, int rows)
{
    if (!((rows == 1) || (rows == 2) || (rows == 4))) {
    	fprintf (stderr, "rows must be 1, 2 or 4\n") ;
    	return EXIT_FAILURE ;
    }

    if (!((cols == 16) || (cols == 20))) {
    	fprintf (stderr, "cols must be 16 or 20\n") ;
    	return EXIT_FAILURE ;
    }

#ifdef HAVE_WIRINGPI_H
    pcf8574Setup(AF_BASE, 0x27) ;
    pinMode (AF_RW, OUTPUT) ;
    digitalWrite (AF_RW, LOW) ;        // Not used with wiringPi - always in write mode

    /*
     * The other control pins are initialised with lcdInit ()
     */
    lcdHandle = lcdInit (rows, cols, 4, AF_RS, AF_E, AF_DB4, AF_DB5, AF_DB6, AF_DB7, 0, 0, 0, 0) ;
    if (lcdHandle < 0) {
    	fprintf (stderr, "lcdInit failed\n") ;
    	return -1 ;
    }

    lcdClear (lcdHandle) ;
#endif

    slcdHandle = slcdInit(0, rows, cols);
    if (slcdHandle < 0) {
	fprintf (stderr, "slcdInit failed\n") ;
	return -1;
    }
    slcdClear(slcdHandle);
    setBacklight(1);

    return 0 ;
}

mercurial