Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions bridge/bridge_ios.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ static void carStateToBridge(const CarState& cs, BridgeCarState* out) {
out->packTMax = cs.packTMax;
out->odometer = cs.odometer;
out->acTemp = cs.acTemp;
out->acTempRight = cs.acTempRight;
out->hvacFanLevel = cs.hvacFanLevel;
out->hvacPowerState = cs.hvacPowerState;
out->hvacAcMode = cs.hvacAcMode;
out->hvacRecirc = cs.hvacRecirc;
out->hvacKeepClimateOn = cs.hvacKeepClimateOn;
out->madsActive = cs.madsActive;
out->selfdriveActive = cs.selfdriveActive;
out->experimentalMode = cs.experimentalMode;
Expand Down
6 changes: 6 additions & 0 deletions bridge/bridge_ios.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ typedef struct {
double packTMax;
double odometer;
double acTemp;
double acTempRight;
double hvacFanLevel;
double hvacPowerState;
double hvacAcMode;
double hvacRecirc;
double hvacKeepClimateOn;

// Openpilot state
double madsActive;
Expand Down
17 changes: 15 additions & 2 deletions bridge/car/car_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ struct CarState {
double packTMax = 0;
double odometer = 0;
double acTemp = 0;
double acTempRight = 0;
double hvacFanLevel = 0;
double hvacPowerState = 0;
double hvacAcMode = 0;
double hvacRecirc = 0;
double hvacKeepClimateOn = 0;

// Openpilot state
double madsActive = 0;
Expand All @@ -46,7 +52,8 @@ struct CarState {
char vin[VIN_LENGTH + 1] = {};

static constexpr size_t VIN_DOUBLE_COUNT = 3;
static constexpr size_t FIELD_COUNT = 31 + VIN_DOUBLE_COUNT;
static constexpr size_t VIN_OFFSET = 37;
static constexpr size_t FIELD_COUNT = VIN_OFFSET + VIN_DOUBLE_COUNT;

void toArray(double* out) const {
// Party bus
Expand Down Expand Up @@ -86,11 +93,17 @@ struct CarState {
out[29] = changingLane;

out[30] = acTemp;
out[31] = acTempRight;
out[32] = hvacFanLevel;
out[33] = hvacPowerState;
out[34] = hvacAcMode;
out[35] = hvacRecirc;
out[36] = hvacKeepClimateOn;

// VIN chars ride the double array as raw bit patterns, 8 bytes per
// double; decoded by CanFrameDecoder.arrayToCarState.
char padded[VIN_DOUBLE_COUNT * sizeof(double)] = {};
std::memcpy(padded, vin, VIN_LENGTH);
std::memcpy(out + 31, padded, sizeof(padded));
std::memcpy(out + VIN_OFFSET, padded, sizeof(padded));
}
};
6 changes: 6 additions & 0 deletions bridge/car/cars/tesla.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ class TeslaDashKitMapper : public CarStateMapper {

// Climate setpoint temperature (degC) from the vehicle bus.
cs.acTemp = cp.get(1, "UI_hvacRequest", "UI_hvacReqTempSetpointLeft");
cs.acTempRight = cp.get(1, "UI_hvacRequest", "UI_hvacReqTempSetpointRight");
cs.hvacFanLevel = cp.get(1, "UI_hvacRequest", "UI_hvacReqBlowerSegment");
cs.hvacPowerState = cp.get(1, "UI_hvacRequest", "UI_hvacReqUserPowerState");
cs.hvacAcMode = cp.get(1, "UI_hvacRequest", "UI_hvacReqACDisable");
cs.hvacRecirc = cp.get(1, "UI_hvacRequest", "UI_hvacReqRecirc");
cs.hvacKeepClimateOn = cp.get(1, "UI_hvacRequest", "UI_hvacReqKeepClimateOn");

updateVehicleBus(cp, cs);
vin_.update(cp, cs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ import com.softwiredtech.dashpilot.datamodel.dash.setLoadedManifests
import com.softwiredtech.dashpilot.datasource.ConnectionStatus
import com.softwiredtech.dashpilot.datasource.DataSourceType
import com.softwiredtech.dashpilot.navigation.AutomationsRoute
import com.softwiredtech.dashpilot.navigation.BatteryRoute
import com.softwiredtech.dashpilot.navigation.ClimateRoute
import com.softwiredtech.dashpilot.navigation.ControlsRoute
import com.softwiredtech.dashpilot.navigation.DashboardRoute
import com.softwiredtech.dashpilot.navigation.OnboardingRoute
Expand All @@ -52,6 +54,8 @@ import com.softwiredtech.dashpilot.navigation.SetupRoute
import com.softwiredtech.dashpilot.navigation.TeslaEnrollRoute
import com.softwiredtech.dashpilot.navigation.ThemePickerRoute
import com.softwiredtech.dashpilot.ui.AutomationsScreen
import com.softwiredtech.dashpilot.ui.BatteryScreen
import com.softwiredtech.dashpilot.ui.ClimateScreen
import com.softwiredtech.dashpilot.ui.ControlScreen
import com.softwiredtech.dashpilot.ui.DashboardScreen
import com.softwiredtech.dashpilot.ui.HomeScreen
Expand Down Expand Up @@ -272,6 +276,12 @@ class MainActivity : ComponentActivity() {
connectionVM.disconnect()
},
onNext = toDashboard,
onBattery = {
navController.navigate(BatteryRoute)
},
onClimate = {
navController.navigate(ClimateRoute)
},
onAutomations = {
navController.navigate(AutomationsRoute)
},
Expand All @@ -284,6 +294,30 @@ class MainActivity : ComponentActivity() {
}
)
}
composable<BatteryRoute> {
val manager by connectionVM.bleManager.collectAsState()
val dashStateFlow by connectionVM.dashState.collectAsState()
BatteryScreen(
dashState = dashStateFlow,
bleManager = manager,
onBack = { navController.popBackStack() }
)
}
composable<ClimateRoute> {
val dashStateFlow by connectionVM.dashState.collectAsState()
ClimateScreen(
dashState = dashStateFlow,
climateKeepEnabled = climateKeepAutomation,
onClimateKeepChange = {
connectionVM.updateClimateKeepAutomation(context, it)
},
climateKeepMinutes = climateKeepMinutes,
onClimateKeepMinutesChange = {
connectionVM.updateClimateKeepMinutes(context, it)
},
onBack = { navController.popBackStack() }
)
}
composable<ControlsRoute> {
val manager by connectionVM.bleManager.collectAsState()
ControlScreen(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ data class CarState(
val packTMax: Float = 0f,
val odometer: Float = 0f,
val acTemp: Float = 0f,
val acTempRight: Float = 0f,
val hvacFanLevel: Float = 0f,
val hvacPowerState: Float = 0f,
val hvacAcMode: Float = 0f,
val hvacRecirc: Float = 0f,
val hvacKeepClimateOn: Float = 0f,
// Openpilot
val selfdriveActive: Boolean = false,
val experimentalMode: Boolean = false,
Expand All @@ -46,11 +52,12 @@ data class CarState(
packTMin = if (packTMin != 0f) packTMin * 1.8f + 32f else 0f,
packTMax = if (packTMax != 0f) packTMax * 1.8f + 32f else 0f,
acTemp = if (acTemp != 0f) acTemp * 1.8f + 32f else 0f,
acTempRight = if (acTempRight != 0f) acTempRight * 1.8f + 32f else 0f,
fusedSpeedLimit = if (speedLimitSignsInKm()) fusedSpeedLimit * KM_TO_MILES else fusedSpeedLimit,
)

companion object {
const val FIELD_COUNT = 34
const val FIELD_COUNT = 40
private const val KM_TO_MILES = 0.621371f

private val MILES_COUNTRIES = setOf("US", "GB", "MM", "LR")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ object ThemePickerRoute
@Serializable
object AutomationsRoute

@Serializable
object BatteryRoute

@Serializable
object ClimateRoute

@Serializable
object ControlsRoute

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import com.softwiredtech.dashpilot.ui.theme.DarkColors
private val FINGER_COUNTS = 3..5

// Minutes the keep-climate-on window can run (matches the firmware clamp).
private val CLIMATE_KEEP_MINUTE_RANGE = 1..60
internal val CLIMATE_KEEP_MINUTE_RANGE = 1..60

// Matches the firmware clamp.
private val SPORT_KICKDOWN_PERCENT_RANGE = 10..95
Expand Down Expand Up @@ -211,7 +211,7 @@ private fun SectionLabel(text: String) {
}

@Composable
private fun NumberPickerFooter(
internal fun NumberPickerFooter(
label: String,
value: Int,
unit: String,
Expand Down Expand Up @@ -403,7 +403,7 @@ private fun AddTriggerButton(onClick: () -> Unit) {
}

@Composable
private fun AutomationRow(
internal fun AutomationRow(
icon: ImageVector,
title: String,
subtitle: String?,
Expand Down
Loading
Loading