void LED_R_Init(void) { // Initialisation d'un port SPI pour 74HC595 d'affichage des LEDS * ROUGES * SpiCreate(0, // Creation du port SPI n° 0 PC, // Utilisation du port XPPI-PC du Rovin (1<<4)|3, // MOSI sur PC.3 (poids faible) initialise a 1 (poids fort) 2, // MISO sur PC.2 (non utilise ici) (0<<4)|1, // SCK sur PC.1 initialise a 0 (0<<4)|0, // CS sur PC.0 initialise a 0 SPI_CPHA0|SPI_CPOL0, // Utilisation modes CPHA0 et CPOL0 SPI_MSBFIRST, // Configuration pour sortie des bits de poids fort en premier 0); // Vitesse maximale du port SPI SpiOut(0, 0xff); SpiLatch(0, SPI_HIGHPULSE); // Extinction des Leds }
int ModeHandler(int mode, char *textIn, int argc, char **argv) { LcdSpi *lcd; Spi *spiBus0; ScreenData *screenBg; int result = 0; Fonts font; iconv_t ic; size_t res; char text[MAX_ISO8859_LEN] = ""; memset(&font, 0, sizeof(Fonts)); spiBus0 = SpiCreate(0); if (spiBus0 == NULL) { printf("SPI-Error\n"); exit(EXITCODE_ERROR); } lcd = LcdOpen(spiBus0); if (!lcd) { printf("LCD-Error\n"); exit(EXITCODE_ERROR); } if (gConfig.mIsInit == 1) { LcdInit(lcd); } else if (gConfig.mIsInit == 2) { LcdUninit(lcd); exit(EXITCODE_OK); } if (gConfig.mIsBgLight) { LcdSetBgLight(lcd, gConfig.mBgLight & 1, gConfig.mBgLight & 2, gConfig.mBgLight & 4); } screenBg = ScreenInit(LCD_X, LCD_Y); if (!screenBg) { printf("Screen-Error\n"); exit(EXITCODE_ERROR); } ScreenClear(screenBg); if (gConfig.mBgFilename) { if (ScreenLoadImage(screenBg, gConfig.mBgFilename, gConfig.mBgOffX, gConfig.mBgOffY) != 0) { ScreenClear(screenBg); } } if (textIn) { int testInLen = strlen(textIn); char **inPtr = &textIn; char *outPtr = &text[0]; ic = iconv_open("ISO-8859-1", "UTF-8"); if (ic != (iconv_t)(-1)) { size_t inBytesLeft = testInLen; size_t outBytesLeft = sizeof(text) - 1; res = iconv(ic, inPtr, &inBytesLeft, &outPtr, &outBytesLeft); if ((int)res != -1 && outBytesLeft) { outPtr[0] = 0; } else { strncpy(text, textIn, sizeof(text) - 1); text[sizeof(text) - 1] = 0; } iconv_close(ic); } } //printf("Mode: %i\n", mode); switch (mode) { case OPT_YESNO: LoadFonts(&font); result = YesNo(lcd, &font, text, screenBg); break; case OPT_OK: LoadFonts(&font); result = Ok(lcd, &font, text, screenBg); break; case OPT_MENU: LoadFonts(&font); result = Menu(lcd, &font, screenBg, optind, argc, argv); break; case OPT_IPV4: LoadFonts(&font); result = Ipv4(lcd, &font, text, screenBg, optind, argc, argv); break; case OPT_SUBNETMASK: LoadFonts(&font); result = Subnetmask(lcd, &font, text, screenBg, optind, argc, argv); break; case OPT_INFO: LoadFonts(&font); result = Info(lcd, &font, text, screenBg); break; case OPT_BUTTONWAIT: result = ButtonWait(); break; case OPT_INTINPUT: LoadFonts(&font); result = IntInput(lcd, &font, text, screenBg, optind, argc, argv); break; case OPT_PROGRESS: LoadFonts(&font); result = Progress(lcd, &font, text, screenBg, optind, argc, argv); break; case OPT_PERCENT: LoadFonts(&font); result = Percent(lcd, &font, text, screenBg, optind, argc, argv); break; default: break; } if (font.mSystem) { //FontDestroy(font.mSystem); } if (font.mInternal) { //FontDestroy(font.mInternal); } if (gConfig.mIsClear) { LcdCls(lcd); } ScreenDestroy(screenBg); LcdCleanup(lcd); SpiDestroy(spiBus0); return result; }