Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: LEAF charger + Cell monitoring #151

Merged
merged 11 commits into from
Feb 3, 2024
Merged

Conversation

dalathegreat
Copy link
Owner

@dalathegreat dalathegreat commented Feb 1, 2024

What

This PR adds the following features

  • Cell monitoring page in webui (All cellvoltages for LEAF + Tesla)
    bild

  • Test fake battery now has editable voltage in webui

  • LEAF PDM support, for emergency generator charging ⛽
    bild

Why

Popularly requested features

How

This is a mess of a PR, coded in a 7h marathon. It will have bugs in the PDM support, but I will squish those later when I test the generator charging at home.

.MsgID = 0x59E,
.data = {0x00, 0x00, 0x0C, 0x76, 0x18, 0x00, 0x00, 0x00}};

static uint8_t crctable[256] = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps relocate out to a common header for leaf battery helper functions/variables/defines used by both the battery code and the charger?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be done at a later time. In PR #152 I added a "utils" folder for common tools, it could be added there as a separate PR after merging #151 and #152 to main

// 0x66 = 0.5A (2x)
// 0x65 = 0.3A (1x)
// 0x64 = no chg
// so 0x64=100. 0xA0=160. so 60 decimal steps. 1 step=100W???
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a suggestion but more thinking out loud. I see this comment block above echoed in Damien's PDM implementation too..to me, 60 100w steps is suspiciously close to the capacity of the 6.6kw charger. I do wonder about differences between the 3.3 and 6.6 versions

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I will clean this up once I get it confirmed working!

@dalathegreat dalathegreat self-assigned this Feb 2, 2024
String cellContent = "Cell " + String(i + 1) + "<br>" + String(cellvoltages[i]) + " mV";

// Check if the cell voltage is below 3000, apply red color
if (cellvoltages[i] < 3000) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wonder if we move this to a user setting with this as default... to account for differences between LFP and other cell types

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No more settings for users to mess up :) Later on we can make this smarter, and autodetect. Each battery file has defined min / max cell voltage ranges, so we should develop a way to use those. But since this PR is blocking other PRs, I suggest we merge this one as-is now as a start!

extern uint16_t temperature_max; //C+1, Goes thru convert2unsignedint16 function (15.0C = 150, -15.0C = 65385)
extern uint16_t cell_max_voltage; //mV, 0-4350
extern uint16_t cell_min_voltage; //mV, 0-4350
extern uint16_t cellvoltages[120]; //mV 0-5000 per cell
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also here, cell min voltage comment is 0-4350 and cell voltages array 0-5000... can be confusing

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments updated in 0befc4b

Copy link
Collaborator

@Cabooman Cabooman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be good to start considering a simple code standard with the influx of changes from various contributors, specifically naming conventions for files, functions and variables. It's getting a bit all over the place :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to keep with the kind of naming convention we have so far for the (physical) system components, i.e. NISSAN-LEAF-CHARGER.*

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 6d7fe87 to match rest of repository standards


extern uint16_t battery_voltage; //V+1, 0-500.0 (0-5000)

void update_values_can_nissanleaf_charger();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I blind or is the definition missing for this function? If it's missing, I guess the declaration can be deleted. Still confused by the lack of definition since some check should complain if it doesn't exist (so maybe I AM blind) but the lack of function calls could mean that the declaration is ignored

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it's unused, removed in 6d7fe87

Comment on lines 12 to 13
uint8_t calculate_CRC_Nissan(CAN_frame_t* frame);
uint8_t calculate_checksum_nibble(CAN_frame_t* frame);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are (currently at least) used as local functions, so the declarations can be moved to .cpp and be made static

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, made static in 05b9e79

@dalathegreat dalathegreat merged commit e93e128 into main Feb 3, 2024
34 checks passed
@dalathegreat dalathegreat deleted the feature/LEAF-charger branch February 3, 2024 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants