Giter Club home page Giter Club logo

Comments (8)

DerKleinePunk avatar DerKleinePunk commented on June 13, 2024 2

More Complex Sample

from elmduino.

wcjxixi avatar wcjxixi commented on June 13, 2024 2

@PowerBroker2 @DerKleinePunk THX!

According to the sample code, It is supposed to use the switch case. I modified the code template as follows:

int    switchNum = 1;

uint32_t     rpm = 0;
......
uint32_t coolant = 0;

//_____________________________________________________________
void updateRpm(uint32_t rpm, bool error) {
  canvas.fillScreen(BLACK);
  gfx.setFont(u8g2_font_wqy15_t_gb2312b);
  gfx.setForegroundColor(LIME);
  gfx.setCursor(2, 14);  gfx.println(F("发动机转速 rpm"));

  gfx.setFont(dsdigital_42);
  gfx.setForegroundColor(WHITE);
  gfx.setCursor(0, 62);
  if (error) {
    gfx.println(F("-"));
  } else {
    gfx.println(rpm);
  }
  //show_canvas_on_screen();
}

......

void updateCoolant(uint32_t coolant, bool error) {
  //canvas.fillScreen(BLACK);
  gfx.setFont(u8g2_font_wqy15_t_gb2312b);
  gfx.setForegroundColor(LIME);
  gfx.setCursor(2, 80);  gfx.println(F("冷却液温度 °C"));

  gfx.setForegroundColor(WHITE);
  gfx.setFont(dsdigital_47);
  gfx.setCursor(0, 128);
  if (error) {
    gfx.println(F("-"));
  } else {
    gfx.println(coolant);
  }
  show_canvas_on_screen();
}

//_____________________________________________________________
void loop() {
  switch (switchNum) {
    case 1: {
        float tempRPM = myELM327.rpm();
        if (myELM327.nb_rx_state == ELM_SUCCESS) {
          rpm = (uint32_t)tempRPM;
          updateRpm(rpm, false);
          switchNum == 2;
        }
        else if (myELM327.nb_rx_state != ELM_GETTING_MSG) {
          updateRpm(0, true);
          switchNum == 2;
        }
        break;
      }

      ......

    case n: {
        float tempCoolant  = myELM327.engineCoolantTemp();
        if (myELM327.nb_rx_state == ELM_SUCCESS) {
          coolant = (uint32_t)tempCoolant;
          updateCoolant(coolant, false);
          switchNum == 1;
        }
        else if (myELM327.nb_rx_state != ELM_GETTING_MSG) {
          updateCoolant(0, true);
          switchNum == 1;
        }
        break;
      }
  }
}

Now I can get the PIDs value.

However, there is a delay in displaying multiple PID queries, and the more PID queries there are, the greater the delay in displaying them, whereas ELMduino v2.6.4 has no delay at all.

Overall this delay seems acceptable though, so if there's nothing better to do, that's it. Thanks again guys!

from elmduino.

DerKleinePunk avatar DerKleinePunk commented on June 13, 2024 1

@wcjxixi I think it is the display.clearDisplay(); Because non Blocking from new Lib version.

void UpdateDisplay(uint32_t rpm, bool error)
{
display.clearDisplay();
  display.fillRect(0, 0, 128, 32, WHITE);
  u8g2.setForegroundColor(BLACK);
  u8g2.setFont(u8g2_font_wqy16_t_gb2312a);
  u8g2.setFontMode(1);
  u8g2.setCursor(5, 22);
  u8g2.print("RPM: ");

  u8g2.setBackgroundColor(WHITE);
  u8g2.setFont(u8g2_font_freedoomr25_mn);
  u8g2.setCursor(50, 30);
  if(error) {
u8g2.print("-");
  } else {
  u8g2.print(rpm);
 }
 display.display();
}

void loop() {

  float tempRPM = myELM327.rpm();
  if (myELM327.nb_rx_state == ELM_SUCCESS)
  {
    rpm = (uint32_t)tempRPM;
    UpdateDisplay(rpm, false);
    Serial.print("RPM: "); Serial.println(rpm);
  }
  else if (myELM327.nb_rx_state != ELM_GETTING_MSG) {
    UpdateDisplay(0, true);
    myELM327.printError();
  }
}

The Code is written hier not Tested. I hope it helps

from elmduino.

PowerBroker2 avatar PowerBroker2 commented on June 13, 2024 1

You'll want to look at the multiple PIDs example

from elmduino.

wcjxixi avatar wcjxixi commented on June 13, 2024

@DerKleinePunk Thank you very much, your code I tested works fine and the RPM value doesn't flicker anymore!

I'll test it on a real car after I've changed all the code.

from elmduino.

wcjxixi avatar wcjxixi commented on June 13, 2024

How can I get the values of multiple PIDs and display them at the same time?

For example, I want to display two PIDs (e.g. rpm and coolant) on my SSD1306 LCD at the same time, but the correct value and the error value will be displayed alternately.

My code is as follows:

void show_canvas_on_screen() {
  screen.drawRGBBitmap(0, 0, canvas.getBuffer(), canvas.width(), canvas.height());
}

//_____________________________________________________________
void updateRpm(uint32_t rpm, bool error) {
  canvas.fillScreen(BLACK);
  gfx.setFont(u8g2_font_wqy15_t_gb2312b);
  gfx.setForegroundColor(LIME);
  gfx.setCursor(2, 14);  gfx.println(F("发动机转速 rpm"));

  gfx.setFont(dsdigital_42);
  gfx.setForegroundColor(WHITE);
  gfx.setCursor(0, 62);
  if (error) {
    gfx.println(F("-"));
  } else {
    gfx.println(rpm);
  }
  //show_canvas_on_screen();
}

void updateCoolant(uint32_t coolant, bool error) {
  //canvas.fillScreen(BLACK);
  gfx.setFont(u8g2_font_wqy15_t_gb2312b);
  gfx.setForegroundColor(LIME);
  gfx.setCursor(2, 80);  gfx.println(F("冷却液温度 °C"));

  gfx.setForegroundColor(WHITE);
  gfx.setFont(dsdigital_47);
  gfx.setCursor(0, 128);
  if (error) {
    gfx.println(F("-"));
  } else {
    gfx.println(coolant);
  }
  show_canvas_on_screen();
}

//_____________________________________________________________
void loop() {
  float tempRPM = myELM327.rpm();
  if (myELM327.nb_rx_state == ELM_SUCCESS) {
    rpm = (uint32_t)tempRPM;
    updateRpm(rpm, false);
  }
  else if (myELM327.nb_rx_state != ELM_GETTING_MSG) {
    updateRpm(0, true);
  }

  float tempCoolant  = myELM327.engineCoolantTemp();
  if (myELM327.nb_rx_state == ELM_SUCCESS) {
    coolant = (uint32_t)tempCoolant;
    updateCoolant(coolant, false);
  }
  else if (myELM327.nb_rx_state != ELM_GETTING_MSG) {
    updateCoolant(0, true);
  }
}

The debug log is attached:
debug_log.txt

from elmduino.

jimwhitelaw avatar jimwhitelaw commented on June 13, 2024

@DerKleinePunk thanks for sharing that link. There's some interesting code there, I like how you've integrated BLE/classic BT. Nice work.

from elmduino.

DerKleinePunk avatar DerKleinePunk commented on June 13, 2024

@jimwhitelaw Thanks

from elmduino.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.