
/*
 * Include Files
 *
 */
#if defined(MATLAB_MEX_FILE)
#include "tmwtypes.h"
#include "simstruc_types.h"
#else
#define SIMPLIFIED_RTWTYPES_COMPATIBILITY
#include "rtwtypes.h"
#undef SIMPLIFIED_RTWTYPES_COMPATIBILITY
#endif



/* %%%-SFUNWIZ_wrapper_includes_Changes_BEGIN --- EDIT HERE TO _END */
#ifndef MATLAB_MEX_FILE

#include <Wire.h>
#include <hd44780.h>
#include <hd44780ioClass/hd44780_I2Cexp.h>

// Anlegen der Displayvariablen
hd44780_I2Cexp lcd;

const char LCD_COLS = 16;
const char LCD_ROWS = 2;

unsigned char displaystate = 1;

#endif
/* %%%-SFUNWIZ_wrapper_includes_Changes_END --- EDIT HERE TO _BEGIN */
#define u_width 1

/*
 * Create external references here.  
 *
 */
/* %%%-SFUNWIZ_wrapper_externs_Changes_BEGIN --- EDIT HERE TO _END */
 
/* %%%-SFUNWIZ_wrapper_externs_Changes_END --- EDIT HERE TO _BEGIN */

/*
 * Start function
 *
 */
void LCD_Display_Start_wrapper(real_T *xD)
{
/* %%%-SFUNWIZ_wrapper_Start_Changes_BEGIN --- EDIT HERE TO _END */
#ifndef MATLAB_MEX_FILE	

 int status;

    status = lcd.begin(LCD_COLS, LCD_ROWS); // Initialisierung des Displays
	if(status)
	{
		hd44780::fatalError(status);
	}
    
#endif
/* %%%-SFUNWIZ_wrapper_Start_Changes_END --- EDIT HERE TO _BEGIN */
}
/*
 * Output function
 *
 */
void LCD_Display_Outputs_wrapper(const uint8_T *DisplayStatus,
			const real_T *xD)
{
/* %%%-SFUNWIZ_wrapper_Outputs_Changes_BEGIN --- EDIT HERE TO _END */
#ifndef MATLAB_MEX_FILE
if ( displaystate != DisplayStatus[0] ) // Wenn sich der Displaystatus ändert
  
{
    
    displaystate = DisplayStatus[0];

    switch(displaystate) // wird zwischen verschiedenen Displayausgaben gewechselt
    {
        
        case 0:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Bitte mit Taste");
    	lcd.setCursor(0,1);
        lcd.print("A / B anmelden");
        break;

        case 1:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Bitte geben Sie");
    	lcd.setCursor(0,1);
        lcd.print("den PIN ein!");
        break;

        case 2:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Eingabe korrekt");
        break;
        
        case 3:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("PIN falsch bitte");
        lcd.setCursor(0,1);
        lcd.print("erneut versuchen");
        break;

        case 4:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Funktionsauswahl");
    	lcd.setCursor(0,1);
        lcd.print("Taste A / B / C");
        break;

        case 5:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Schloss wird");
    	lcd.setCursor(0,1);
        lcd.print("entsperrt");
        break;

        case 6:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Zum Verriegeln");
    	lcd.setCursor(0,1);
        lcd.print("[1] dr\365cken");
        break;

        case 7:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Finger auflegen");
    	lcd.setCursor(0,1);
        lcd.print("und [1] dr\365cken");
        break;

        case 8:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Fingerabdruck");
    	lcd.setCursor(0,1);
        lcd.print("wird gepr\365ft");
        break;
 
        case 9:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Fingerabdruck");
    	lcd.setCursor(0,1);
        lcd.print("nicht erkannt");
        break;

        case 10:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("ALARM: ZUGRIFF");
    	lcd.setCursor(0,1);
        lcd.print("VERWEIGERT");
        break;

        case 11:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Abdruck wird");
    	lcd.setCursor(0,1);
        lcd.print("erneut gepr\365ft");
        break;

        case 12:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Fingerabdruck");
    	lcd.setCursor(0,1);
        lcd.print("wurde gewechselt");
        break;

        case 13:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Finger ab- und");
    	lcd.setCursor(0,1);
        lcd.print("auflegen [1]");
        break;

        case 14:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Zum PIN wechseln");
    	lcd.setCursor(0,1);
        lcd.print("[1] dr\365cken");
        break;

        case 15:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Bitte 1. Ziffer");
    	lcd.setCursor(0,1);
        lcd.print("vom PIN eingeben");
        break;

        case 16:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Bitte 2. Ziffer");
    	lcd.setCursor(0,1);
        lcd.print("vom PIN eingeben");
        break;

        case 17:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Bitte 3. Ziffer");
    	lcd.setCursor(0,1);
        lcd.print("vom PIN eingeben");
        break;

        case 18:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Bitte 4. Ziffer");
    	lcd.setCursor(0,1);
        lcd.print("vom PIN eingeben");
        break;

        case 19:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("PIN erfolgreich");
    	lcd.setCursor(0,1);
        lcd.print("gewechselt");
        break;

        case 20:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("T\365r ge\357ffnet");
    	lcd.setCursor(0,1);
        lcd.print("Bitte schlie\342en");
        break;

    }

}

#endif
/* %%%-SFUNWIZ_wrapper_Outputs_Changes_END --- EDIT HERE TO _BEGIN */
}

/*
 * Updates function
 *
 */
void LCD_Display_Update_wrapper(const uint8_T *DisplayStatus,
			real_T *xD)
{
/* %%%-SFUNWIZ_wrapper_Update_Changes_BEGIN --- EDIT HERE TO _END */
 
/* %%%-SFUNWIZ_wrapper_Update_Changes_END --- EDIT HERE TO _BEGIN */
}

