Honda Insight Forum banner
41 - 44 of 44 Posts

Engine-Off-Coast
Joined
2,319 Posts
Where I've gotten now is I can control text elements like the version info, but I still can't change the value of other elements.

There's another way the data can be formatted using bytes instead of the strings seen here. I'll look into that next and see if that lets me update bar graphs and numbers.



Code:
//Copyright 2021-2022(c) John Sullivan
//github.com/doppelhub/Honda_Insight_LiBCM

//LiDisplay (HMI) Serial Functions

#include "libcm.h"

bool versionAlreadyDisplayed = false;
uint8_t LiDisplayElementToUpdate = 0;
const String typeMap[3] = {
    "j", "n", "t"
};
const String attrMap[2] = {
    "txt", "val"
};
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void LiDisplay_begin(void)
{
    #ifdef LIDISPLAY_CONNECTED
         Serial.print(F("\nLiDisplay BEGIN"));
        Serial1.begin(9600,SERIAL_8E1);

        LiDisplayElementToUpdate = 0;

/*  Serial1.print("page0.j0.val=" + String('"') + String(SoC_getBatteryStateNow_percent()) + String('"'));
  Serial1.write(0xFF);
  Serial1.write(0xFF);
  Serial1.write(0xFF); */

  //LiDisplay_writeByte(SoC_getBatteryStateNow_percent());
    #endif
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void LiDisplay_updateElement(uint8_t page, uint8_t elementTypeIndex, uint8_t elementId, uint8_t elementAttrIndex, String value) {
    #ifdef LIDISPLAY_CONNECTED
        static String LiDisplay_Data_Str;
        LiDisplay_Data_Str = "page" + String(page) + "." + typeMap[elementTypeIndex] + elementId + "." + attrMap[elementAttrIndex] + "=" + String('"') + value + String('"');
        Serial1.print(LiDisplay_Data_Str);
        Serial1.write(0xFF);
        Serial1.write(0xFF);
        Serial1.write(0xFF);
    /*
        Serial1.print("page0.t1.txt=" + String('"') + String(FW_VERSION) + String('"'));
        Serial1.write(0xFF);
        Serial1.write(0xFF);
        Serial1.write(0xFF);
        Serial1.print("page0.n0.val=" + String('"') + String(SoC_getBatteryStateNow_percent()) + String('"'));
        Serial1.write(0xFF);
        Serial1.write(0xFF);
        Serial1.write(0xFF);
    */
    #endif
}

void LiDisplay_refresh(void)
{
    #ifdef LIDISPLAY_CONNECTED

        //static uint8_t LiDisplayElementToUpdate = LCDUPDATE_NUMERRORS; //init round-robin with least likely state to have changed
        static uint32_t millis_previous = 0;

        #define LIDISPLAY_UPDATE_RATE_MILLIS 256 //one element is updated each time

        if(millis() - millis_previous > LIDISPLAY_UPDATE_RATE_MILLIS)
        {
            millis_previous = millis();

            switch(LiDisplayElementToUpdate)
            {
                case 0:
                    //LiDisplay_updateElement(0, 1, 0, 1, String(SoC_getBatteryStateNow_percent()));
                    LiDisplay_updateElement(0, 2, 1, 0, String(FW_VERSION));
                    break;
                case 1:
                    //LiDisplay_updateElement(0, 2, 1, 0, String(555));
                    LiDisplay_updateElement(0, 1, 0, 1, String(SoC_getBatteryStateNow_percent()));
                    break;
                case 2:
                    //LiDisplay_updateElement(0, 2, 1, 0, String(666));
                    LiDisplay_updateElement(0, 0, 0, 1, String(SoC_getBatteryStateNow_percent()));
                    break;
            }

            LiDisplayElementToUpdate += 1;

            if (LiDisplayElementToUpdate > 2) {
                LiDisplayElementToUpdate = 0;
            }

            /*
            uint8_t updateAttempts = 0;
            do
            {
                if( (++LiDisplayElementToUpdate) > LIDISPLAYUPDATE_MAX_VALUE ) { LiDisplayElementToUpdate = 1; } //reset to first element
                updateAttempts++;
            } while( (lcd_updateValue(LiDisplayElementToUpdate) == SCREEN_DIDNT_UPDATE) && (updateAttempts < MAX_LIDISPLAYUPDATE_ATTEMPTS) );
            */
        }

    #endif
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

uint8_t LiDisplay_bytesAvailableForWrite(void)
{
  return Serial1.availableForWrite();
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

uint8_t LiDisplay_writeByte(uint8_t data)
{
  Serial1.write(data);
  return data;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

uint8_t LiDisplay_readByte(void)
{
  return Serial1.read();
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

uint8_t LiDisplay_bytesAvailableToRead()
{
  return Serial1.available();
}
 

Linsight Designer
Joined
3,611 Posts
Discussion Starter · #42 ·
Great to see some tinkering here. Eventually LiBCM will need to communicate by sending bytes instead of strings, to minimize data transfer. For now you can go either way. If you're still having trouble getting it all to work, make a branch and send me a link... I'll see how it works on my end.
 

Engine-Off-Coast
Joined
2,319 Posts
Television set Bumper Gadget Automotive exterior Gas


Very beginnings... I finally got it to edit the values of more than just text boxes. Now that it works I can start making us an actual UI.

I'm thinking 5 screens:
  • Splash On
  • Grid Charging
  • Driving
  • Configuration
  • Splash Off

Different stuff could be displayed on each. Splash Off for example might display version number, hours left, and KW used during most recent drive cycle. Splash On might display version, hours left, and KW charged or energy consumption (from fan) during the period since last key-off.
 
41 - 44 of 44 Posts
Top