2014-08-29 07:52:33 -07:00
|
|
|
/**
|
|
|
|
* @file lcd_controller.cpp
|
|
|
|
*
|
|
|
|
* @date Aug 14, 2014
|
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2014
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "main.h"
|
|
|
|
#include "lcd_controller.h"
|
|
|
|
#include "lcd_HD44780.h"
|
|
|
|
#include "efilib.h"
|
|
|
|
#include "rpm_calculator.h"
|
|
|
|
#include "allsensors.h"
|
|
|
|
#include "engine.h"
|
|
|
|
#include "rtc_helper.h"
|
|
|
|
#include "io_pins.h"
|
2014-09-27 12:03:45 -07:00
|
|
|
#include "efiGpio.h"
|
2014-11-03 19:03:18 -08:00
|
|
|
#include "svnversion.h"
|
2015-01-02 20:03:41 -08:00
|
|
|
#include "joystick.h"
|
2014-08-29 07:52:33 -07:00
|
|
|
|
2015-01-02 20:03:41 -08:00
|
|
|
EXTERN_ENGINE
|
|
|
|
;
|
2014-08-29 07:52:33 -07:00
|
|
|
|
2014-11-24 09:03:09 -08:00
|
|
|
extern bool hasFirmwareErrorFlag;
|
|
|
|
|
2014-08-29 07:52:33 -07:00
|
|
|
#define LCD_WIDTH 20
|
|
|
|
// this value should be even
|
|
|
|
#define NUMBER_OF_DIFFERENT_LINES 4
|
|
|
|
|
2015-01-02 20:03:41 -08:00
|
|
|
static int infoIndex = 0;
|
|
|
|
|
|
|
|
void onJoystick(joystick_button_e button) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-08-29 07:52:33 -07:00
|
|
|
char * appendStr(char *ptr, const char *suffix) {
|
2014-09-13 19:02:41 -07:00
|
|
|
for (uint32_t i = 0; i < efiStrlen(suffix); i++) {
|
2014-08-29 07:52:33 -07:00
|
|
|
*ptr++ = suffix[i];
|
|
|
|
}
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
2014-11-03 19:03:18 -08:00
|
|
|
static char * prepareVBattMapLine(engine_configuration_s *engineConfiguration, char *buffer) {
|
2014-08-29 07:52:33 -07:00
|
|
|
char *ptr = buffer;
|
|
|
|
*ptr++ = 'V';
|
2014-11-06 10:04:30 -08:00
|
|
|
ptr = ftoa(ptr, getVBatt(engineConfiguration), 10.0f);
|
2014-08-29 07:52:33 -07:00
|
|
|
|
|
|
|
ptr = appendStr(ptr, " M");
|
|
|
|
ptr = ftoa(ptr, getRawMap(), 10.0f);
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
2014-10-20 08:03:40 -07:00
|
|
|
static char * prepareCltIatTpsLine(Engine *engine, char *buffer) {
|
2014-08-29 07:52:33 -07:00
|
|
|
char *ptr = buffer;
|
|
|
|
*ptr++ = 'C';
|
2014-10-31 12:03:00 -07:00
|
|
|
ptr = ftoa(ptr, getCoolantTemperature(engine), 10.0f);
|
2014-08-29 07:52:33 -07:00
|
|
|
|
|
|
|
ptr = appendStr(ptr, " C");
|
2014-10-31 12:03:00 -07:00
|
|
|
ptr = ftoa(ptr, getIntakeAirTemperature(engine), 10.0f);
|
2014-08-29 07:52:33 -07:00
|
|
|
|
|
|
|
ptr = appendStr(ptr, " TP");
|
2014-11-24 19:03:19 -08:00
|
|
|
ptr = itoa10(ptr, (int) getTPS(PASS_ENGINE_PARAMETER_F));
|
2014-08-29 07:52:33 -07:00
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char* algorithmStr[] = { "MAF", "TPS", "MAP", "SD" };
|
|
|
|
static const char* ignitionModeStr[] = { "1C", "IND", "WS" };
|
|
|
|
static const char* injectionModeStr[] = { "Sim", "Seq", "Bch" };
|
|
|
|
static const char* idleModeStr[] = { "I:A", "I:M" };
|
|
|
|
|
|
|
|
static const char *getPinShortName(io_pin_e pin) {
|
|
|
|
switch (pin) {
|
|
|
|
case ALTERNATOR_SWITCH:
|
|
|
|
return "AL";
|
|
|
|
case FUEL_PUMP_RELAY:
|
|
|
|
return "FP";
|
|
|
|
case FAN_RELAY:
|
|
|
|
return "FN";
|
|
|
|
case O2_HEATER:
|
|
|
|
return "O2H";
|
|
|
|
default:
|
|
|
|
firmwareError("No short name for %d", (int) pin);
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
char * appendPinStatus(char *buffer, io_pin_e pin) {
|
|
|
|
char *ptr = appendStr(buffer, getPinShortName(pin));
|
|
|
|
int state = getOutputPinValue(pin);
|
|
|
|
// todo: should we handle INITIAL_PIN_STATE?
|
|
|
|
if (state) {
|
|
|
|
return appendStr(ptr, ":Y ");
|
|
|
|
} else {
|
|
|
|
return appendStr(ptr, ":n ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-03 19:03:18 -08:00
|
|
|
static char * prepareInfoLine(engine_configuration_s *engineConfiguration, char *buffer) {
|
2014-08-29 07:52:33 -07:00
|
|
|
char *ptr = buffer;
|
|
|
|
|
|
|
|
ptr = appendStr(ptr, algorithmStr[engineConfiguration->algorithm]);
|
|
|
|
|
|
|
|
ptr = appendStr(ptr, " ");
|
|
|
|
ptr = appendStr(ptr, ignitionModeStr[engineConfiguration->ignitionMode]);
|
|
|
|
|
|
|
|
ptr = appendStr(ptr, " ");
|
|
|
|
ptr = appendStr(ptr, injectionModeStr[engineConfiguration->injectionMode]);
|
|
|
|
|
|
|
|
ptr = appendStr(ptr, " ");
|
|
|
|
ptr = appendStr(ptr, idleModeStr[engineConfiguration->idleMode]);
|
|
|
|
|
|
|
|
ptr = appendStr(ptr, " ");
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char * prepareStatusLine(char *buffer) {
|
|
|
|
char *ptr = buffer;
|
|
|
|
|
|
|
|
ptr = appendPinStatus(ptr, FUEL_PUMP_RELAY);
|
|
|
|
ptr = appendPinStatus(ptr, FAN_RELAY);
|
|
|
|
ptr = appendPinStatus(ptr, O2_HEATER);
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char buffer[LCD_WIDTH + 4];
|
|
|
|
static char dateBuffer[30];
|
|
|
|
|
2014-10-20 08:03:40 -07:00
|
|
|
static void prepareCurrentSecondLine(Engine *engine, int index) {
|
2014-08-29 07:52:33 -07:00
|
|
|
memset(buffer, ' ', LCD_WIDTH);
|
|
|
|
char *ptr;
|
|
|
|
switch (index) {
|
|
|
|
case 0:
|
2014-10-20 08:03:40 -07:00
|
|
|
ptr = prepareCltIatTpsLine(engine, buffer);
|
2014-08-29 07:52:33 -07:00
|
|
|
break;
|
|
|
|
case 1:
|
2014-11-03 19:03:18 -08:00
|
|
|
ptr = prepareInfoLine(engine->engineConfiguration, buffer);
|
2014-08-29 07:52:33 -07:00
|
|
|
break;
|
|
|
|
case 2:
|
2014-11-03 19:03:18 -08:00
|
|
|
ptr = prepareVBattMapLine(engine->engineConfiguration, buffer);
|
2014-08-29 07:52:33 -07:00
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
ptr = prepareStatusLine(buffer);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
firmwareError("unexpected case");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
*ptr = ' ';
|
|
|
|
}
|
|
|
|
|
2015-01-02 20:03:41 -08:00
|
|
|
static void showLine(lcd_line_e line) {
|
|
|
|
switch (line) {
|
|
|
|
case LL_VERSION:
|
|
|
|
lcd_HD44780_print_string("version ");
|
|
|
|
lcd_HD44780_print_string(VCS_VERSION);
|
|
|
|
return;
|
|
|
|
case LL_CONFIG:
|
|
|
|
lcd_HD44780_print_string("config ");
|
2014-11-03 19:03:18 -08:00
|
|
|
lcd_HD44780_print_string(getConfigurationName(engine->engineConfiguration->engineType));
|
2014-08-29 07:52:33 -07:00
|
|
|
return;
|
|
|
|
}
|
2015-01-02 20:03:41 -08:00
|
|
|
}
|
2014-08-29 07:52:33 -07:00
|
|
|
|
2015-01-02 20:03:41 -08:00
|
|
|
void updateHD44780lcd(Engine *engine) {
|
|
|
|
for (int i = infoIndex; i < infoIndex + engineConfiguration->HD44780height - 1; i++) {
|
|
|
|
lcd_HD44780_set_position(i - infoIndex, 0);
|
2014-08-29 07:52:33 -07:00
|
|
|
|
2015-01-02 20:03:41 -08:00
|
|
|
showLine((lcd_line_e) i);
|
2014-08-29 07:52:33 -07:00
|
|
|
|
2015-01-02 20:03:41 -08:00
|
|
|
int column = getCurrentHD44780column();
|
2014-08-29 07:52:33 -07:00
|
|
|
|
2015-01-02 20:03:41 -08:00
|
|
|
for (int r = column; r < 20; r++) {
|
|
|
|
lcd_HD44780_print_char('*');
|
|
|
|
}
|
|
|
|
}
|
2014-08-29 07:52:33 -07:00
|
|
|
|
2015-01-02 20:03:41 -08:00
|
|
|
// lcd_HD44780_set_position(0, 0);
|
|
|
|
// bool_t isEven = getTimeNowSeconds() % 2 == 0;
|
|
|
|
//
|
|
|
|
// if (isEven) {
|
|
|
|
//
|
|
|
|
// } else {
|
|
|
|
//
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// lcd_HD44780_set_position(0, 9);
|
|
|
|
// /**
|
|
|
|
// * this would blink so that we know the LCD is alive
|
|
|
|
// */
|
|
|
|
// if (isEven) {
|
|
|
|
// lcd_HD44780_print_char('R');
|
|
|
|
// } else {
|
|
|
|
// lcd_HD44780_print_char(' ');
|
|
|
|
// }
|
|
|
|
// lcd_HD44780_set_position(0, 10);
|
|
|
|
//
|
|
|
|
// char * ptr = itoa10(buffer, getRpmE(engine));
|
|
|
|
// ptr[0] = 0;
|
|
|
|
// int len = ptr - buffer;
|
|
|
|
// for (int i = 0; i < 6 - len; i++) {
|
|
|
|
// lcd_HD44780_print_char(' ');
|
|
|
|
// }
|
|
|
|
// lcd_HD44780_print_string(buffer);
|
|
|
|
//
|
|
|
|
// if (hasFirmwareError()) {
|
|
|
|
// memcpy(buffer, getFirmwareError(), LCD_WIDTH);
|
|
|
|
// buffer[LCD_WIDTH] = 0;
|
|
|
|
// lcd_HD44780_set_position(1, 0);
|
|
|
|
// lcd_HD44780_print_string(buffer);
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// lcd_HD44780_set_position(1, 0);
|
|
|
|
// memset(buffer, ' ', LCD_WIDTH);
|
|
|
|
// memcpy(buffer, getWarninig(), LCD_WIDTH);
|
|
|
|
// buffer[LCD_WIDTH] = 0;
|
|
|
|
// lcd_HD44780_print_string(buffer);
|
|
|
|
//
|
|
|
|
// if (engineConfiguration->HD44780height < 3) {
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// int index = (getTimeNowSeconds() / 2) % (NUMBER_OF_DIFFERENT_LINES / 2);
|
|
|
|
//
|
|
|
|
// prepareCurrentSecondLine(engine, index);
|
|
|
|
// buffer[LCD_WIDTH] = 0;
|
|
|
|
// lcd_HD44780_set_position(2, 0);
|
|
|
|
// lcd_HD44780_print_string(buffer);
|
|
|
|
//
|
|
|
|
// prepareCurrentSecondLine(engine, index + NUMBER_OF_DIFFERENT_LINES / 2);
|
|
|
|
// buffer[LCD_WIDTH] = 0;
|
|
|
|
// lcd_HD44780_set_position(3, 0);
|
|
|
|
// lcd_HD44780_print_string(buffer);
|
|
|
|
//
|
|
|
|
//#if EFI_PROD_CODE
|
|
|
|
// dateToString(dateBuffer);
|
|
|
|
// lcd_HD44780_set_position(1, 0);
|
|
|
|
// lcd_HD44780_print_string(dateBuffer);
|
|
|
|
//#endif /* EFI_PROD_CODE */
|
2014-08-29 07:52:33 -07:00
|
|
|
}
|