Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import io.rebble.libpebblecommon.database.dao.ValueParams
import io.rebble.libpebblecommon.database.dao.WatchPreference
import io.rebble.libpebblecommon.database.entity.QuickLaunchSetting.Companion.toJson
import io.rebble.libpebblecommon.metadata.WatchType
import io.rebble.libpebblecommon.packets.ProtocolCapsFlag
import io.rebble.libpebblecommon.packets.blobdb.TimelineAttribute
import io.rebble.libpebblecommon.packets.blobdb.TimelineItem.Attribute
import io.rebble.libpebblecommon.services.blobdb.DbWrite
Expand Down Expand Up @@ -68,6 +69,11 @@ data class WatchPrefItem(
logger.w { "Don't know how to encode watch pref key: $id" }
return null
}
if (type.isBacklightColorScheduleHelperPref() &&
!params.capabilities.contains(ProtocolCapsFlag.SupportsBacklightColorSchedule)) {
logger.d { "Skipping $id: watch does not support backlight color scheduling" }
return null
}
logger.v { "trying to insert watch pref to watch blobdb: $id / $value" }
val bytes = try {
when (type.type) {
Expand Down Expand Up @@ -132,6 +138,13 @@ data class WatchPrefItem(
}
}

fun WatchPref<*>.isBacklightColorScheduleHelperPref(): Boolean {
return this == BoolWatchPref.BacklightColorDayNightEnabled ||
this == RgbColorWatchPref.BacklightColorNight ||
this == NumberWatchPref.BacklightColorSunriseMinute ||
this == NumberWatchPref.BacklightColorSunsetMinute
}

enum class WatchPrefType {
TypeString,
TypeUuid,
Expand Down Expand Up @@ -203,6 +216,12 @@ enum class BoolWatchPref(
Backlight("lightEnabled", "Backlight", true),
AmbientLightSensor("lightAmbientSensorEnabled", "Ambient Light Sensor", true, description = "Only enable backlight when in a dark environment (using light sensor)"),
BacklightMotion("lightMotion", "Backlight Motion", true, description = "Turn on backlight by flicking wrist"),
BacklightColorDayNightEnabled(
id = "lightColorDayNightEnabled",
displayName = "Change Backlight Color at night",
defaultValue = false,
description = null,
),
DynamicBacklightIntensity("lightDynamicIntensity", "Dynamic Backlight Intensity", true, description = "Adjust backlight intensity automatically to match environment (using light sensor)"),
LanguageEnglish("langEnglish", "Language: English", false),
TimelineQuickViewEnabled("timelineQuickViewEnabled", "Timeline Quick View", true, description = "Show upcoming events below watchface"),
Expand Down Expand Up @@ -524,6 +543,26 @@ enum class NumberWatchPref(
max = 30,
unit = "minutes",
),
BacklightColorSunriseMinute(
id = "lightColorSunriseMinute",
displayName = "Backlight Color Sunrise Minute",
defaultValue = 6L * 60,
type = WatchPrefType.TypeUInt16,
min = 0,
max = 1439,
unit = "minutes",
isDebugSetting = true,
),
BacklightColorSunsetMinute(
id = "lightColorSunsetMinute",
displayName = "Backlight Color Sunset Minute",
defaultValue = 18L * 60,
type = WatchPrefType.TypeUInt16,
min = 0,
max = 1439,
unit = "minutes",
isDebugSetting = true,
),
NotificationTimeoutMs(
id = "notifWindowTimeout",
displayName = "Notification Timeout",
Expand Down Expand Up @@ -578,6 +617,13 @@ enum class RgbColorWatchPref(
presets = BACKLIGHT_COLOR_PRESETS,
description = "LED color used when the backlight is on, unless over-ridden by an app (color-backlight watches only)",
),
BacklightColorNight(
id = "lightColorNight",
displayName = "Night",
defaultValue = LED_WARM_WHITE_RGB,
presets = BACKLIGHT_COLOR_PRESETS,
description = null,
),
;

override val type = WatchPrefType.TypeUInt32
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ enum class ProtocolCapsFlag(val value: Int) {
SupportsFwUpdateAcrossDisconnection(21),
SupportsBlobDbVersion(22),
SupportsSettingsSync(23),
SupportsBacklightColorSchedule(24),
;

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,4 @@ fun PebbleDevice.watchType(): WatchHardwarePlatform? = when (this) {
fun PebbleDevice.isConnected(): Boolean =
this is ConnectedPebbleDevice || this is ConnectedPebbleDeviceInRecovery

fun PebbleDevice.hasConnectGoal(): Boolean = isConnected() || this is ConnectingPebbleDevice
fun PebbleDevice.hasConnectGoal(): Boolean = isConnected() || this is ConnectingPebbleDevice
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package coredevices.pebble.backlight

import kotlinx.datetime.TimeZone
import kotlinx.datetime.toLocalDateTime
import kotlin.time.Instant

const val BACKLIGHT_COLOR_USE_WEATHER_SCHEDULE_SETTINGS_KEY =
"backlight_color_use_weather_schedule"

fun backlightScheduleMinuteOfDay(
instant: Instant,
timeZone: TimeZone = TimeZone.currentSystemDefault(),
): Int {
val local = instant.toLocalDateTime(timeZone)
return local.hour * 60 + local.minute
}

fun formatBacklightScheduleMinute(minuteOfDay: Long): String {
val minute = minuteOfDay.coerceIn(0, 1439)
val hour = minute / 60
val minutePart = minute % 60
return "${hour.toString().padStart(2, '0')}:${minutePart.toString().padStart(2, '0')}"
}
3 changes: 2 additions & 1 deletion pebble/src/commonMain/kotlin/coredevices/pebble/ui/Colors.kt
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ fun SelectRgbColor(
currentRgb: UInt,
defaultRgb: UInt,
presets: List<RgbColorPreset>,
label: String = "Color",
onChangeColor: (UInt) -> Unit,
) {
var showPicker by remember { mutableStateOf(false) }
Expand All @@ -525,7 +526,7 @@ fun SelectRgbColor(
val swatchColor = Color(0xFF000000u.toInt() or (currentRgb and 0x00FFFFFFu).toInt())
val matchedPreset = presets.firstOrNull { it.rgb == currentRgb }
ListItem(
headlineContent = { Text("Color") },
headlineContent = { Text(label) },
supportingContent = {
Box(modifier = Modifier.padding(4.dp)) {
Box(
Expand Down
Loading