view Discovery/Src/tInfoSensor.c @ 1082:1aa45000f92c Icon_Integration tip

Added configuration menu for HUD functions: The V1 HUD has 4 functions (holes) which may be realized by one or two LEDs. The functions (like ppo2 monitoring or ascent speed) may be configurated by the diver using the HUD menu. The functions which may be selected depend on the HW configuration (e.g. the connected sensors) and the number of LEDs which are needed to realize the function. The previous HUD test implementation may still be activate usind the compile switch ENABLE_HUD_TESTING
author Ideenmodellierer
date Sun, 15 Mar 2026 21:40:35 +0100
parents 082825daccb5
children
line wrap: on
line source

///////////////////////////////////////////////////////////////////////////////
/// -*- coding: UTF-8 -*-
///
/// \file   Discovery/Src/tInfoCompass.c
/// \brief  there is only compass_DX_f, compass_DY_f, compass_DZ_f output during this mode
/// \author heinrichs weikamp gmbh
/// \date   23-Feb-2015
///
/// \details
///
/// $Id$
///////////////////////////////////////////////////////////////////////////////
/// \par Copyright (c) 2014-2018 Heinrichs Weikamp gmbh
///
///     This program is free software: you can redistribute it and/or modify
///     it under the terms of the GNU General Public License as published by
///     the Free Software Foundation, either version 3 of the License, or
///     (at your option) any later version.
///
///     This program 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 General Public License for more details.
///
///     You should have received a copy of the GNU General Public License
///     along with this program.  If not, see <http://www.gnu.org/licenses/>.
//////////////////////////////////////////////////////////////////////////////

/* Includes ------------------------------------------------------------------*/

#include "gfx_engine.h"
#include "gfx_fonts.h"
#include "tHome.h"
#include "tInfo.h"
#include "tInfoSensor.h"
#include "tMenuEdit.h"
#include "data_exchange_main.h"
#include "hud.h"

#include <string.h>
#include <inttypes.h>

extern void openEdit_Sensors(uint8_t filter);

/* Private variables ---------------------------------------------------------*/
static uint8_t	activeSensorId = 0;
static uint8_t sensorActive = 0;
static externalInterfaceSensorType sensorType = SENSOR_NONE;
/* Exported functions --------------------------------------------------------*/
void openInfo_Sensor(uint8_t sensorId)
{
	SSettings *pSettings = settingsGetPointer();
	activeSensorId = sensorId;
    set_globalState(StISENINFO);
    switch (activeSensorId)
    {
    	case 2: setBackMenu((uint32_t)openEdit_Sensors,SENSOR_END,3);
    		break;
    	case 1: setBackMenu((uint32_t)openEdit_Sensors,SENSOR_END,2);
    	    		break;
    	default:
    	case 0: setBackMenu((uint32_t)openEdit_Sensors,SENSOR_END,1);
    	    		break;
    }
    sensorActive = 1;
    switch(sensorType)	/* type has to be set using the set function before info dialog is used */
    {
    	case SENSOR_CO2:
    	case SENSOR_CO2M:	sensorActive = pSettings->co2_sensor_active;
    		break;
    	case SENSOR_DIGO2:	DataEX_setExtInterface_Cmd(EXT_INTERFACE_O2_INDICATE, activeSensorId);
    		/*no break*/
    	default:			if(pSettings->ppo2sensors_deactivated & (1 << (activeSensorId)))
    						{
    							sensorActive = 0;
    						}
    		break;
    }


}

void openInfo_SetSensorType(externalInterfaceSensorType Type)
{
	sensorType = Type;
}

uint64_t mod64(uint64_t a, uint64_t b)
{
   uint64_t div;
   div=(a/10);
   b=(10*div);
   return (a-b);
}

void uint64ToString(uint64_t value, char* pbuf)
{
	char tmpBuf[32];
	uint8_t index = 31;

	tmpBuf[index--] = 0;	/* zero termination */
	while((index != 0)  && (value != 0))
	{
		tmpBuf[index--] = '0' + (value % 10);// mod64(worker64,10);
		value /= 10;
	}
	strcpy(pbuf,&tmpBuf[index+1]);
}


