1
0
forked from me/IronOS

expand bulk data to match individual value data (#1555)

* track and return Operating mode with BLE

* move global variable to fix build on other platforms

* formatting

* expand bulk data to match individual value data

* formatting

* fix accidental single line if

---------

Co-authored-by: Ben V. Brown <5425387+Ralim@users.noreply.github.com>
This commit is contained in:
Thomas White
2023-02-04 21:04:51 +08:00
committed by GitHub
parent 9802a622d5
commit 8e7e58018a
6 changed files with 66 additions and 25 deletions

View File

@@ -70,13 +70,7 @@ int ble_char_read_status_callback(struct bt_conn *conn, const struct bt_gatt_att
break; break;
case 6: // power src case 6: // power src
// Todo return enum for current power source // Todo return enum for current power source
if (getIsPoweredByDCIN()) { temp = getPowerSrc();
temp = 0;
} else if (USBPowerDelivery::negotiationComplete()) {
temp = 1;
} else {
temp = 2;
}
memcpy(buf, &temp, sizeof(temp)); memcpy(buf, &temp, sizeof(temp));
return sizeof(temp); return sizeof(temp);
break; break;
@@ -124,7 +118,6 @@ int ble_char_read_status_callback(struct bt_conn *conn, const struct bt_gatt_att
break; break;
case 13: case 13:
// Operating mode // Operating mode
// TODO: Needs tracking
temp = currentMode; temp = currentMode;
memcpy(buf, &temp, sizeof(temp)); memcpy(buf, &temp, sizeof(temp));
return sizeof(temp); return sizeof(temp);
@@ -150,13 +143,20 @@ int ble_char_read_bulk_value_callback(struct bt_conn *conn, const struct bt_gatt
// Bulk data // Bulk data
{ {
uint32_t bulkData[] = { uint32_t bulkData[] = {
TipThermoModel::getTipInC(), // Current temp TipThermoModel::getTipInC(), // 0 - Current temp
getSettingValue(SettingsOptions::SolderingTemp), // Setpoint getSettingValue(SettingsOptions::SolderingTemp), // 1 - Setpoint
getHandleTemperature(0), // Handle X10 Temp in C getInputVoltageX10(getSettingValue(SettingsOptions::VoltageDiv), 0), // 2 - Input voltage
getInputVoltageX10(getSettingValue(SettingsOptions::VoltageDiv), 0), // Input voltage getHandleTemperature(0), // 3 - Handle X10 Temp in C
x10WattHistory.average(), // Estimated Wattage X10WattsToPWM(x10WattHistory.average()), // 4 - Power as PWM level
X10WattsToPWM(x10WattHistory.average()), // Power as PWM level getPowerSrc(), // 5 - power src
TipThermoModel::convertTipRawADCTouV(getTipRawTemp(0), true), // Raw tip getTipResistanceX10(), // 6 - Tip resistance
xTaskGetTickCount() / TICKS_100MS, // 7 - uptime in deciseconds
lastMovementTime / TICKS_100MS, // 8 - last movement time (deciseconds)
TipThermoModel::getTipMaxInC(), // 9 - max temp
TipThermoModel::convertTipRawADCTouV(getTipRawTemp(0), true), // 10 - Raw tip in μV
abs(getRawHallEffect()), // 11 - hall sensor
currentMode, // 12 - Operating mode
x10WattHistory.average(), // 13 - Estimated Wattage *10
}; };
int lenToCopy = sizeof(bulkData) - offset; int lenToCopy = sizeof(bulkData) - offset;
if (lenToCopy > len) { if (lenToCopy > len) {
@@ -243,3 +243,37 @@ int ble_char_write_setting_value_callback(struct bt_conn *conn, const struct bt_
MSG("Unhandled attr write %d | %d\n", (uint32_t)attr->uuid, uuid_value); MSG("Unhandled attr write %d | %d\n", (uint32_t)attr->uuid, uuid_value);
return 0; return 0;
} }
uint32_t getPowerSrc() {
int sourceNumber = 0;
if (getIsPoweredByDCIN()) {
sourceNumber = 0;
} else {
// We are not powered via DC, so want to display the appropriate state for PD or QC
bool poweredbyPD = false;
bool pdHasVBUSConnected = false;
#if POW_PD
if (USBPowerDelivery::fusbPresent()) {
// We are PD capable
if (USBPowerDelivery::negotiationComplete()) {
// We are powered via PD
poweredbyPD = true;
#ifdef VBUS_MOD_TEST
pdHasVBUSConnected = USBPowerDelivery::isVBUSConnected();
#endif
}
}
#endif
if (poweredbyPD) {
if (pdHasVBUSConnected) {
sourceNumber = 2;
} else {
sourceNumber = 3;
}
} else {
sourceNumber = 1;
}
}
return sourceNumber;
}

View File

@@ -13,6 +13,8 @@ int ble_char_read_bulk_value_callback(struct bt_conn *conn, const struct bt_gatt
int ble_char_write_setting_value_callback(struct bt_conn *conn, const struct bt_gatt_attr *attr, const void *buf, u16_t len, u16_t offset, u8_t flags); int ble_char_write_setting_value_callback(struct bt_conn *conn, const struct bt_gatt_attr *attr, const void *buf, u16_t len, u16_t offset, u8_t flags);
uint32_t getPowerSrc();
#ifdef __cplusplus #ifdef __cplusplus
}; };
#endif #endif

View File

@@ -27,9 +27,10 @@ extern "C" {
enum OperatingMode { enum OperatingMode {
idle = 0, idle = 0,
soldering = 1, soldering = 1,
sleeping = 2, boost = 2,
settings = 3, sleeping = 3,
debug = 4 settings = 4,
debug = 5
}; };
void performCJCC(void); // Used to calibrate the Cold Junction offset void performCJCC(void); // Used to calibrate the Cold Junction offset

View File

@@ -45,6 +45,7 @@ void gui_solderingMode(uint8_t jumpToSleep) {
// if boost mode is enabled turn it on // if boost mode is enabled turn it on
if (getSettingValue(SettingsOptions::BoostTemp) && (getSettingValue(SettingsOptions::LockingMode) == 1)) { if (getSettingValue(SettingsOptions::BoostTemp) && (getSettingValue(SettingsOptions::LockingMode) == 1)) {
boostModeOn = true; boostModeOn = true;
currentMode = OperatingMode::boost;
} }
break; break;
// fall through // fall through
@@ -63,14 +64,17 @@ void gui_solderingMode(uint8_t jumpToSleep) {
case BUTTON_NONE: case BUTTON_NONE:
// stay // stay
boostModeOn = false; boostModeOn = false;
currentMode = OperatingMode::soldering;
break; break;
case BUTTON_BOTH: case BUTTON_BOTH:
case BUTTON_B_LONG: case BUTTON_B_LONG:
return; // exit on back long hold return; // exit on back long hold
case BUTTON_F_LONG: case BUTTON_F_LONG:
// if boost mode is enabled turn it on // if boost mode is enabled turn it on
if (getSettingValue(SettingsOptions::BoostTemp)) if (getSettingValue(SettingsOptions::BoostTemp)) {
boostModeOn = true; boostModeOn = true;
currentMode = OperatingMode::boost;
}
break; break;
case BUTTON_F_SHORT: case BUTTON_F_SHORT:
case BUTTON_B_SHORT: { case BUTTON_B_SHORT: {