view Discovery/Src/tDebug.c @ 471:73da921869d9 fix-bat-2

bugfix: implement battery charge percentage in dive header This commit is (much) less trivial than the related 919e5cb51c92. First, rename the CCRmode attribute (corresponding to byte Ox59) of the SLogbookHeaderOSTC3. This byte (according to the hwOS interface document) does not contain any CCR related value, but it contains "battery information". Already since 2017, this byte is used from libdivecomputer to interface the charge percentage. So, its renamed from CCRmode to batteryCharge, to reflect its true purpose. Now, simply add a batteryCharge attribute to the SLogbookHeader (and see below why that is possible, without breaking things). The remaining changes are trivial to implement battery charge percentage in dive header. Caveat: do not get confused by the exact role of the individual logbook header types. SLogbookHeaderOSTC3 is the formal type of the logbook format that the OSTC4 produces. This format is supposed to identical to the format, as is used in hwOS for the series of small OSTCs. Only some values of attributes are different. For example, the OSTC4 supports VPM, so byte 0x79 (deco model used for this dive) also has a value for VPM. But the SLogbookHeader type, despite its name and structure, is *not* a true logbook header, as it includes attributes that are not available in the SLogbookHeaderOSTC3 formal header type. Signed-off-by: Jan Mulder <jan@jlmulder.nl>
author Jan Mulder <jlmulder@xs4all.nl>
date Wed, 22 Apr 2020 13:08:57 +0200
parents 717f335cc5c9
children
line wrap: on
line source

///////////////////////////////////////////////////////////////////////////////
/// -*- coding: UTF-8 -*-
///
/// \file   Discovery/Src/tDebug.c
/// \brief  Screen with Terminal Out
/// \author heinrichs weikamp gmbh
/// \date   06-April-2016
///
/// \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 "tDebug.h"

#include "data_exchange_main.h"
#include "gfx_engine.h"
#include "gfx_fonts.h"
#include "ostc.h"
#include "tInfo.h"
#include "tComm.h"

#include "stm32f4xx_hal.h"

#include <string.h>

uint8_t tD_selection_page = 1;
uint8_t tD_debugModeActive = 0;
uint8_t tD_status = 0;

char tD_communication[6][40];

void tDebug_Action(void);
void tDebug_NextPage(void);


void setDebugMode(void)
{
    tD_debugModeActive = 1;
}


void exitDebugMode(void)
{
    MX_Bluetooth_PowerOff();
    settingsGetPointer()->debugModeOnStart = 0;
    tD_debugModeActive = 0;
}


uint8_t inDebugMode(void)
{
    return tD_debugModeActive;
/*
    if(settingsGetPointer()->showDebugInfo == 2)
        return 1;
    else
        return 0;
*/
}


void tDebug_start(void)
{
    MX_Bluetooth_PowerOn();
    tComm_StartBlueModConfig();

    tD_debugModeActive = 1;
    tD_status = 0;
    for(int i=0;i<6;i++)
        tD_communication[i][0] = 0;

    set_globalState(StIDEBUG);
}


void tDebugControl(uint8_t sendAction)
{
    switch(sendAction)
    {
    case ACTION_BUTTON_ENTER:
            tDebug_Action();
        break;
    case ACTION_BUTTON_NEXT:
            tDebug_NextPage();
        break;
    case ACTION_TIMEOUT:
    case ACTION_MODE_CHANGE:
    case ACTION_BUTTON_BACK:
    exitInfo();
    	break;
    default:
        break;
    case ACTION_IDLE_TICK:
    case ACTION_IDLE_SECOND:
        break;
    }
}


void tDebug_refresh(void)
{
    uint8_t color;
    char text[50];

    tInfo_write_content_simple( 700,780,  20, &FontT24, "\0021/1", CLUT_NiceGreen);

    tInfo_write_content_simple(  20,780,  20, &FontT24, "Debug Terminal", CLUT_NiceGreen);
/*
    snprintf(text,50,"X: %i  Y: %i  Z: %i  %03.0f  %03.0f"
                                    ,stateUsed->lifeData.compass_DX_f
                                    ,stateUsed->lifeData.compass_DY_f
                                    ,stateUsed->lifeData.compass_DZ_f
                                    ,stateUsed->lifeData.compass_roll
                                    ,stateUsed->lifeData.compass_pitch
    );
*/
    snprintf(text,50,"roll  %.0f  pitch  %.0f"
                                    ,stateUsed->lifeData.compass_roll
                                    ,stateUsed->lifeData.compass_pitch
    );

    tInfo_write_content_simple(  20,780,  60, &FontT24, text, CLUT_NiceGreen);

    for(int i=0;i<6;i++)
    {
        if(i%2)
            color = CLUT_WarningRed;
        else
            color = CLUT_WarningYellow;
        tInfo_write_content_simple(  20,780, (60*i)+100, &FontT42, tD_communication[i], color);
    }
}


void tDebug_NextPage(void)
{

}


void tDebug_helper_replaceCRLF(char *text, uint8_t maxlength)
{
    for(int i=0; i<maxlength; i++)
    {
        if(text[i] == 0)
            break;
        if((text[i] == '\r') || (text[i] == '\n'))
            text[i] = ' ';
    }
}


void tDebug_Action(void)
{
    char aRxBuffer[50];

    char aTxBufferEscapeSequence[4] = "+++";
    char aTxBufferName[22] = "AT+BNAME=OSTC4-12345\r";
    char aTxBufferWrite[6] = "AT&W\r";
    gfx_number_to_string(5,1,&aTxBufferName[15],hardwareDataGetPointer()->primarySerial);

    tD_status++;

    switch(tD_status)
    {
    case 1:
        if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBufferEscapeSequence, 3, 2000) == HAL_OK)
        {
            strcpy(tD_communication[0],aTxBufferEscapeSequence);
        }
        else
        {
            strcpy(tD_communication[0],"Error.");
        }

        if(HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, 3, 2000) == HAL_OK)
        {
            aRxBuffer[3] = 0;
            tDebug_helper_replaceCRLF(aRxBuffer, 3);
            strcpy(tD_communication[1],aRxBuffer);
        }
        else
        {
            strcpy(tD_communication[1],"Error.");
        }
        break;

    case 2:
        if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBufferName, 21, 2000) == HAL_OK)
        {
            strcpy(tD_communication[2],aTxBufferName);
        }
        else
        {
            strcpy(tD_communication[2],"Error.");
        }

        if(HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, 21+6, 2000) == HAL_OK)
        {
            aRxBuffer[21+6] = 0;
            tDebug_helper_replaceCRLF(aRxBuffer, 21+6);
            strcpy(tD_communication[3],aRxBuffer);
        }
        else
        {
            strcpy(tD_communication[3],"Error.");
        }
        break;

    case 3:
        if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBufferWrite, 5, 2000) == HAL_OK)
        {
            strcpy(tD_communication[4],aTxBufferWrite);
        }
        else
        {
            strcpy(tD_communication[4],"Error.");
        }

        if(HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, 5+6, 2000) == HAL_OK)
        {
            aRxBuffer[5+6] = 0;
            tDebug_helper_replaceCRLF(aRxBuffer, 5+6);
            strcpy(tD_communication[5],aRxBuffer);
        }
        else
        {
            strcpy(tD_communication[5],"Error.");
        }
        break;

    default:
        tD_status = 0;
        break;
    }
}



/************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/