static void refreshInfo_SensorO2(GFX_DrawCfgScreen s)
{
	const SDiveState *pStateReal = stateRealGetPointer();
    SSensorDataDiveO2* pDiveO2Data;
    char text[31];
    uint8_t strIndex = 0;
    char *textPointer = text;

    float pressure = 0.0;

    pDiveO2Data = (SSensorDataDiveO2*)pStateReal->lifeData.extIf_sensor_data[activeSensorId];
	strIndex = snprintf(text,32,"ID: ");
	if(pDiveO2Data->sensorId != 0)
	{
		uint64ToString(pDiveO2Data->sensorId,&text[strIndex]);
	}
	tInfo_write_content_simple(  30, 770, ME_Y_LINE1, &FontT48, text, CLUT_Font020);
	snprintf(text,32,"%c: %02.1f",TXT_Temperature , (float)pDiveO2Data->temperature / 1000.0);
	tInfo_write_content_simple(  30, 770, ME_Y_LINE2, &FontT48, text, CLUT_Font020);

#ifdef ENABLE_EXTERNAL_PRESSURE
	pressure = (float)(stateRealGetPointer()->lifeData.ppO2Sensor_bar[2]);
#else
	pressure = (float)pDiveO2Data->pressure / 1000.0;
#endif
	snprintf(text,32,"Druck: %02.1f (%02.1f)", (float)pDiveO2Data->pressure / 1000.0, pressure *1000.0);

	tInfo_write_content_simple(  30, 770, ME_Y_LINE3, &FontT48, text, CLUT_Font020);
	snprintf(text,32,"Feuchtigkeit: %02.1f", (float)pDiveO2Data->humidity / 1000.0);
	tInfo_write_content_simple(  30, 770, ME_Y_LINE4, &FontT48, text, CLUT_Font020);
	snprintf(text,32,"Status: 0x%lx", pDiveO2Data->status);
	tInfo_write_content_simple(  30, 770, ME_Y_LINE5, &FontT48, text, CLUT_Font020);
#ifdef ENABLE_EXTERNAL_PRESSURE
	snprintf(text,32,"Norm ppO2: %02.3f (%02.1f)", (float)(stateRealGetPointer()->lifeData.ppO2Sensor_bar[0] / (pressure / 1000.0)),(float)(stateRealGetPointer()->lifeData.ppO2Sensor_bar[0]));
	tInfo_write_content_simple(  30, 770, ME_Y_LINE6, &FontT48, text, CLUT_Font020);
#endif

	if(sensorActive)
	{
		*textPointer++ = '\005';
	}
	else
	{
		*textPointer++ = '\006';
	}
	*textPointer++ = ' ';
	*textPointer++ = TXT_2BYTE;
	*textPointer++ = TXT2BYTE_Sensor;
	*textPointer++ = ' ';
	*textPointer++ = TXT_2BYTE;
	*textPointer++ = TXT2BYTE_O2IFDigital;
	*textPointer++ = '1' + activeSensorId;

	snprintf(textPointer, 20,": %01.2f, %01.1f mV",  pStateReal->lifeData.ppO2Sensor_bar[activeSensorId], pStateReal->lifeData.sensorVoltage_mV[activeSensorId]);

	tInfo_write_content_simple(  30, 770, ME_Y_LINE6, &FontT48, text, CLUT_Font020);

	tInfo_write_buttonTextline_simple(TXT2BYTE_ButtonBack,TXT2BYTE_ButtonEnter,0);
}

