Exemplo n.º 1
0
/**
 * @brief   Sets RTC time.
 *
 * @param[in] rtcp      pointer to RTC driver structure
 * @param[in] tv_sec    time specification
 * @return              Unix time value in seconds.
 *
 * @api
 */
void rtcSetTimeUnixSec(RTCDriver *rtcp, time_t tv_sec) {
  RTCTime timespec = {0,0};

  timespec.tv_sec = tv_sec;
  timespec.tv_msec = 0;
  rtcSetTime(rtcp, &timespec);
}
Exemplo n.º 2
0
/**
 * @brief   Sets RTC time.
 *
 * @param[in] rtcp      pointer to RTC driver structure
 * @param[out] timp     pointer to a @p tm structure as defined in time.h
 *
 * @api
 */
void rtcSetTimeTm(RTCDriver *rtcp, struct tm *timp) {
  RTCTime timespec = {0,0};

  timespec.tv_sec = mktime(timp);
  timespec.tv_msec = 0;
  rtcSetTime(rtcp, &timespec);
}
Exemplo n.º 3
0
static void rtc_set_time_unix(time_t t) {
  RTCDateTime timespec;
  struct tm tim;

  localtime_r(&t, &tim);
  rtcConvertStructTmToDateTime(&tim, 0, &timespec);
  rtcSetTime(&RTCD1, &timespec);
}
Exemplo n.º 4
0
cell pawn_setRtc( AMX * amx, const cell * params )
{
	(void)amx;
    RTCTime rtc;
    rtc.tv_sec  = params[1] / 1000;
    rtc.tv_msec = params[1] - (rtc.tv_sec);
    rtcSetTime( &RTCD1, &rtc );
    return 0;
}
Exemplo n.º 5
0
static bool_t stm32_set_datetime(TDateTime *dt)
{
	if(dt){	
		rt.tv_sec = datetime_mktime(dt);			
		rtcSetTime(&RTCD1,&rt);
		return TRUE;
	}
	return FALSE;
}
Exemplo n.º 6
0
/**
 * @brief   Sets RTC time.
 *
 * @param[in] rtcp      pointer to RTC driver structure
 * @param[out] timp     pointer to a @p tm structure as defined in time.h
 *
 * @api
 */
void rtcSetTimeTm(RTCDriver *rtcp, struct tm *timp) {
#if STM32_RTC_HAS_SUBSECONDS
  RTCTime timespec = {0,0,FALSE,0};
#else
  RTCTime timespec = {0,0,FALSE};
#endif

  stm32_rtc_tm2bcd(timp, &timespec);
  rtcSetTime(rtcp, &timespec);
}
Exemplo n.º 7
0
/**
 * @brief   Sets RTC time.
 *
 * @param[in] rtcp      pointer to RTC driver structure
 * @param[in] tv_sec    time specification
 * @return              Unix time value in seconds.
 *
 * @api
 */
void rtcSetTimeUnixSec(RTCDriver *rtcp, time_t tv_sec) {
#if STM32_RTC_HAS_SUBSECONDS
  RTCTime timespec = {0,0,FALSE,0};
#else
  RTCTime timespec = {0,0,FALSE};
#endif

  stm32_rtc_tm2bcd(localtime(&tv_sec), &timespec);
  rtcSetTime(rtcp, &timespec);
}
Exemplo n.º 8
0
/**
  * Sets the STM32 internal time (RTC)
  * @param date Date in Julian calendar format
  */