static void refreshInfo_SensorCo2(GFX_DrawCfgScreen s)
{
	const SDiveState *pStateReal = stateRealGetPointer();
    char text[31];
    char *textPointer = text;

    snprintf(text,32,"CO2: %ld ppm",pStateReal->lifeData.CO2_data.CO2_ppm);
    tInfo_write_content_simple(  30, 770, ME_Y_LINE1, &FontT48, text, CLUT_Font020);


    snprintf(text,32,"Signal: %d",pStateReal->lifeData.CO2_data.signalStrength);
    tInfo_write_content_simple(  30, 770, ME_Y_LINE2, &FontT48, text, CLUT_Font020);

	if(sensorActive)
	{
		*textPointer++ = '\005';
	}
	else
	{
		*textPointer++ = '\006';
	}
	*textPointer++ = ' ';
	*textPointer++ = TXT_2BYTE;
	*textPointer++ = TXT2BYTE_Sensor;
	*textPointer++ = ' ';
	*textPointer++ = 'C';
	*textPointer++ = 'o';
	*textPointer++ = '1' + activeSensorId;

	snprintf(textPointer, 20,": %ld ppm",  pStateReal->lifeData.CO2_data.CO2_ppm);

	tInfo_write_content_simple(  30, 770, ME_Y_LINE6, &FontT48, text, CLUT_Font020);

	tInfo_write_buttonTextline_simple(TXT2BYTE_ButtonBack,TXT2BYTE_ButtonEnter,TXT2BYTE_O2Calib);
}

static void refreshInfo_SensorHUD(GFX_DrawCfgScreen s)
{
	const SDiveState *pStateReal = stateRealGetPointer();
    char text[50];
    char infostr[HUD_INFO_INFOSTR_LENGTH + 1];

    uint8_t hudAddress = hud_GetAddress();

    if(hudAddress < EXT_INTERFACE_SENSOR_CNT)
    {
		memcpy(infostr, (char*)&pStateReal->lifeData.extIf_sensor_data[hudAddress][HUD_INFO_INFOSTR_OFFSET], HUD_INFO_INFOSTR_LENGTH);
		infostr[HUD_INFO_INFOSTR_LENGTH] = 0;

		snprintf(text,50,"%s",infostr);
		tInfo_write_content_simple(  30, 770, ME_Y_LINE1, &FontT48, text, CLUT_Font020);
    }
	tInfo_write_buttonTextline_simple(TXT2BYTE_ButtonBack,TXT2BYTE_ButtonEnter,0);
}



//  ===============================================================================
void refreshInfo_Sensor(GFX_DrawCfgScreen s)
{
    char text[31];

    text[0] = '\001';
	text[1] = TXT_Sensor;
	text[2] = ' ';
	text[3] = TXT_Information;
	text[4] = ' ';
	text[5] = '1' + activeSensorId;
	text[6] = 0;
	tInfo_write_content_simple(  30, 770, ME_Y_LINE_BASE, &FontT48, text, CLUT_MenuPageHardware);

	switch(sensorType)
	{
		default:
		case SENSOR_DIGO2M:	refreshInfo_SensorO2(s);
			break;
		case SENSOR_CO2:
		case SENSOR_CO2M: 	refreshInfo_SensorCo2(s);
			break;
		case SENSOR_HUD:	refreshInfo_SensorHUD(s);
			break;
	}
}

void sendActionToInfoSensor(uint8_t sendAction)
{
	SSettings *pSettings = settingsGetPointer();

    switch(sendAction)
    {
    	case ACTION_BUTTON_BACK:
    		exitMenuEdit_to_BackMenu();
    			break;

    	case ACTION_BUTTON_ENTER: 	switch(sensorType)
									{
										 case SENSOR_CO2:
										 case SENSOR_CO2M:   if(pSettings->co2_sensor_active)
															 {
																 pSettings->co2_sensor_active = 0;
																 sensorActive = 0;
															 }
															 else
															 {
																 pSettings->co2_sensor_active = 1;
																 sensorActive = 1;
															 }
												 break;
										 default:			if(pSettings->ppo2sensors_deactivated & (1 << (activeSensorId)))
															{
																 pSettings->ppo2sensors_deactivated &= ~(1 << (activeSensorId));
																 sensorActive = 1;
															}
															else
															{
																pSettings->ppo2sensors_deactivated |= (1 << (activeSensorId));
																sensorActive = 0;
															}
											 break;
									}
    		break;
		case ACTION_BUTTON_NEXT:		if((sensorType == SENSOR_CO2M) || (sensorType == SENSOR_CO2))
										{
											DataEX_setExtInterface_Cmd(EXT_INTERFACE_CO2_CALIB, activeSensorId);
										}
			break;
		case ACTION_TIMEOUT:
		case ACTION_MODE_CHANGE:
	    case ACTION_IDLE_TICK:
	    case ACTION_IDLE_SECOND:
		default:
	        break;
    }
}