void setTime(ptime_t date) {
	RTCDateTime timespec;
	timespec.year = date.year - 2000;
	timespec.month = date.month;
	timespec.day = date.day;
	timespec.millisecond = date.hour * 3600000 + date.minute * 60000 + date.second * 1000 + date.millisecond;

	TRACE_INFO("GPS  > Calibrate RTC");
	PRINT_TIME("RTC");
	rtcSetTime(&RTCD1, &timespec);
}
Exemplo n.º 9
0
static void rtcWriteData(RTC* rtc, UInt16 ioPort, UInt8 value)
{
    int block;

    switch (rtc->latch) {
    case 0x0d:
        rtcUpdateRegs(rtc);
        rtc->modeReg = value;
        return;

    case 0x0e:
        rtcUpdateRegs(rtc);
        rtc->testReg = value;
        return;

    case 0x0f:
        rtc->resetReg = value;

        if (value & RESET_ALARM) {
            int i;

            for (i = 2; i <= 8; i++) {
                rtc->registers[1][i] = 0;
            }
        }
        if (value & RESET_FRACTION) {
            rtc->fraction = 0;
        }
        return;
    }

    block = rtc->modeReg & MODE_BLOCKSELECT;

    if (block == 0) {
        rtcUpdateRegs(rtc);
    }

    rtc->registers[block][rtc->latch] = value & mask[block][rtc->latch];

    if (block == 0) {
        rtcSetTime(rtc);
    }
}
Exemplo n.º 10
0
void sp5K_writeFunction(void)
{

u08 dateTimeStr[11];
char tmp[3];
RtcTimeType rtcDateTime;
char *p;
u08 devId, address, regValue;
u08 value = 0;
s08 retS = FALSE;
u08  mcp_address = 0;
u08 length = 0;
u08 *nro = NULL;
u08 *msg = NULL;
u08 timeout;
char phase;
u08 chip;
u16 sleepTime;

	memset( cmd_printfBuff, NULL, CHAR128);
	makeargv();

	// Parametros:
	if (!strcmp_P( strupr(argv[1]), PSTR("PARAM\0")))
	{

		// PASSWD
		if (!strcmp_P( strupr(argv[2]), PSTR("PASSWD\0"))) {
			memset(systemVars.passwd, '\0', sizeof(systemVars.passwd));
			memcpy(systemVars.passwd, argv[3], sizeof(systemVars.passwd));
			systemVars.passwd[PASSWD_LENGTH - 1] = '\0';
			pv_snprintfP_OK();
			return;
		}

		// APN
		if (!strcmp_P( strupr(argv[2]), PSTR("APN\0"))) {
			memset(systemVars.apn, '\0', sizeof(systemVars.apn));
			memcpy(systemVars.apn, argv[3], sizeof(systemVars.apn));
			systemVars.apn[APN_LENGTH - 1] = '\0';
			pv_snprintfP_OK();
			return;
		}

		// SERVER PORT
		if (!strcmp_P( strupr(argv[2]), PSTR("PORT\0"))) {
			memset(systemVars.serverPort, '\0', sizeof(systemVars.serverPort));
			memcpy(systemVars.serverPort, argv[3], sizeof(systemVars.serverPort));
			systemVars.serverPort[PORT_LENGTH - 1] = '\0';
			pv_snprintfP_OK();
			return;
		}

		// SERVER IP
		if (!strcmp_P( strupr(argv[2]), PSTR("IP\0"))) {
			memset(systemVars.serverAddress, '\0', sizeof(systemVars.serverAddress));
			memcpy(systemVars.serverAddress, argv[3], sizeof(systemVars.serverAddress));
			systemVars.serverAddress[IP_LENGTH - 1] = '\0';
			pv_snprintfP_OK();
			return;
		}

		// SERVER SCRIPT
		// write param script cgi-bin/oseApp/scripts/oseSp5K001.pl
		if (!strcmp_P( strupr(argv[2]), PSTR("SCRIPT\0"))) {
			memset(systemVars.serverScript, '\0', sizeof(systemVars.serverScript));
			memcpy(systemVars.serverScript, argv[3], sizeof(systemVars.serverScript));
			systemVars.serverScript[SCRIPT_LENGTH - 1] = '\0';
			pv_snprintfP_OK();
			return;
		}

		// MagP ( magnitud  por pulso )
		if (!strcmp_P( strupr(argv[2]), PSTR("MAGP\0"))) {
			retS = setParamMagP(argv[3], argv[4]);
			if ( retS ) {
				pv_snprintfP_OK();
			} else {
				pv_snprintfP_ERR();
			}
			return;
		}

		// dname X ( digital name X )
		if (!strcmp_P( strupr(argv[2]), PSTR("DNAME\0"))) {
			retS = setParamDname(argv[3], argv[4]);
			if ( retS ) {
				pv_snprintfP_OK();
			} else {
				pv_snprintfP_ERR();
			}
			return;
		}

		// aname X ( analog name X )
		if (!strcmp_P( strupr(argv[2]), PSTR("ANAME\0"))) {
			retS = setParamAname(argv[3], argv[4]);
			if ( retS ) {
				pv_snprintfP_OK();
			} else {
				pv_snprintfP_ERR();
			}
			return;
		}

		// imin X
		if (!strcmp_P( strupr(argv[2]), PSTR("IMIN\0"))) {
			retS = setParamImin(argv[3], argv[4]);
			if ( retS ) {
				pv_snprintfP_OK();
			} else {
				pv_snprintfP_ERR();
			}
			return;
		}

		// imax X
		if (!strcmp_P( strupr(argv[2]), PSTR("IMAX\0"))) {
			retS = setParamImax(argv[3], argv[4]);
			if ( retS ) {
				pv_snprintfP_OK();
			} else {
				pv_snprintfP_ERR();
			}
			return;
		}

		// Mmin X
		if (!strcmp_P( strupr(argv[2]), PSTR("MMIN\0"))) {
			retS = setParamMmin(argv[3], argv[4]);
			if ( retS ) {
				pv_snprintfP_OK();
			} else {
				pv_snprintfP_ERR();
			}
			return;
		}

		// Mmax X
		if (!strcmp_P( strupr(argv[2]), PSTR("MMAX\0"))) {
			retS = setParamMmax(argv[3], argv[4]);
			if ( retS ) {
				pv_snprintfP_OK();
			} else {
				pv_snprintfP_ERR();
			}
			return;
		}

		// offmmin X
		if (!strcmp_P( strupr(argv[2]), PSTR("OFFMMIN\0"))) {
			retS = setParamOffset(0,argv[3], argv[4]);
			if ( retS ) {
				pv_snprintfP_OK();
			} else {
				pv_snprintfP_ERR();
			}
			return;
		}

		// offmmax X
		if (!strcmp_P( strupr(argv[2]), PSTR("OFFMMAX\0"))) {
			retS = setParamOffset(1,argv[3], argv[4]);
			if ( retS ) {
				pv_snprintfP_OK();
			} else {
				pv_snprintfP_ERR();
			}
			return;
		}

		/* DebugLevel */
		if (!strcmp_P( strupr(argv[2]), PSTR("DEBUGLEVEL\0"))) {
			retS = setParamDebugLevel(argv[3]);
			if ( retS ) {
				pv_snprintfP_OK();
			} else {
				pv_snprintfP_ERR();
			}
			return;
		}

		/* LogLevel */
		if (!strcmp_P( strupr(argv[2]), PSTR("LOGLEVEL\0"))) {
			retS = setParamLogLevel(argv[3]);
			if ( retS ) {
				pv_snprintfP_OK();
			} else {
				pv_snprintfP_ERR();
			}
			return;
		}

		// dlgId
		if (!strcmp_P( strupr(argv[2]), PSTR("DLGID\0"))) {
			memcpy(systemVars.dlgId, argv[3], sizeof(systemVars.dlgId));
			systemVars.dlgId[DLGID_LENGTH - 1] = '\0';
			pv_snprintfP_OK();
			return;
		}

		/* TimerPoll */
		if (!strcmp_P( strupr(argv[2]), PSTR("TIMERPOLL\0"))) {
			retS = setParamTimerPoll(argv[3]);
			if ( retS ) {
				pv_snprintfP_OK();
			} else {
				pv_snprintfP_ERR();
			}
			return;
		}

		/* TimerDial */
		if (!strcmp_P( strupr(argv[2]), PSTR("TIMERDIAL\0"))) {
			retS = setParamTimerDial(argv[3]);
			if ( retS ) {
				pv_snprintfP_OK();
			} else {
				pv_snprintfP_ERR();
			}
			return;
		}

		/* Wrkmode */
		if (!strcmp_P( strupr(argv[2]), PSTR("WRKMODE\0"))) {
			retS = setParamWrkMode(argv[3],argv[4]);
			if ( retS ) {
				pv_snprintfP_OK();
			} else {
				pv_snprintfP_ERR();
			}
			return;
		}

		/* Pwrmode */
		if (!strcmp_P( strupr(argv[2]), PSTR("PWRMODE\0"))) {
			retS = setParamPwrMode(argv[3]);
			if ( retS ) {
				pv_snprintfP_OK();
			} else {
				pv_snprintfP_ERR();
			}
			return;
		}

/*		// MONITOR
		// write param monitor [sqe|frame]
		if (!strcmp_P( strupr(argv[2]), PSTR("MONITOR\0"))) {
			retS = setParamMonitor(argv[3]);
			if ( retS ) {
				pv_snprintfP_OK();
			} else {
				pv_snprintfP_ERR();
			}
			return;
		}
*/


	}

	// CONSIGNA
	if (!strcmp_P( strupr(argv[2]), PSTR("CONSIGNA\0"))) {
		retS = setParamConsigna(argv[3], argv[4]);
		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;
	}

	// ALL SystemVars ( save )
	if (!strcmp_P( strupr(argv[1]), PSTR("SAVE\0"))) {
		retS = saveSystemParamsInEE( &systemVars );
		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;
	}

	// RTC
	if (!strcmp_P( strupr(argv[1]), PSTR("RTC\0"))) {
		/* YYMMDDhhmm */
		memcpy(dateTimeStr, argv[2], 10);
		// year
		tmp[0] = dateTimeStr[0]; tmp[1] = dateTimeStr[1];	tmp[2] = '\0';
		rtcDateTime.year = atoi(tmp);
		// month
		tmp[0] = dateTimeStr[2]; tmp[1] = dateTimeStr[3];	tmp[2] = '\0';
		rtcDateTime.month = atoi(tmp);
		// day of month
		tmp[0] = dateTimeStr[4]; tmp[1] = dateTimeStr[5];	tmp[2] = '\0';
		rtcDateTime.day = atoi(tmp);
		// hour
		tmp[0] = dateTimeStr[6]; tmp[1] = dateTimeStr[7];	tmp[2] = '\0';
		rtcDateTime.hour = atoi(tmp);
		// minute
		tmp[0] = dateTimeStr[8]; tmp[1] = dateTimeStr[9];	tmp[2] = '\0';
		rtcDateTime.min = atoi(tmp);

		retS = rtcSetTime(&rtcDateTime);

		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;
	}

	// Si no estoy en modo service no puedo hacer estas tareas administrativas.

	if ( systemVars.wrkMode != WK_SERVICE) {
		snprintf_P( &cmd_printfBuff,CHAR128,PSTR("WARNING: Debe pasar a modo SERVICE !!!\r\n\0"));
		sp5K_printStr(&cmd_printfBuff);
		return;
	}

	// MCP
	// write mcp 0|1|2 addr value
	if (!strcmp_P( strupr(argv[1]), PSTR("MCP\0"))) {
		devId = atoi(argv[2]);
		address = atoi(argv[3]);
		regValue = strtol(argv[4],NULL,2);

		if ( devId == 0 ) { mcp_address = MCP_ADDR0; }
		if ( devId == 1 ) { mcp_address = MCP_ADDR1; }
		if ( devId == 2 ) { mcp_address = MCP_ADDR2; }

		retS = MCP_write( address,  mcp_address, 1, &regValue);
		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;
	}

	// EEPROM
	if (!strcmp_P( strupr(argv[1]), PSTR("EE\0"))) {
		address = atoi(argv[2]);
		p = argv[3];
		while (*p != NULL) {
			p++;
			length++;
			if (length > CMDLINE_BUFFERSIZE )
				break;
		}

		retS = EE_write( address, length, argv[3] );
		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;
	}

	// LED
	// write led 0|1
	if (!strcmp_P( strupr(argv[1]), PSTR("LED\0"))) {
		value = atoi(argv[2]);
		retS = MCP_setLed( value );
		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;
	}

	// gprsPWR
	if (!strcmp_P( strupr(argv[1]), PSTR("GPRSPWR\0"))) {
		value = atoi(argv[2]);
		retS = MCP_setGprsPwr( value );
		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;
	}

	// gprsSW
	if (!strcmp_P( strupr(argv[1]), PSTR("GPRSSW\0"))) {
		value = atoi(argv[2]);
		retS = MCP_setGprsSw( value );
		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;
	}

	// termPWR
	if (!strcmp_P( strupr(argv[1]), PSTR("TERMPWR\0"))) {
		value = atoi(argv[2]);
		retS = MCP_setTermPwr( value );
		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;
	}

	// sensorPWR
	if (!strcmp_P( strupr(argv[1]), PSTR("SENSORPWR\0"))) {
		value = atoi(argv[2]);
		retS = MCP_setSensorPwr( value );
		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;
	}

	// analogPWR
	if (!strcmp_P( strupr(argv[1]), PSTR("ANALOGPWR\0"))) {
		value = atoi(argv[2]);
		retS = MCP_setAnalogPwr( value );
		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;
	}

	// SMS
	if (!strcmp_P(argv[1], PSTR("SMS\0"))) {
		nro = argv[2];
		msg = cmdlineGetArgStr(3);

		rprintfStr(GPRS_UART, "AT+CMGS=\"+\0" );
		rprintfStr(GPRS_UART, nro );
		rprintfStr(GPRS_UART, "\r\0");

		// Espero el prompt > para enviar el mensaje.
		timeout = 10;
		xUartQueueFlush(GPRS_UART);
		while (timeout > 0) {
			vTaskDelay( (portTickType)( 1000 / portTICK_RATE_MS ));
			if (strstr( &xUart0RxedCharsBuffer.buffer, ">") != NULL) {
				break;
			}
			timeout--;
		}
		rprintfStr(GPRS_UART, msg );
		rprintfStr(GPRS_UART, "\r");

		rprintfStr(CMD_UART, &xUart0RxedCharsBuffer.buffer );
		rprintfCRLF(CMD_UART);

		rprintfStr(GPRS_UART, "\032");

		return;
	}

	// ATCMD
	if (!strcmp_P(argv[1], PSTR("ATCMD\0"))) {
		msg = argv[2];
		timeout = atoi(argv[3]);
		if (timeout == 0)
			timeout = 1;

		xUartQueueFlush(GPRS_UART);
		rprintfStr(GPRS_UART, msg);
		rprintfStr(GPRS_UART, "\r\0");

		rprintfStr(CMD_UART, "sent>\0");
		rprintfStr(CMD_UART, msg);
		rprintfCRLF(CMD_UART);

		while (timeout > 0) {
			vTaskDelay( (portTickType)( 1000 / portTICK_RATE_MS ));
			timeout--;
		}

		rprintfStr(CMD_UART, &xUart0RxedCharsBuffer.buffer );
		rprintfCRLF(CMD_UART);

		return;
	}

#ifdef CHANNELS_3

	// Valves: Phase
	// write ph A1 1
	if (!strcmp_P( strupr(argv[1]), PSTR("PH\0"))) {

		phase = toupper( argv[2][0]  );
		//(s0)++;
		chip = argv[2][1] - 0x30;
		value = atoi(argv[3]);

		retS = setValvesPhase(phase,chip, value);
		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;
	}

	// Valves: Enable
	// write en A1 1
	if (!strcmp_P( strupr(argv[1]), PSTR("EN\0"))) {

		phase = toupper( argv[2][0]  );
		//(s0)++;
		chip = argv[2][1] - 0x30;
		value = atoi(argv[3]);

		retS = setValvesEnable(phase,chip, value);
		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;
	}

	// Valves: Reset
	if (!strcmp_P( strupr(argv[1]), PSTR("VRESET\0"))) {

		value = atoi(argv[2]);

		retS = setValvesReset( value );
		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;
	}

	// Valves: Sleep
	if (!strcmp_P( strupr(argv[1]), PSTR("VSLEEP\0"))) {

		value = atoi(argv[2]);

		retS = setValvesSleep( value );
		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;
	}

	// Valves: Pulse [A/B][1/2] {+|-} {ms}
	if (!strcmp_P( strupr(argv[1]), PSTR("VPULSE\0"))) {

		phase = toupper( argv[2][0]  );
		chip = argv[2][1] - 0x30;
		value = toupper( argv[3][0]  );
		sleepTime = atol(argv[4]);

		if ( sleepTime > 5000 ) {
			sleepTime = 5000;
		}

		retS = setValvesPulse( phase, chip, value, sleepTime );
		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;

	}

	// Valves: OPEN
	if (!strcmp_P( strupr(argv[1]), PSTR("OPEN\0"))) {

		phase = toupper( argv[2][0]  );
		chip = argv[2][1] - 0x30;

		retS = setValvesOpen( phase, chip );
		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;

	}

	// Valves: CLOSE
	if (!strcmp_P( strupr(argv[1]), PSTR("CLOSE\0"))) {

		phase = toupper( argv[2][0]  );
		chip = argv[2][1] - 0x30;

		retS = setValvesClose( phase, chip );
		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;

	}

	// Valves: Consigna
	if (!strcmp_P( strupr(argv[1]), PSTR("CONSIGNA\0"))) {

		if (!strcmp_P( strupr(argv[2]), PSTR("DIA\0"))) {
			retS = setConsignaDia();
		}

		if (!strcmp_P( strupr(argv[2]), PSTR("NOCHE\0"))) {
			retS = setConsignaNoche();
		}

		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;

	}
#endif

	// CMD NOT FOUND
	if (xSemaphoreTake( sem_CmdUart, MSTOTAKECMDUARTSEMPH ) == pdTRUE ) {
		rprintfProgStrM(CMD_UART, "ERROR\r\n");
		rprintfProgStrM(CMD_UART, "CMD NOT DEFINED\r\n");
		xSemaphoreGive( sem_CmdUart );
	}
	return;

}
Exemplo n.º 11
0
//**************************************************************************************
//***
//***
//***
//**************************************************************************************
uchar cmdCheck(uchar exec)
{
	uchar cmd = CMD_NONE;
	uchar args[RXBUFSIZE];
	long li;
	uchar a[3];
	uchar i,j;
	
	// ASkr DEBUG
	uchar tmp[30];
	
	cmd = cmdParse(&args);

	
	if( exec != EXEC )
		return cmd;


	switch( cmd )
	{
		//----------------------------------------------------------------------------------
		case CMD_NONE: break;			// NO ACTION IN HERE!
		//----------------------------------------------------------------------------------
		case CMD_OFF: break;			// NO ACTION IN HERE!
		//----------------------------------------------------------------------------------
		case CMD_ERROR: break;		// NO ACTION IN HERE!
		//----------------------------------------------------------------------------------
		case CMD_HELP: serUsage(); break;
		//----------------------------------------------------------------------------------
		case CMD_START:break;			// NO ACTION IN HERE!
		//----------------------------------------------------------------------------------
		case CMD_STOP:break;			// NO ACTION IN HERE!
		//----------------------------------------------------------------------------------
		case CMD_SHOW:
			serShowParams();
			break;
		//----------------------------------------------------------------------------------
		case CMD_LOAD:break;			// NO ACTION IN HERE!
		//----------------------------------------------------------------------------------
		case CMD_SAVE:break;			// NO ACTION IN HERE!
		//----------------------------------------------------------------------------------
		case CMD_TIMESET:
			j = 1;
			for(i=1;i<4;i++)
			{
				li = serMatRead((uchar *)&args,i,':');
				if( li == NUMERR_LONG )
				{
					j = 0;
					break;
				}
				a[i-1] = (uchar)li;
			}
			if(!j)
			{
				serSendString("ERROR\r\n");
				break;
			}
			rtcSetTime(a[0],a[1],a[2]);
			// continue with next CASE below (TIMEQUERY)...
		
		//----------------------------------------------------------------------------------
		case CMD_TIMEQUERY:
			rtcGetTimeString((uchar *)&args);
			serSendStringDebug((uchar *)&args,NUMERR_LONG,"\r\n");
			break;
		//----------------------------------------------------------------------------------
		case CMD_DATESET:
			j = 1;
			for(i=1;i<4;i++)
			{
				li = serMatRead((uchar *)&args,i,'.');
				if( li == NUMERR_LONG )
				{
					j = 0;
					break;
				}
				
				// quick and more than dirty 4-digit year entry hack
				if( ( i == 3 ) && ( li > 2000 ) )
					li-=2000;
				
				a[i-1] = (uchar)li;
			}
			if(!j)
			{
				serSendString("ERROR\r\n");
				break;
			}
      // TODO: either error checks in here or return code upon illegal stuff in rtcSetDate()
			rtcSetDate(a[2],a[1],a[0]);
      
			// continue with next CASE below (DATEQUERY)...
		
		//----------------------------------------------------------------------------------
		case CMD_DATEQUERY:
			rtcGetDateString((uchar *)&args);
			serSendStringDebug((uchar *)&args,NUMERR_LONG,"\r\n");
			break;
		
		//----------------------------------------------------------------------------------
		case CMD_SLEEPSET:
			li = serMatRead((uchar *)&args,1,'X');
			if( (li == 0) || (li == 1) )
				sCfg.rtcSleep = (uchar)li;
			else
			{
				serSendString("ERROR\r\n");
				break;
			}
			// continue with next CASE below (SLEEPQUERY)...
			
		//----------------------------------------------------------------------------------
		case CMD_SLEEPQUERY:
			if( sCfg.rtcSleep == NOSLEEP )
				serSendString("0\r\n");
			else
				serSendString("1\r\n");
			break;
		//----------------------------------------------------------------------------------
		case CMD_SRATESET:
			li = serMatRead((uchar *)&args,1,'X');
			if( (li > 0)&&(li < 65536) )
				sCfg.rtcSRate = (unsigned)li;
			else
			{
				serSendString("ERROR\r\n");
				break;
			}
			// continue with next CASE below (SRATEQUERY)...
		//----------------------------------------------------------------------------------
		case CMD_SRATEQUERY:
			serSendStringDebug(NULL,sCfg.rtcSRate,"\r\n");
			break;
		//----------------------------------------------------------------------------------
		case CMD_SMEANSSET:
			li = serMatRead((uchar *)&args,1,'X');
			if( (li > 0)&&(li < 17) )
				sCfg.rtcSMeans = (uchar)li;
			else
			{
				serSendString("ERROR\r\n");
				break;
			}
			// continue with next CASE below (SMEANSQUERY)...
		//----------------------------------------------------------------------------------
		case CMD_SMEANSQUERY:
			serSendStringDebug(NULL,sCfg.rtcSMeans,"\r\n");
			break;
		//----------------------------------------------------------------------------------
		case CMD_SUNITSET:
			i=0;
			switch((uchar)args[0])
			{
				case 's': sCfg.rtcSUnit = SECONDS; break;
				case 'm': sCfg.rtcSUnit = MINUTES; break;
//				case 'h': sCfg.rtcSUnit = HOURS;   break;		// BLOCKED (does not make sense...)
				default:  serSendString("ERROR\r\n"); i=1;
			}
			if( i )
				break;
			// continue with next CASE below (SUNITQUERY)...
				
		//----------------------------------------------------------------------------------
		case CMD_SUNITQUERY:
			switch(sCfg.rtcSUnit)
			{
				case SECONDS: serSendString("S\r\n"); break;
				case MINUTES: serSendString("M\r\n"); break;
				case HOURS:   serSendString("H\r\n"); break;
				default:      serSendString("ERROR\r\n");
			}
			break;
		//----------------------------------------------------------------------------------
		case CMD_SERIALLOGSET:
			serSendString("NOT IMPLEMENTED\r\n");		
			break;
		//----------------------------------------------------------------------------------
		case CMD_SERIALLOGQUERY:
			serSendString("NOT IMPLEMENTED\r\n");		
			break;
		//----------------------------------------------------------------------------------
		case CMD_SEPSET:
			i = (uchar)strlen((uchar*)&args);
			if( i != 1 )
			{
				serSendString("ERROR\r\n");				
				break;
			}
			sCfg.crdSeparator = args[0];
			// continue with next CASE below (SEPQUERY)...

		//----------------------------------------------------------------------------------
		case CMD_SEPQUERY:
			args[0] = ''';
			args[1] = sCfg.crdSeparator;
			args[2] = ''';
			args[3] = 0;
			serSendStringDebug((uchar *)&args,NUMERR_LONG,"\r\n");
			break;
		//----------------------------------------------------------------------------------
		case CMD_LOGDATESET:
			li = serMatRead((uchar *)&args,1,'X');
			if( (li == 0) || (li == 1) )
				sCfg.crdLogDate = (uchar)li;
			else
			{
				serSendString("ERROR\r\n");
				break;
			}
			// continue with next CASE below (LOGDATEQUERY)...

		//----------------------------------------------------------------------------------
		case CMD_LOGDATEQUERY:
			if( sCfg.crdLogDate == NO )
				serSendString("0\r\n");
			else
				serSendString("1\r\n");
			break;
		//----------------------------------------------------------------------------------
		case CMD_LOGTIMESET:
			li = serMatRead((uchar *)&args,1,'X');
			if( (li == 0) || (li == 1) )
				sCfg.crdLogTime = (uchar)li;
			else
			{
				serSendString("ERROR\r\n");
				break;
			}
			// continue with next CASE below (LOGDATEQUERY)...
		
		//----------------------------------------------------------------------------------
		case CMD_LOGTIMEQUERY:
			if( sCfg.crdLogTime == NO )
				serSendString("0\r\n");
			else
				serSendString("1\r\n");
			break;
		//----------------------------------------------------------------------------------
		case CMD_FNAMESET:
			if( !cmdCheckStringAlphaNum( (char *)&args) )
			{
				serSendString("ERROR\r\n");				
				break;
			}
			i = (uchar)strlen((uchar*)&args);
			if( (i < 1 ) || (i > 8) )
			{
				serSendString("ERROR\r\n");	
				break;
			}
			strcpy( (uchar*)&sCfg.crdFName, (uchar*)&args );
			// continue with next CASE below (SUNITQUERY)...

		//----------------------------------------------------------------------------------
		case CMD_FNAMEQUERY:
			serSendString( (uchar *)&sCfg.crdFName);
			serSendString("\r\n");
			break;
		//----------------------------------------------------------------------------------
		case CMD_USECARDSET:
			li = serMatRead((uchar *)&args,1,'X');
			if( (li == 0) || (li == 1) )
				sCfg.crdUseCard = (uchar)li;
			else
			{
				serSendString("ERROR\r\n");
				break;
			}
			// continue with next CASE below (USECARDQUERY)...
		//----------------------------------------------------------------------------------
		case CMD_USECARDQUERY:
			if( sCfg.crdUseCard == NO )
				serSendString("0\r\n");
			else
				serSendString("1\r\n");
			break;
		//----------------------------------------------------------------------------------
		case CMD_BATQUERY:
			measMeasureAllComplete();
			serSendStringDebug(NULL,(long)measGetChannelVoltage(AD_UBEXT),"\r\n");
			break;
		//----------------------------------------------------------------------------------
		case CMD_MEASNOW:
			measMeasureAllComplete();
			li = serMatRead((uchar *)&args,1,'X');
			if( (li >= 0) && (li < 12) )
				serSendStringDebug(NULL,measGetChannelValue((uchar)li),"\r\n");
			else
				serSendString("ERROR\r\n");
			break;
		//----------------------------------------------------------------------------------
		case CMD_MEASVOL:
			measMeasureAllComplete();
			li = serMatRead((uchar *)&args,1,'X');
			if( (li >= 0) && (li < 12) )
				serSendStringDebug(NULL,measGetChannelVoltage((uchar)li),"\r\n");
			else
				serSendString("ERROR\r\n");
			break;
		//----------------------------------------------------------------------------------
		case CMD_VERSIONQUERY:
			serSendStringDebug((uchar*)&sCfg.appVersion,NUMERR_LONG,"\r\n");
			break;
		//----------------------------------------------------------------------------------
		case CMD_DATILASTSET:
			li = serMatRead((uchar *)&args,1,'X');
			if( (li == 0) || (li == 1) )
				sCfg.crdLogDaTi2nd = (uchar)li;
			else
			{
				serSendString("ERROR\r\n");
				break;
			}
			// continue with next CASE below (USECARDQUERY)...
		//----------------------------------------------------------------------------------
		case CMD_DATILASTQUERY:
			if( sCfg.crdLogDaTi2nd == NO )
				serSendString("0\r\n");
			else
				serSendString("1\r\n");
			break;
		//----------------------------------------------------------------------------------
		case CMD_LOGEXCORESET:
			li = serMatRead((uchar *)&args,1,'X');
			if( (li == 0) || (li == 1) )
				sCfg.crdLogExCore = (uchar)li;
			else
			{
				serSendString("ERROR\r\n");
				break;
			}
			// continue with next CASE below (USECARDQUERY)...
		//----------------------------------------------------------------------------------
		case CMD_LOGEXCOREQUERY:
			if( sCfg.crdLogExCore == NO )
				serSendString("0\r\n");
			else
				serSendString("1\r\n");
			break;
		//----------------------------------------------------------------------------------
		case CMD_BGCORRSET:
			li = serMatRead((uchar *)&args,1,'X');
			if( (li < -100) || (li > 100) )
			{
				serSendString("ERROR\r\n");
				break;
			}
			else
				sCfg.meaBandCorr = (schar)li;
			// continue with next CASE below (LOGDATEQUERY)...
		//----------------------------------------------------------------------------------
		case CMD_BGCORRQUERY:
			serSendStringDebug(NULL,(long)sCfg.meaBandCorr,"\r\n");
			break;
		//----------------------------------------------------------------------------------
		default:
			serSendString("***UNKNOWN***\r\n"); break;
	}// END switch
	

	return cmd;
}
Exemplo n.º 12
0
static void rtc_set_time(struct tm *tim) {
  RTCDateTime timespec;
  rtcConvertStructTmToDateTime(tim, 0, &timespec);
  rtcSetTime(&RTCD1, &timespec);
}
void menuGeneralSetup(uint8_t event)
{
#if defined(RTCLOCK)
  struct gtm t;
  gettime(&t);

  if ((menuVerticalPosition==ITEM_SETUP_DATE || menuVerticalPosition==ITEM_SETUP_TIME) &&
      (s_editMode>0) &&
      (event==EVT_KEY_FIRST(KEY_ENTER) || event==EVT_KEY_FIRST(KEY_EXIT) || IS_ROTARY_BREAK(event) || IS_ROTARY_LONG(event))) {
    // set the date and time into RTC chip
    rtcSetTime(&t);
  }
#endif

#if defined(FAI_CHOICE)
  if (warningResult) {
    warningResult = 0;
    g_eeGeneral.fai = true;
    eeDirty(EE_GENERAL);
  }
#endif

  MENU(STR_MENURADIOSETUP, menuTabGeneral, e_Setup, ITEM_SETUP_MAX, { 2, 2, 1, LABEL(SOUND), 0, 0, 0, 0, 0, 0, 0, CASE_VARIO_CPUARM(LABEL(VARIO)) CASE_VARIO_CPUARM(0) CASE_VARIO_CPUARM(0) CASE_VARIO_CPUARM(0) CASE_VARIO_CPUARM(0) CASE_HAPTIC(LABEL(HAPTIC)) CASE_HAPTIC(0) CASE_HAPTIC(0) CASE_HAPTIC(0) 0, LABEL(ALARMS), 0, 0, 0, 0, IF_ROTARY_ENCODERS(0) LABEL(BACKLIGHT), 0, 0, 0, CASE_REVPLUS(0) CASE_PWM_BACKLIGHT(0) CASE_PWM_BACKLIGHT(0) 0, CASE_SPLASH_PARAM(0) CASE_GPS(LABEL(GPS)) CASE_GPS(0) CASE_GPS(0) CASE_GPS(0) CASE_PXX(0) 0, 0, IF_FAI_CHOICE(0) CASE_MAVLINK(0) 0, 0, LABEL(TX_MODE), 0, 1/*to force edit mode*/ });

  int sub = menuVerticalPosition;

  for (unsigned int i=0; i<NUM_BODY_LINES; i++) {
    coord_t y = MENU_HEADER_HEIGHT + 1 + i*FH;
    uint8_t k = i+menuVerticalOffset;
    uint8_t blink = ((s_editMode>0) ? BLINK|INVERS : INVERS);
    uint8_t attr = (sub == k ? blink : 0);

    switch(k) {
      case ITEM_SETUP_DATE:
        lcd_putsLeft(y, STR_DATE);
        lcd_putc(RADIO_SETUP_DATE_COLUMN, y, '-'); lcd_putc(RADIO_SETUP_DATE_COLUMN+3*FW-2, y, '-');
        for (uint8_t j=0; j<3; j++) {
          uint8_t rowattr = (menuHorizontalPosition==j ? attr : 0);
          switch (j) {
            case 0:
              lcd_outdezAtt(RADIO_SETUP_DATE_COLUMN, y, t.tm_year+1900, rowattr);
              if (rowattr && s_editMode>0) t.tm_year = checkIncDec(event, t.tm_year, 112, 200, 0);
              break;
            case 1:
              lcd_outdezNAtt(RADIO_SETUP_DATE_COLUMN+3*FW-2, y, t.tm_mon+1, rowattr|LEADING0, 2);
              if (rowattr && s_editMode>0) t.tm_mon = checkIncDec(event, t.tm_mon, 0, 11, 0);
              break;
            case 2:
            {
              int16_t year = 1900 + t.tm_year;
              int8_t dlim = (((((year%4==0) && (year%100!=0)) || (year%400==0)) && (t.tm_mon==1)) ? 1 : 0);
              static const pm_uint8_t dmon[] PROGMEM = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
              dlim += pgm_read_byte(&dmon[t.tm_mon]);
              lcd_outdezNAtt(RADIO_SETUP_DATE_COLUMN+6*FW-4, y, t.tm_mday, rowattr|LEADING0, 2);
              if (rowattr && s_editMode>0) t.tm_mday = checkIncDec(event, t.tm_mday, 1, dlim, 0);
              break;
            }
          }
        }
        if (attr && menuHorizontalPosition < 0) drawFilledRect(RADIO_SETUP_2ND_COLUMN, y, LCD_W-RADIO_SETUP_2ND_COLUMN-MENUS_SCROLLBAR_WIDTH, 8);
        if (attr && checkIncDec_Ret) {
        g_rtcTime = gmktime(&t); // update local timestamp and get wday calculated
        }
        break;

      case ITEM_SETUP_TIME:
        lcd_putsLeft(y, STR_TIME);
        lcd_putc(RADIO_SETUP_TIME_COLUMN+1, y, ':'); lcd_putc(RADIO_SETUP_TIME_COLUMN+3*FW-2, y, ':');
        for (uint8_t j=0; j<3; j++) {
          uint8_t rowattr = (menuHorizontalPosition==j ? attr : 0);
          switch (j) {
            case 0:
              lcd_outdezNAtt(RADIO_SETUP_TIME_COLUMN, y, t.tm_hour, rowattr|LEADING0, 2);
              if (rowattr && s_editMode>0) t.tm_hour = checkIncDec(event, t.tm_hour, 0, 23, 0);
              break;
            case 1:
              lcd_outdezNAtt(RADIO_SETUP_TIME_COLUMN+3*FWNUM, y, t.tm_min, rowattr|LEADING0, 2);
              if (rowattr && s_editMode>0) t.tm_min = checkIncDec(event, t.tm_min, 0, 59, 0);
              break;
            case 2:
              lcd_outdezNAtt(RADIO_SETUP_TIME_COLUMN+6*FWNUM, y, t.tm_sec, rowattr|LEADING0, 2);
              if (rowattr && s_editMode>0) t.tm_sec = checkIncDec(event, t.tm_sec, 0, 59, 0);
              break;
          }
        }
        if (attr && menuHorizontalPosition < 0) drawFilledRect(RADIO_SETUP_2ND_COLUMN, y, LCD_W-RADIO_SETUP_2ND_COLUMN-MENUS_SCROLLBAR_WIDTH, 8);
        if (attr && checkIncDec_Ret)
        g_rtcTime = gmktime(&t); // update local timestamp and get wday calculated
        break;

      case ITEM_SETUP_BATT_RANGE:
        lcd_putsLeft(y, STR_BATTERY_RANGE);
        putsVolts(RADIO_SETUP_2ND_COLUMN, y,  90+g_eeGeneral.vBatMin, (menuHorizontalPosition==0 ? attr : 0)|LEFT|NO_UNIT);
        lcd_putc(lcdLastPos, y, '-');
        putsVolts(lcdLastPos+FW, y, 120+g_eeGeneral.vBatMax, (menuHorizontalPosition>0 ? attr : 0)|LEFT|NO_UNIT);
        if (attr && menuHorizontalPosition < 0) drawFilledRect(RADIO_SETUP_2ND_COLUMN, y, LCD_W-RADIO_SETUP_2ND_COLUMN-MENUS_SCROLLBAR_WIDTH, 8);
        if (attr && s_editMode>0) {
          if (menuHorizontalPosition==0)
            CHECK_INCDEC_GENVAR(event, g_eeGeneral.vBatMin, -50, g_eeGeneral.vBatMax+29); // min=4.0V
          else
            CHECK_INCDEC_GENVAR(event, g_eeGeneral.vBatMax, g_eeGeneral.vBatMin-29, +40); // max=16.0V
        }
        break;

      case ITEM_SETUP_SOUND_LABEL:
        lcd_putsLeft(y, STR_SOUND_LABEL);
        break;

      case ITEM_SETUP_BEEP_MODE:
        g_eeGeneral.beepMode = selectMenuItem(RADIO_SETUP_2ND_COLUMN, y, STR_SPEAKER, STR_VBEEPMODE, g_eeGeneral.beepMode, -2, 1, attr, event);
#if defined(FRSKY)
        if (attr && checkIncDec_Ret) frskySendAlarms();
#endif
        break;

      case ITEM_SETUP_SPEAKER_VOLUME:
      {
        lcd_putsLeft(y, STR_SPEAKER_VOLUME);
        uint8_t b = g_eeGeneral.speakerVolume+VOLUME_LEVEL_DEF;
        displaySlider(RADIO_SETUP_2ND_COLUMN, y, b, VOLUME_LEVEL_MAX, attr);
        if (attr) {
          CHECK_INCDEC_GENVAR(event, b, 0, VOLUME_LEVEL_MAX);
          if (checkIncDec_Ret) {
            g_eeGeneral.speakerVolume = (int8_t)b-VOLUME_LEVEL_DEF;
          }
        }
        break;
      }

      case ITEM_SETUP_BEEP_VOLUME:
        SLIDER_5POS(y, g_eeGeneral.beepVolume, STR_BEEP_VOLUME, event, attr);
        break;
      case ITEM_SETUP_WAV_VOLUME:
        SLIDER_5POS(y, g_eeGeneral.wavVolume, STR_WAV_VOLUME, event, attr);
        break;
      case ITEM_SETUP_BACKGROUND_VOLUME:
        SLIDER_5POS(y, g_eeGeneral.backgroundVolume, STR_BG_VOLUME, event, attr);
        break;

      case ITEM_SETUP_BEEP_LENGTH:
        SLIDER_5POS(y, g_eeGeneral.beepLength, STR_BEEP_LENGTH, event, attr);
        break;

      case ITEM_SETUP_SPEAKER_PITCH:
        lcd_putsLeft( y, STR_SPKRPITCH);
        lcd_putcAtt(RADIO_SETUP_2ND_COLUMN, y, '+', attr);
        lcd_outdezAtt(RADIO_SETUP_2ND_COLUMN+FW, y, g_eeGeneral.speakerPitch*15, attr|LEFT);
        lcd_putsAtt(lcdLastPos, y, "Hz", attr);
        if (attr) {
          CHECK_INCDEC_GENVAR(event, g_eeGeneral.speakerPitch, 0, 20);
        }
        break;

#if defined(VARIO)
      case ITEM_SETUP_VARIO_LABEL:
        lcd_putsLeft(y, STR_VARIO);
        break;
      case ITEM_SETUP_VARIO_VOLUME:
        SLIDER_5POS(y, g_eeGeneral.varioVolume, TR_SPEAKER_VOLUME, event, attr);
        break;
      case ITEM_SETUP_VARIO_PITCH:
        lcd_putsLeft(y, STR_PITCH_AT_ZERO);
        lcd_outdezAtt(RADIO_SETUP_2ND_COLUMN, y, VARIO_FREQUENCY_ZERO+(g_eeGeneral.varioPitch*10), attr|LEFT);
        lcd_putsAtt(lcdLastPos, y, "Hz", attr);
        if (attr) CHECK_INCDEC_GENVAR(event, g_eeGeneral.varioPitch, -40, 40);
        break;
      case ITEM_SETUP_VARIO_RANGE:
        lcd_putsLeft(y, STR_PITCH_AT_MAX);
        lcd_outdezAtt(RADIO_SETUP_2ND_COLUMN, y, VARIO_FREQUENCY_ZERO+(g_eeGeneral.varioPitch*10)+VARIO_FREQUENCY_RANGE+(g_eeGeneral.varioRange*10), attr|LEFT);
        lcd_putsAtt(lcdLastPos, y, "Hz", attr);
        if (attr) CHECK_INCDEC_GENVAR(event, g_eeGeneral.varioRange, -80, 80);
        break;
      case ITEM_SETUP_VARIO_REPEAT:
        lcd_putsLeft(y, STR_REPEAT_AT_ZERO);
        lcd_outdezAtt(RADIO_SETUP_2ND_COLUMN, y, VARIO_REPEAT_ZERO+(g_eeGeneral.varioRepeat*10), attr|LEFT);
        lcd_putsAtt(lcdLastPos, y, STR_MS, attr);
        if (attr) CHECK_INCDEC_GENVAR(event, g_eeGeneral.varioRepeat, -30, 50);
        break;
#endif

#if defined(HAPTIC)
      case ITEM_SETUP_HAPTIC_LABEL:
        lcd_putsLeft(y, STR_HAPTIC_LABEL);
        break;

      case ITEM_SETUP_HAPTIC_MODE:
        g_eeGeneral.hapticMode = selectMenuItem(RADIO_SETUP_2ND_COLUMN, y, STR_MODE, STR_VBEEPMODE, g_eeGeneral.hapticMode, -2, 1, attr, event);
        break;

      case ITEM_SETUP_HAPTIC_LENGTH:
        SLIDER_5POS(y, g_eeGeneral.hapticLength, STR_LENGTH, event, attr);
        break;

      case ITEM_SETUP_HAPTIC_STRENGTH:
        SLIDER_5POS(y, g_eeGeneral.hapticStrength, STR_HAPTICSTRENGTH, event, attr);
        break;
#endif

      case ITEM_SETUP_CONTRAST:
        lcd_putsLeft(y, STR_CONTRAST);
        lcd_outdezAtt(RADIO_SETUP_2ND_COLUMN, y, g_eeGeneral.contrast, attr|LEFT);
        if (attr) {
          CHECK_INCDEC_GENVAR(event, g_eeGeneral.contrast, CONTRAST_MIN, CONTRAST_MAX);
          lcdSetContrast();
        }
        break;

      case ITEM_SETUP_ALARMS_LABEL:
        lcd_putsLeft(y, STR_ALARMS_LABEL);
        break;

      case ITEM_SETUP_BATTERY_WARNING:
        lcd_putsLeft(y, STR_BATTERYWARNING);
        putsVolts(RADIO_SETUP_2ND_COLUMN, y, g_eeGeneral.vBatWarn, attr|LEFT);
        if(attr) CHECK_INCDEC_GENVAR(event, g_eeGeneral.vBatWarn, 40, 120); //4-12V
        break;

      case ITEM_SETUP_MEMORY_WARNING:
      {
        uint8_t b = 1-g_eeGeneral.disableMemoryWarning;
        g_eeGeneral.disableMemoryWarning = 1 - onoffMenuItem(b, RADIO_SETUP_2ND_COLUMN, y, STR_MEMORYWARNING, attr, event);
        break;
      }

      case ITEM_SETUP_ALARM_WARNING:
      {
        uint8_t b = 1-g_eeGeneral.disableAlarmWarning;
        g_eeGeneral.disableAlarmWarning = 1 - onoffMenuItem(b, RADIO_SETUP_2ND_COLUMN, y, STR_ALARMWARNING, attr, event);
        break;
      }

      case ITEM_SETUP_INACTIVITY_ALARM:
        lcd_putsLeft(y, STR_INACTIVITYALARM);
        lcd_outdezAtt(RADIO_SETUP_2ND_COLUMN, y, g_eeGeneral.inactivityTimer, attr|LEFT);
        lcd_putc(lcdLastPos, y, 'm');
        if(attr) g_eeGeneral.inactivityTimer = checkIncDec(event, g_eeGeneral.inactivityTimer, 0, 250, EE_GENERAL); //0..250minutes
        break;

      case ITEM_SETUP_BACKLIGHT_LABEL:
        lcd_putsLeft(y, STR_BACKLIGHT_LABEL);
        break;

      case ITEM_SETUP_BACKLIGHT_MODE:
        g_eeGeneral.backlightMode = selectMenuItem(RADIO_SETUP_2ND_COLUMN, y, STR_MODE, STR_VBLMODE, g_eeGeneral.backlightMode, e_backlight_mode_off, e_backlight_mode_on, attr, event);
        break;

      case ITEM_SETUP_FLASH_BEEP:
        g_eeGeneral.alarmsFlash = onoffMenuItem(g_eeGeneral.alarmsFlash, RADIO_SETUP_2ND_COLUMN, y, STR_ALARM, attr, event ) ;
        break;

      case ITEM_SETUP_BACKLIGHT_DELAY:
        lcd_putsLeft(y, STR_BLDELAY);
        lcd_outdezAtt(RADIO_SETUP_2ND_COLUMN, y, g_eeGeneral.lightAutoOff*5, attr|LEFT);
        lcd_putc(lcdLastPos, y, 's');
        if (attr) CHECK_INCDEC_GENVAR(event, g_eeGeneral.lightAutoOff, 0, 600/5);
        break;

      case ITEM_SETUP_BRIGHTNESS:
        lcd_putsLeft(y, STR_BRIGHTNESS);
        lcd_outdezAtt(RADIO_SETUP_2ND_COLUMN, y, 100-g_eeGeneral.backlightBright, attr|LEFT) ;
        if (attr) {
          uint8_t b = 100 - g_eeGeneral.backlightBright;
          CHECK_INCDEC_GENVAR(event, b, 0, 100);
          g_eeGeneral.backlightBright = 100 - b;
        }
        break;

#if defined(REVPLUS)
      case ITEM_SETUP_BACKLIGHT_COLOR:
        lcd_putsLeft(y, STR_BLCOLOR);
        displaySlider(RADIO_SETUP_2ND_COLUMN, y, g_eeGeneral.backlightColor, 20, attr);
        if (attr) g_eeGeneral.backlightColor = checkIncDec(event, g_eeGeneral.backlightColor, 0, 20, EE_GENERAL | NO_INCDEC_MARKS);
        break;
#endif

#if defined(SPLASH) && !defined(FSPLASH)
      case ITEM_SETUP_DISABLE_SPLASH:
      {
        lcd_putsLeft(y, STR_SPLASHSCREEN);
        if (SPLASH_NEEDED()) {
          lcd_outdezAtt(RADIO_SETUP_2ND_COLUMN, y, SPLASH_TIMEOUT/100, attr|LEFT);
          lcd_putc(lcdLastPos, y, 's');
        }
        else {
          lcd_putsiAtt(RADIO_SETUP_2ND_COLUMN, y, STR_MMMINV, 0, attr); // TODO define
        }
        if (attr) g_eeGeneral.splashMode = -checkIncDecGen(event, -g_eeGeneral.splashMode, -3, 4);
        break;
      }
#endif

#if defined(FRSKY) && defined(FRSKY_HUB) && defined(GPS)
      case ITEM_SETUP_LABEL_GPS:
        lcd_putsLeft(y, STR_GPS);
        break;

      case ITEM_SETUP_TIMEZONE:
        lcd_putsLeft(y, STR_TIMEZONE);
        lcd_outdezAtt(RADIO_SETUP_2ND_COLUMN, y, g_eeGeneral.timezone, attr|LEFT);
        if (attr) CHECK_INCDEC_GENVAR(event, g_eeGeneral.timezone, -12, 12);
        break;

      case ITEM_SETUP_ADJUST_RTC:
        g_eeGeneral.adjustRTC = onoffMenuItem(g_eeGeneral.adjustRTC, RADIO_SETUP_2ND_COLUMN, y, STR_ADJUST_RTC, attr, event);
        break;

      case ITEM_SETUP_GPSFORMAT:
        g_eeGeneral.gpsFormat = selectMenuItem(RADIO_SETUP_2ND_COLUMN, y, STR_GPSCOORD, STR_GPSFORMAT, g_eeGeneral.gpsFormat, 0, 1, attr, event);
        break;
#endif

#if defined(PXX)
      case ITEM_SETUP_COUNTRYCODE:
        g_eeGeneral.countryCode = selectMenuItem(RADIO_SETUP_2ND_COLUMN, y, STR_COUNTRYCODE, STR_COUNTRYCODES, g_eeGeneral.countryCode, 0, 2, attr, event);
        break;
#endif

      case ITEM_SETUP_LANGUAGE:
        lcd_putsLeft(y, STR_VOICELANG);
        lcd_putsAtt(RADIO_SETUP_2ND_COLUMN, y, currentLanguagePack->name, attr);
        if (attr) {
          currentLanguagePackIdx = checkIncDec(event, currentLanguagePackIdx, 0, DIM(languagePacks)-2, EE_GENERAL);
          if (checkIncDec_Ret) {
            currentLanguagePack = languagePacks[currentLanguagePackIdx];
            strncpy(g_eeGeneral.ttsLanguage, currentLanguagePack->id, 2);
          }
        }
        break;

      case ITEM_SETUP_IMPERIAL:
        g_eeGeneral.imperial = selectMenuItem(RADIO_SETUP_2ND_COLUMN, y, STR_UNITSSYSTEM, STR_VUNITSSYSTEM, g_eeGeneral.imperial, 0, 1, attr, event);
        break;

#if defined(FAI_CHOICE)
      case ITEM_SETUP_FAI:
        onoffMenuItem(g_eeGeneral.fai, RADIO_SETUP_2ND_COLUMN, y, PSTR("FAI Mode"), attr, event);
        if (attr && checkIncDec_Ret) {
          if (g_eeGeneral.fai)
            POPUP_WARNING(PSTR("FAI\001mode blocked!"));
          else
            POPUP_CONFIRMATION(PSTR("FAI mode?"));
        }
        break;
#endif

#if defined(MAVLINK)
      case ITEM_MAVLINK_BAUD:
        g_eeGeneral.mavbaud = selectMenuItem(RADIO_SETUP_2ND_COLUMN, y, STR_MAVLINK_BAUD_LABEL, STR_MAVLINK_BAUDS, g_eeGeneral.mavbaud, 0, 7, attr, event);
        break;
#endif

      case ITEM_SETUP_SWITCHES_DELAY:
        lcd_putsLeft(y, STR_SWITCHES_DELAY);
        lcd_outdezAtt(RADIO_SETUP_2ND_COLUMN, y, 10*SWITCHES_DELAY(), attr|LEFT);
        lcd_putsAtt(lcdLastPos, y, STR_MS, attr);
        if (attr) CHECK_INCDEC_GENVAR(event, g_eeGeneral.switchesDelay, -15, 100-15);
        break;

      case ITEM_SETUP_RX_CHANNEL_ORD:
        lcd_putsLeft(y, STR_RXCHANNELORD); // RAET->AETR
        for (uint8_t i=1; i<=4; i++) {
          putsChnLetter(RADIO_SETUP_2ND_COLUMN - FW + i*FW, y, channel_order(i), attr);
        }
        if (attr) CHECK_INCDEC_GENVAR(event, g_eeGeneral.templateSetup, 0, 23);
        break;

      case ITEM_SETUP_STICK_MODE_LABELS:
        lcd_putsLeft(y, NO_INDENT(STR_MODE));
        for (uint8_t i=0; i<4; i++) {
          lcd_img((6+4*i)*FW, y, sticks, i, 0);
#if defined(FRSKY_STICKS)
          if (g_eeGeneral.stickReverse & (1<<i)) {
            drawFilledRect((6+4*i)*FW, y, 3*FW, FH-1);
          }
#endif
        }
#if defined(FRSKY_STICKS)
        if (attr) {
          s_editMode = 0;
          CHECK_INCDEC_GENVAR(event, g_eeGeneral.stickReverse, 0, 15);
          lcd_rect(6*FW-1, y-1, 15*FW+2, 9);
        }
#endif
        break;

      case ITEM_SETUP_STICK_MODE:
        lcd_putcAtt(2*FW, y, '1'+g_eeGeneral.stickMode, attr);
        for (uint8_t i=0; i<4; i++) {
          putsStickName((6+4*i)*FW, y, pgm_read_byte(modn12x3 + 4*g_eeGeneral.stickMode + i), 0);
        }
        if (attr && s_editMode>0) {
          CHECK_INCDEC_GENVAR(event, g_eeGeneral.stickMode, 0, 3);
        }
        else if (stickMode != g_eeGeneral.stickMode) {
          pausePulses();
          stickMode = g_eeGeneral.stickMode;
          checkTHR();
          resumePulses();
          clearKeyEvents();
        }
        break;
    }
  }
}
Exemplo n.º 14
0
static THD_FUNCTION(ThreadGFXEvent, arg)
{
	(void)arg;

	chRegSetThreadName("GFXEvent");

	GEvent* pe;
	static RTCDateTime timespec;
	struct tm timeinfo;
	struct tm tim;
	struct tm *canary;
	static time_t unix_time;
	while (true) {
		pe = geventEventWait(&gl, TIME_INFINITE);
		switch (pe->type) {
			case GEVENT_GWIN_BUTTON:
				if (((GEventGWinButton*)pe)->gwin == ghBtnSettings) {
					createSettingsFrame();
					gwinShow(ghFrame1);
					updateGraph = false;
					updateSettingTime = true;
				} else if (((GEventGWinButton*)pe)->gwin == ghBtnSave) {
					timeinfo.tm_hour = atoi(gwinListGetSelectedText(ghListHour));
					timeinfo.tm_min = atoi(gwinListGetSelectedText(ghListMin));
					timeinfo.tm_sec = 0;
					timeinfo.tm_mday = atoi(gwinListGetSelectedText(ghListDay));
					timeinfo.tm_mon = gwinListGetSelected(ghListMonth);
					timeinfo.tm_year = atoi(gwinListGetSelectedText(ghListYear))-1900;
					unix_time = mktime(&timeinfo);
					canary = localtime_r(&unix_time, &tim);
					osalDbgCheck(&tim == canary);
					rtcConvertStructTmToDateTime(&tim, 0, &timespec);
					rtcSetTime(RTC_DRIVER, &timespec);
				} else if (((GEventGWinButton*)pe)->gwin == ghBtnTime) {
					updateGraph = false;
					gwinShow(ghListFreq);
				}
				break;

			case GEVENT_GWIN_CHECKBOX:
				if (((GEventGWinCheckbox*)pe)->gwin == ghCheckBoxHR) {
					if (((GEventGWinCheckbox*)pe)->isChecked)
						use12HR = true;
					else
						use12HR = false;
				}
				break;

			case GEVENT_GWIN_CLOSE:
				updateGraph = true;
				updateSettingTime = false;
				switch (activeGraph) {
					case 0:
						drawGraphLines(ghContainerGraphC);
						break;

					case 1:
						drawGraphLines(ghContainerGraphV);
						break;

					case 2:
						drawGraphLines(ghContainerGraphW);
						break;

					case 3:
						drawGraphLines(ghContainerGraphCV_1);
						drawGraphLines(ghContainerGraphCV_2);
						break;

					default:
						break;
				}
				break;

			case GEVENT_GWIN_RADIO:
				activeGraph = atoi(gwinGetText(((GEventGWinRadio *)pe)->gwin));
				setActiveGraph(activeGraph);
				break;

			case GEVENT_GWIN_LIST:
				if (((GEventGWinList*)pe)->gwin == ghListFreq)  {
					char str[5];
					uint8_t val = atoi(gwinListGetSelectedText(ghListFreq));
					GRAPH_Refresh = ((1.0/val)*1000);
					snprintf(str, 5, "%d%s", val, "Hz");
					gwinSetText(ghBtnTime, str, true);
					chThdSleepMilliseconds(10);
					gwinHide(ghListFreq);
					updateGraph = true;

					switch (activeGraph) {
					case 0:
						drawGraphLines(ghContainerGraphC);
						break;

					case 1:
						drawGraphLines(ghContainerGraphV);
						break;

					case 2:palSetPadMode(GPIOA, 5, PAL_MODE_OUTPUT_PUSHPULL); palClearPad(GPIOA, 5);
						drawGraphLines(ghContainerGraphW);
						break;

					case 3:
						drawGraphLines(ghContainerGraphCV_1);
						drawGraphLines(ghContainerGraphCV_2);
						break;

					default:
						break;
					}

				}

				break;
			default:
				break;
		}

		chThdSleepMilliseconds(500);
	}
}
Exemplo n.º 15
0
void menuGeneralSetup(uint8_t event)
{
#if defined(RTCLOCK)
  struct gtm t;
  gettime(&t);

  if ((m_posVert==ITEM_SETUP_DATE+1 || m_posVert==ITEM_SETUP_TIME+1) &&
      (s_editMode>0) &&
      (event==EVT_KEY_FIRST(KEY_ENTER) || event==EVT_KEY_FIRST(KEY_EXIT) || IS_ROTARY_BREAK(event) || IS_ROTARY_LONG(event))) {
    // set the date and time into RTC chip
    rtcSetTime(&t);
  }
#endif

#if defined(FAI_CHOICE)
  if (s_warning_result) {
    s_warning_result = 0;
    g_eeGeneral.fai = true;
    eeDirty(EE_GENERAL);
  }
#endif

  MENU(STR_MENURADIOSETUP, menuTabDiag, e_Setup, ITEM_SETUP_MAX+1, {0, IF_RTCLOCK(2) IF_RTCLOCK(2) IF_BATTGRAPH(1) LABEL(SOUND), IF_AUDIO(0) IF_BUZZER(0) IF_VOICE(0) IF_CPUARM(0) IF_CPUARM(0) IF_CPUARM(0) IF_CPUARM(0) 0, IF_AUDIO(0) IF_HAPTIC(LABEL(HAPTIC)) IF_HAPTIC(0) IF_HAPTIC(0) IF_HAPTIC(0) 0, LABEL(ALARMS), 0, IF_PCBSKY9X(0) IF_PCBSKY9X(0) 0, 0, 0, IF_ROTARY_ENCODERS(0) LABEL(BACKLIGHT), 0, 0, IF_CPUARM(0) CASE_PWM_BACKLIGHT(0) CASE_PWM_BACKLIGHT(0) 0, IF_SPLASH(0) IF_GPS(0) IF_GPS(0) IF_PXX(0) IF_CPUARM(0) IF_CPUARM(0) IF_FAI_CHOICE(0) 0, LABEL(TX_MODE), CASE_PCBTARANIS(0) 1/*to force edit mode*/});

  uint8_t sub = m_posVert - 1;

  for (uint8_t i=0; i<LCD_LINES-1; i++) {
    uint8_t y = 1 + 1*FH + i*FH;
    uint8_t k = i+s_pgOfs;
    uint8_t blink = ((s_editMode>0) ? BLINK|INVERS : INVERS);
    uint8_t attr = (sub == k ? blink : 0);

    switch(k) {
#if defined(RTCLOCK)
      case ITEM_SETUP_DATE:
        lcd_putsLeft(y, STR_DATE);
        lcd_putc(RADIO_SETUP_DATE_COLUMN, y, '-'); lcd_putc(RADIO_SETUP_DATE_COLUMN+3*FW-1, y, '-');
        for (uint8_t j=0; j<3; j++) {
          uint8_t rowattr = (m_posHorz==j ? attr : 0);
          switch (j) {
            case 0:
              lcd_outdezAtt(RADIO_SETUP_DATE_COLUMN, y, t.tm_year+1900, rowattr);
              if (rowattr && (s_editMode>0 || p1valdiff)) t.tm_year = checkIncDec(event, t.tm_year, 112, 200, 0);
              break;
            case 1:
              lcd_outdezNAtt(RADIO_SETUP_DATE_COLUMN+3*FW-1, y, t.tm_mon+1, rowattr|LEADING0, 2);
              if (rowattr && (s_editMode>0 || p1valdiff)) t.tm_mon = checkIncDec(event, t.tm_mon, 0, 11, 0);
              break;
            case 2:
            {
              int16_t year = 1900 + t.tm_year;
              int8_t dlim = (((((year%4==0) && (year%100!=0)) || (year%400==0)) && (t.tm_mon==1)) ? 1 : 0);
              static const pm_uint8_t dmon[] PROGMEM = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
              dlim += pgm_read_byte(&dmon[t.tm_mon]);
              lcd_outdezNAtt(RADIO_SETUP_DATE_COLUMN+6*FW-2, y, t.tm_mday, rowattr|LEADING0, 2);
              if (rowattr && (s_editMode>0 || p1valdiff)) t.tm_mday = checkIncDec(event, t.tm_mday, 1, dlim, 0);
              break;
            }
          }
        }
#if defined(PCBTARANIS)
        if (attr && m_posHorz < 0) lcd_filled_rect(RADIO_SETUP_2ND_COLUMN, y, LCD_W-RADIO_SETUP_2ND_COLUMN-MENUS_SCROLLBAR_WIDTH, 8);
#endif
        if (attr && checkIncDec_Ret)
          g_rtcTime = gmktime(&t); // update local timestamp and get wday calculated
        break;

      case ITEM_SETUP_TIME:
        lcd_putsLeft(y, STR_TIME);
        lcd_putc(RADIO_SETUP_TIME_COLUMN-1, y, ':'); lcd_putc(RADIO_SETUP_TIME_COLUMN+3*FW-4, y, ':');
        for (uint8_t j=0; j<3; j++) {
          uint8_t rowattr = (m_posHorz==j ? attr : 0);
          switch (j) {
            case 0:
              lcd_outdezNAtt(RADIO_SETUP_TIME_COLUMN, y, t.tm_hour, rowattr|LEADING0, 2);
              if (rowattr && (s_editMode>0 || p1valdiff)) t.tm_hour = checkIncDec(event, t.tm_hour, 0, 23, 0);
              break;
            case 1:
              lcd_outdezNAtt(RADIO_SETUP_TIME_COLUMN+3*FWNUM, y, t.tm_min, rowattr|LEADING0, 2);
              if (rowattr && (s_editMode>0 || p1valdiff)) t.tm_min = checkIncDec(event, t.tm_min, 0, 59, 0);
              break;
            case 2:
              lcd_outdezNAtt(RADIO_SETUP_TIME_COLUMN+6*FWNUM, y, t.tm_sec, rowattr|LEADING0, 2);
              if (rowattr && (s_editMode>0 || p1valdiff)) t.tm_sec = checkIncDec(event, t.tm_sec, 0, 59, 0);
              break;
          }
        }
#if defined(PCBTARANIS)
        if (attr && m_posHorz < 0) lcd_filled_rect(RADIO_SETUP_2ND_COLUMN, y, LCD_W-RADIO_SETUP_2ND_COLUMN-MENUS_SCROLLBAR_WIDTH, 8);
#endif
        if (attr && checkIncDec_Ret)
          g_rtcTime = gmktime(&t); // update local timestamp and get wday calculated
        break;
#endif

#if defined(BATTGRAPH) || defined(PCBTARANIS)
      case ITEM_SETUP_BATT_RANGE:
        lcd_putsLeft(y, STR_BATTERY_RANGE);
        lcd_putc(g_eeGeneral.vBatMin >= 10 ? RADIO_SETUP_2ND_COLUMN+2*FW+FWNUM-1 : RADIO_SETUP_2ND_COLUMN+2*FW+FWNUM-FW/2, y, '-');
        putsVolts(RADIO_SETUP_2ND_COLUMN, y,  90+g_eeGeneral.vBatMin, (m_posHorz==0 ? attr : 0)|LEFT|NO_UNIT);
        putsVolts(RADIO_SETUP_2ND_COLUMN+4*FW-2, y, 120+g_eeGeneral.vBatMax, (m_posHorz>0 ? attr : 0)|LEFT|NO_UNIT);
#if defined(PCBTARANIS)
        if (attr && m_posHorz < 0) lcd_filled_rect(RADIO_SETUP_2ND_COLUMN, y, LCD_W-RADIO_SETUP_2ND_COLUMN-MENUS_SCROLLBAR_WIDTH, 8);
#endif
        if (attr && s_editMode>0) {
          if (m_posHorz==0)
            CHECK_INCDEC_GENVAR(event, g_eeGeneral.vBatMin, -50, g_eeGeneral.vBatMax+29); // min=4.0V
          else
            CHECK_INCDEC_GENVAR(event, g_eeGeneral.vBatMax, g_eeGeneral.vBatMin-29, +40); // max=16.0V
        }
        break;
#endif

      case ITEM_SETUP_SOUND_LABEL:
        lcd_putsLeft(y, STR_SOUND_LABEL);
        break;

#if defined(AUDIO)
      case ITEM_SETUP_BEEP_MODE:
        g_eeGeneral.beepMode = selectMenuItem(RADIO_SETUP_2ND_COLUMN, y, STR_SPEAKER, STR_VBEEPMODE, g_eeGeneral.beepMode, -2, 1, attr, event);
#if defined(FRSKY)
        if (attr && checkIncDec_Ret) frskySendAlarms();
#endif
        break;

#if defined(BUZZER)
      case ITEM_SETUP_BUZZER_MODE:
        g_eeGeneral.buzzerMode = selectMenuItem(RADIO_SETUP_2ND_COLUMN, y, STR_BUZZER, STR_VBEEPMODE, g_eeGeneral.buzzerMode, -2, 1, attr, event);
#if defined(FRSKY)
        if (attr && checkIncDec_Ret) frskySendAlarms();
#endif
        break;
#endif
#else
      case ITEM_SETUP_BUZZER_MODE:
        g_eeGeneral.beepMode = selectMenuItem(RADIO_SETUP_2ND_COLUMN, y, STR_SPEAKER, STR_VBEEPMODE, g_eeGeneral.beepMode, -2, 1, attr, event);
#if defined(FRSKY)
        if (attr && checkIncDec_Ret) frskySendAlarms();
#endif
        break;
#endif

#if defined(VOICE)
      case ITEM_SETUP_SPEAKER_VOLUME:
      {
        lcd_putsLeft(y, STR_SPEAKER_VOLUME);
        uint8_t b = g_eeGeneral.speakerVolume+VOLUME_LEVEL_DEF;
        displaySlider(RADIO_SETUP_2ND_COLUMN, y, b, VOLUME_LEVEL_MAX, attr);
        if (attr) {
          CHECK_INCDEC_GENVAR(event, b, 0, VOLUME_LEVEL_MAX);
          if (checkIncDec_Ret) {
            g_eeGeneral.speakerVolume = (int8_t)b-VOLUME_LEVEL_DEF;
#if !defined(CPUARM)
            setVolume(b);
#endif
          }
        }
        break;
      }
#endif

#if defined(CPUARM)
      case ITEM_SETUP_BEEP_VOLUME:
        SLIDER_5POS(y, g_eeGeneral.beepVolume, STR_BEEP_VOLUME, event, attr);
        break;
      case ITEM_SETUP_WAV_VOLUME:
        SLIDER_5POS(y, g_eeGeneral.wavVolume, STR_WAV_VOLUME, event, attr);
        break;
      case ITEM_SETUP_VARIO_VOLUME:
        SLIDER_5POS(y, g_eeGeneral.varioVolume, STR_VARIO_VOLUME, event, attr);
        break;
      case ITEM_SETUP_BACKGROUND_VOLUME:
        SLIDER_5POS(y, g_eeGeneral.backgroundVolume, STR_BG_VOLUME, event, attr);
        break;
#endif

      case ITEM_SETUP_BEEP_LENGTH:
        SLIDER_5POS(y, g_eeGeneral.beepLength, STR_LENGTH, event, attr);
        break;

#if defined(AUDIO)
      case ITEM_SETUP_SPEAKER_PITCH:
        lcd_putsLeft( y, STR_SPKRPITCH);
        lcd_outdezAtt(RADIO_SETUP_2ND_COLUMN, y, g_eeGeneral.speakerPitch, attr|LEFT);
        if (attr) {
          CHECK_INCDEC_GENVAR(event, g_eeGeneral.speakerPitch, 0, 20);
        }
        break;
#endif

#if defined(HAPTIC)
      case ITEM_SETUP_HAPTIC_LABEL:
        lcd_putsLeft(y, STR_HAPTIC_LABEL);
        break;

      case ITEM_SETUP_HAPTIC_MODE:
        g_eeGeneral.hapticMode = selectMenuItem(RADIO_SETUP_2ND_COLUMN, y, STR_MODE, STR_VBEEPMODE, g_eeGeneral.hapticMode, -2, 1, attr, event);
        break;

      case ITEM_SETUP_HAPTIC_LENGTH:
        SLIDER_5POS(y, g_eeGeneral.hapticLength, STR_LENGTH, event, attr);
        break;

      case ITEM_SETUP_HAPTIC_STRENGTH:
        lcd_putsLeft( y, STR_HAPTICSTRENGTH);
        lcd_outdezAtt(RADIO_SETUP_2ND_COLUMN, y, g_eeGeneral.hapticStrength, attr|LEFT);
        if (attr) {
          CHECK_INCDEC_GENVAR(event, g_eeGeneral.hapticStrength, 0, 5);
        }
        break;
#endif

      case ITEM_SETUP_CONTRAST:
        lcd_putsLeft(y, STR_CONTRAST);
        lcd_outdezAtt(RADIO_SETUP_2ND_COLUMN, y, g_eeGeneral.contrast, attr|LEFT);
        if(attr) {
#if defined(PCBTARANIS)
          CHECK_INCDEC_GENVAR(event, g_eeGeneral.contrast, 0, 45);
#else
          CHECK_INCDEC_GENVAR(event, g_eeGeneral.contrast, 10, 45);
#endif          
          lcdSetContrast();
        }
        break;

      case ITEM_SETUP_ALARMS_LABEL:
        lcd_putsLeft(y, STR_ALARMS_LABEL);
        break;

      case ITEM_SETUP_BATTERY_WARNING:
        lcd_putsLeft(y, STR_BATTERYWARNING);
        putsVolts(RADIO_SETUP_2ND_COLUMN, y, g_eeGeneral.vBatWarn, attr|LEFT);
        if(attr) CHECK_INCDEC_GENVAR(event, g_eeGeneral.vBatWarn, 40, 120); //4-12V
        break;

      case ITEM_SETUP_MEMORY_WARNING:
      {
        uint8_t b = 1-g_eeGeneral.disableMemoryWarning;
        g_eeGeneral.disableMemoryWarning = 1 - onoffMenuItem(b, RADIO_SETUP_2ND_COLUMN, y, STR_MEMORYWARNING, attr, event);
        break;
      }

      case ITEM_SETUP_ALARM_WARNING:
      {
        uint8_t b = 1-g_eeGeneral.disableAlarmWarning;
        g_eeGeneral.disableAlarmWarning = 1 - onoffMenuItem(b, RADIO_SETUP_2ND_COLUMN, y, STR_ALARMWARNING, attr, event);
        break;
      }

#if defined(PCBSKY9X)
      case ITEM_SETUP_CAPACITY_WARNING:
        lcd_putsLeft(y, STR_CAPAWARNING);
        putsTelemetryValue(RADIO_SETUP_2ND_COLUMN, y, g_eeGeneral.mAhWarn*50, UNIT_MAH, attr|LEFT) ;
        if(attr) CHECK_INCDEC_GENVAR(event, g_eeGeneral.mAhWarn, 0, 100);
        break;
#endif

#if defined(PCBSKY9X)
      case ITEM_SETUP_TEMPERATURE_WARNING:
        lcd_putsLeft(y, STR_TEMPWARNING);
        putsTelemetryValue(RADIO_SETUP_2ND_COLUMN, y, g_eeGeneral.temperatureWarn, UNIT_DEGREES, attr|LEFT) ;
        if(attr) CHECK_INCDEC_GENVAR(event, g_eeGeneral.temperatureWarn, 0, 120); // 0 means no alarm
        break;
#endif

      case ITEM_SETUP_INACTIVITY_ALARM:
        lcd_putsLeft( y,STR_INACTIVITYALARM);
        lcd_outdezAtt(RADIO_SETUP_2ND_COLUMN, y, g_eeGeneral.inactivityTimer, attr|LEFT);
        lcd_putc(lcdLastPos, y, 'm');
        if(attr) g_eeGeneral.inactivityTimer = checkIncDec(event, g_eeGeneral.inactivityTimer, 0, 250, EE_GENERAL); //0..250minutes
        break;

#if ROTARY_ENCODERS > 0
      case ITEM_SETUP_RE_NAVIGATION:
        g_eeGeneral.reNavigation = selectMenuItem(RADIO_SETUP_2ND_COLUMN, y, STR_RENAVIG, STR_VRENAVIG, g_eeGeneral.reNavigation, 0, NUM_ROTARY_ENCODERS, attr, event);
        if (attr && checkIncDec_Ret) {
          g_rotenc[NAVIGATION_RE_IDX()] = 0;
        }
        break;
#endif

      case ITEM_SETUP_BACKLIGHT_LABEL:
        lcd_putsLeft(y, STR_BACKLIGHT_LABEL);
        break;

      case ITEM_SETUP_BACKLIGHT_MODE:
        g_eeGeneral.backlightMode = selectMenuItem(RADIO_SETUP_2ND_COLUMN, y, STR_MODE, STR_VBLMODE, g_eeGeneral.backlightMode, e_backlight_mode_off, e_backlight_mode_on, attr, event);
        break;

      case ITEM_SETUP_FLASH_BEEP:
        g_eeGeneral.alarmsFlash = onoffMenuItem(g_eeGeneral.alarmsFlash, RADIO_SETUP_2ND_COLUMN, y, STR_ALARM, attr, event ) ;
        break;

      case ITEM_SETUP_BACKLIGHT_DELAY:
        lcd_putsLeft(y, STR_BLDELAY);
        lcd_outdezAtt(RADIO_SETUP_2ND_COLUMN, y, g_eeGeneral.lightAutoOff*5, attr|LEFT);
        lcd_putc(lcdLastPos, y, 's');
        if (attr) CHECK_INCDEC_GENVAR(event, g_eeGeneral.lightAutoOff, 0, 600/5);
        break;

#if defined(CPUARM)
      case ITEM_SETUP_BRIGHTNESS:
        lcd_putsLeft(y, STR_BRIGHTNESS);
        lcd_outdezAtt(RADIO_SETUP_2ND_COLUMN, y, 100-g_eeGeneral.backlightBright, attr|LEFT) ;
        if(attr) {
          uint8_t b = 100 - g_eeGeneral.backlightBright;
          CHECK_INCDEC_GENVAR(event, b, 0, 100);
          g_eeGeneral.backlightBright = 100 - b;
        }
        break;
#endif

#if defined(PWM_BACKLIGHT)
      case ITEM_SETUP_BACKLIGHT_BRIGHTNESS_OFF:
        lcd_putsLeft(y, STR_BLOFFBRIGHTNESS);
        lcd_outdezAtt(RADIO_SETUP_2ND_COLUMN, y, g_eeGeneral.blOffBright, attr|LEFT);
        if (attr) CHECK_INCDEC_GENVAR(event, g_eeGeneral.blOffBright, 0, 15);
        break;

      case ITEM_SETUP_BACKLIGHT_BRIGHTNESS_ON:
        lcd_putsLeft(y, STR_BLONBRIGHTNESS);
        lcd_outdezAtt(RADIO_SETUP_2ND_COLUMN, y, 15-g_eeGeneral.blOnBright, attr|LEFT);
        if (attr) g_eeGeneral.blOnBright = 15 - checkIncDecGen(event, 15-g_eeGeneral.blOnBright, 0, 15);
        break;
#endif

#if defined(SPLASH) && !defined(FSPLASH)
      case ITEM_SETUP_DISABLE_SPLASH:
      {
        uint8_t b = 1-g_eeGeneral.splashMode;
        g_eeGeneral.splashMode = 1 - onoffMenuItem(b, RADIO_SETUP_2ND_COLUMN, y, STR_SPLASHSCREEN, attr, event);
        break;
      }
#endif

#if defined(FRSKY) && defined(FRSKY_HUB) && defined(GPS)
      case ITEM_SETUP_TIMEZONE:
        lcd_putsLeft(y, STR_TIMEZONE);
        lcd_outdezAtt(RADIO_SETUP_2ND_COLUMN, y, g_eeGeneral.timezone, attr|LEFT);
        if (attr) CHECK_INCDEC_GENVAR(event, g_eeGeneral.timezone, -12, 12);
        break;

      case ITEM_SETUP_GPSFORMAT:
        g_eeGeneral.gpsFormat = selectMenuItem(RADIO_SETUP_2ND_COLUMN, y, STR_GPSCOORD, STR_GPSFORMAT, g_eeGeneral.gpsFormat, 0, 1, attr, event);
        break;
#endif

#if defined(PXX)
      case ITEM_SETUP_COUNTRYCODE:
        g_eeGeneral.countryCode = selectMenuItem(RADIO_SETUP_2ND_COLUMN, y, STR_COUNTRYCODE, STR_COUNTRYCODES, g_eeGeneral.countryCode, 0, 2, attr, event);
        break;
#endif

#if defined(CPUARM)
      case ITEM_SETUP_LANGUAGE:
        lcd_putsLeft(y, STR_VOICELANG);
        lcd_putsAtt(RADIO_SETUP_2ND_COLUMN, y, currentLanguagePack->name, attr);
        if (attr) {
          currentLanguagePackIdx = checkIncDec(event, currentLanguagePackIdx, 0, DIM(languagePacks)-2, EE_GENERAL);
          if (checkIncDec_Ret) {
            currentLanguagePack = languagePacks[currentLanguagePackIdx];
            strncpy(g_eeGeneral.ttsLanguage, currentLanguagePack->id, 2);
          }
        }
        break;

      case ITEM_SETUP_IMPERIAL:
        g_eeGeneral.imperial = selectMenuItem(RADIO_SETUP_2ND_COLUMN, y, STR_UNITSSYSTEM, STR_VUNITSSYSTEM, g_eeGeneral.imperial, 0, 1, attr, event);
        break;
#endif

#if defined(FAI_CHOICE)
      case ITEM_SETUP_FAI:
        onoffMenuItem(g_eeGeneral.fai, RADIO_SETUP_2ND_COLUMN, y, PSTR("FAI Mode"), attr, event);
        if (attr && checkIncDec_Ret) {
          if (g_eeGeneral.fai)
            POPUP_WARNING(PSTR("FAI\001mode blocked!"));
          else
            POPUP_CONFIRMATION(PSTR("FAI mode?"));
        }
        break;
#endif

#if defined(MAVLINK)
		case ITEM_MAVLINK_BAUD:
			g_eeGeneral.mavbaud = selectMenuItem(RADIO_SETUP_2ND_COLUMN,  //Y
				y, 					// Y
				STR_MAVLINK_BAUD_LABEL, 			// pm_char *label
				STR_MAVLINK_BAUDS, 		// pm_char *values
//				PSTR("4800""9600""14400""19200""38400""57600""76800""115200"),
				g_eeGeneral.mavbaud, 	// value
				0, 	// min
				7, 	// max
				attr,  // attr
				event);	// event
			break;
#endif

      case ITEM_SETUP_RX_CHANNEL_ORD:
        lcd_putsLeft(y, STR_RXCHANNELORD); // RAET->AETR
        for (uint8_t i=1; i<=4; i++)
          putsChnLetter(RADIO_SETUP_2ND_COLUMN - FW + i*FW, y, channel_order(i), attr);
        if (attr) CHECK_INCDEC_GENVAR(event, g_eeGeneral.templateSetup, 0, 23);
        break;

      case ITEM_SETUP_STICK_MODE_LABELS:
        lcd_putsLeft(y, NO_INDENT(STR_MODE));
        for (uint8_t i=0; i<4; i++) lcd_img((6+4*i)*FW, y, sticks, i, 0);
        break;

      case ITEM_SETUP_STICK_MODE:
        lcd_putcAtt(2*FW, y, '1'+g_eeGeneral.stickMode, attr);
        for (uint8_t i=0; i<4; i++) putsMixerSource((6+4*i)*FW, y, pgm_read_byte(modn12x3 + 4*g_eeGeneral.stickMode + i), 0);
        if (attr && s_editMode>0) {
          CHECK_INCDEC_GENVAR(event, g_eeGeneral.stickMode, 0, 3);
        }
        else if (stickMode != g_eeGeneral.stickMode) {
          pausePulses();
          stickMode = g_eeGeneral.stickMode;
          checkTHR();
          resumePulses();
          clearKeyEvents();
        }
#if defined(ROTARY_ENCODER_NAVIGATION)
        MOVE_CURSOR_FROM_HERE();
#endif
        break;
    }
  }
}