diff --git a/app/src/main/java/icu/fur93/esp32_car/page/ControlPage.kt b/app/src/main/java/icu/fur93/esp32_car/page/ControlPage.kt index 7aba02d..c00c9f1 100644 --- a/app/src/main/java/icu/fur93/esp32_car/page/ControlPage.kt +++ b/app/src/main/java/icu/fur93/esp32_car/page/ControlPage.kt @@ -1,15 +1,33 @@ package icu.fur93.esp32_car.page +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.height +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.Home import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.vector.ImageVector +import androidx.compose.ui.res.vectorResource +import androidx.compose.ui.unit.dp import androidx.navigation.NavHostController +import icu.fur93.esp32_car.R import icu.fur93.esp32_car.Route +import icu.fur93.esp32_car.ui.carditem.StatusCardInfo +import icu.fur93.esp32_car.ui.carditem.StatusCardJoystickStatus +import icu.fur93.esp32_car.ui.carditem.StatusCardMotorStatus import icu.fur93.esp32_car.ui.component.BottomNavigationBar +import icu.fur93.esp32_car.ui.component.CardButtonGroup +import icu.fur93.esp32_car.ui.component.CardButtonItem +import icu.fur93.esp32_car.ui.component.PageTitle +import icu.fur93.esp32_car.ui.component.StatusCard import icu.fur93.esp32_car.ui.layout.MainLayout @Composable fun ControlPage(navController: NavHostController) { MainLayout( content = { + PageTitle("控制") + ControlPageStatusCard() }, bottomBar = { BottomNavigationBar( @@ -18,4 +36,45 @@ fun ControlPage(navController: NavHostController) { ) } ) +} + +@Composable +fun ControlPageStatusCard() { + ControlPageAutoControl() + Spacer(Modifier.height(18.dp)) + ControlPageManualControl() +} + +@Composable +fun ControlPageAutoControl() { + return CardButtonGroup( + title = "自动控制", + buttons = listOf( + CardButtonItem( + text = "循迹模式", + icon = ImageVector.vectorResource(id = R.drawable.outline_route_24) + ) + ) + ) +} + +@Composable +fun ControlPageManualControl() { + CardButtonGroup( + title = "手动控制", + buttons = listOf( + CardButtonItem( + text = "单摇杆模式", + icon = ImageVector.vectorResource(id = R.drawable.outline_joystick_24) + ), + CardButtonItem( + text = "单向按键模式", + icon = ImageVector.vectorResource(id = R.drawable.outline_gamepad_24) + ), + CardButtonItem( + text = "陀螺仪模式", + icon = ImageVector.vectorResource(id = R.drawable.motion_sensor_active_24) + ) + ) + ) } \ No newline at end of file diff --git a/app/src/main/java/icu/fur93/esp32_car/page/HomePage.kt b/app/src/main/java/icu/fur93/esp32_car/page/HomePage.kt index a7ba8dc..05f3669 100644 --- a/app/src/main/java/icu/fur93/esp32_car/page/HomePage.kt +++ b/app/src/main/java/icu/fur93/esp32_car/page/HomePage.kt @@ -1,22 +1,16 @@ package icu.fur93.esp32_car.page -import androidx.compose.foundation.layout.Arrangement -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.lazy.grid.GridCells -import androidx.compose.foundation.lazy.grid.LazyVerticalGrid -import androidx.compose.material3.Button -import androidx.compose.material3.Text import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier import androidx.navigation.NavHostController import icu.fur93.esp32_car.Route +import icu.fur93.esp32_car.ui.card.UnconnectedStatusCard +import icu.fur93.esp32_car.ui.carditem.StatusCardInfo +import icu.fur93.esp32_car.ui.carditem.StatusCardInfraredStatus +import icu.fur93.esp32_car.ui.carditem.StatusCardMotorStatus +import icu.fur93.esp32_car.ui.carditem.StatusCardUltrasoundStatus import icu.fur93.esp32_car.ui.component.BottomNavigationBar -import icu.fur93.esp32_car.ui.component.CardItem import icu.fur93.esp32_car.ui.component.PageTitle import icu.fur93.esp32_car.ui.component.StatusCard -import icu.fur93.esp32_car.ui.component.StatusCardItemText import icu.fur93.esp32_car.ui.layout.MainLayout @Composable @@ -24,8 +18,8 @@ fun HomePage(navController: NavHostController) { MainLayout( content = { PageTitle("标题还没想好") -// HomePageConnectedStatusCard() - HomePageUnconnectedStatusCard() + HomePageStatusCard() +// UnconnectedStatusCard() }, bottomBar = { BottomNavigationBar( @@ -37,89 +31,14 @@ fun HomePage(navController: NavHostController) { } @Composable -fun HomePageConnectedStatusCard() { +fun HomePageStatusCard() { StatusCard( cardItems = listOf( - CardItem( - title = "当前连接", - content = { - StatusCardItemText("名称 Name") - StatusCardItemText("Mac XX:XX:XX:XX:XX:XX") - StatusCardItemText("版本 001") - } - ), - CardItem( - title = "电机状态", - content = { - LazyVerticalGrid( - columns = GridCells.Fixed(2) - ) { - item { - StatusCardItemText("A 0 1 255") - } - item { - StatusCardItemText("D 0 1 255") - } - item { - StatusCardItemText("B 1 0 255") - } - item { - StatusCardItemText("C 1 0 255") - } - } - } - ), - CardItem( - title = "红外模块状态", - content = { - Row( - modifier = Modifier.fillMaxWidth(), - horizontalArrangement = Arrangement.SpaceBetween - ) { - listOf(0, 0, 0, 0, 0).forEach { status -> - StatusCardItemText(status.toString()) - } - } - } - ), - CardItem( - title = "超声波状态", - content = { - Row( - modifier = Modifier.fillMaxWidth() - ) { - Column(Modifier.weight(1f)) { - StatusCardItemText("舵机角度 90") - } - Column(Modifier.weight(1f)) { - StatusCardItemText("舵机角度 20mm") - } - } - } - ) + StatusCardInfo(), + StatusCardMotorStatus(), + StatusCardInfraredStatus(), + StatusCardUltrasoundStatus() ) ) } -@Composable -fun HomePageUnconnectedStatusCard() { - StatusCard( - cardItems = listOf( - CardItem( - title = "设备未连接", - content = { - StatusCardItemText("请先连接设备") - } - ) - ), - bottomControl = { - Button( - onClick = { - - } - ) { - Text("连接设备") - } - } - ) -} \ No newline at end of file diff --git a/app/src/main/java/icu/fur93/esp32_car/ui/card/UnconnectedStatusCard.kt b/app/src/main/java/icu/fur93/esp32_car/ui/card/UnconnectedStatusCard.kt new file mode 100644 index 0000000..1816857 --- /dev/null +++ b/app/src/main/java/icu/fur93/esp32_car/ui/card/UnconnectedStatusCard.kt @@ -0,0 +1,31 @@ +package icu.fur93.esp32_car.ui.card + +import androidx.compose.material3.Button +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import icu.fur93.esp32_car.ui.component.CardItem +import icu.fur93.esp32_car.ui.component.StatusCard +import icu.fur93.esp32_car.ui.component.StatusCardItemText + +@Composable +fun UnconnectedStatusCard() { + StatusCard( + cardItems = listOf( + CardItem( + title = "设备未连接", + content = { + StatusCardItemText("请先连接设备") + } + ) + ), + bottomControl = { + Button( + onClick = { + + } + ) { + Text("连接设备") + } + } + ) +} \ No newline at end of file diff --git a/app/src/main/java/icu/fur93/esp32_car/ui/carditem/StatusCardInfo.kt b/app/src/main/java/icu/fur93/esp32_car/ui/carditem/StatusCardInfo.kt new file mode 100644 index 0000000..0d3db94 --- /dev/null +++ b/app/src/main/java/icu/fur93/esp32_car/ui/carditem/StatusCardInfo.kt @@ -0,0 +1,19 @@ +package icu.fur93.esp32_car.ui.carditem + +import android.annotation.SuppressLint +import androidx.compose.runtime.Composable +import icu.fur93.esp32_car.ui.component.CardItem +import icu.fur93.esp32_car.ui.component.StatusCardItemText + +@SuppressLint("ComposableNaming") +@Composable +fun StatusCardInfo () : CardItem { + return CardItem( + title = "当前连接", + content = { + StatusCardItemText("名称 Name") + StatusCardItemText("Mac XX:XX:XX:XX:XX:XX") + StatusCardItemText("版本 001") + } + ) +} \ No newline at end of file diff --git a/app/src/main/java/icu/fur93/esp32_car/ui/carditem/StatusCardInfraredStatus.kt b/app/src/main/java/icu/fur93/esp32_car/ui/carditem/StatusCardInfraredStatus.kt new file mode 100644 index 0000000..ef94e8f --- /dev/null +++ b/app/src/main/java/icu/fur93/esp32_car/ui/carditem/StatusCardInfraredStatus.kt @@ -0,0 +1,28 @@ +package icu.fur93.esp32_car.ui.carditem + +import android.annotation.SuppressLint +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import icu.fur93.esp32_car.ui.component.CardItem +import icu.fur93.esp32_car.ui.component.StatusCardItemText + +@SuppressLint("ComposableNaming") +@Composable +fun StatusCardInfraredStatus () : CardItem { + return CardItem( + title = "红外模块状态", + content = { + Row( + modifier = Modifier.fillMaxWidth(), + horizontalArrangement = Arrangement.SpaceBetween + ) { + listOf(0, 0, 0, 0, 0).forEach { status -> + StatusCardItemText(status.toString()) + } + } + } + ) +} \ No newline at end of file diff --git a/app/src/main/java/icu/fur93/esp32_car/ui/carditem/StatusCardJoystickStatus.kt b/app/src/main/java/icu/fur93/esp32_car/ui/carditem/StatusCardJoystickStatus.kt new file mode 100644 index 0000000..ee87b5e --- /dev/null +++ b/app/src/main/java/icu/fur93/esp32_car/ui/carditem/StatusCardJoystickStatus.kt @@ -0,0 +1,18 @@ +package icu.fur93.esp32_car.ui.carditem + +import android.annotation.SuppressLint +import androidx.compose.runtime.Composable +import icu.fur93.esp32_car.ui.component.CardItem +import icu.fur93.esp32_car.ui.component.StatusCardItemText + +@SuppressLint("ComposableNaming") +@Composable +fun StatusCardJoystickStatus () : CardItem { + return CardItem( + title = "摇杆状态", + content = { + StatusCardItemText("X 0.00") + StatusCardItemText("Y 0.00") + } + ) +} \ No newline at end of file diff --git a/app/src/main/java/icu/fur93/esp32_car/ui/carditem/StatusCardPathfinderStatus.kt b/app/src/main/java/icu/fur93/esp32_car/ui/carditem/StatusCardPathfinderStatus.kt new file mode 100644 index 0000000..2f0ee77 --- /dev/null +++ b/app/src/main/java/icu/fur93/esp32_car/ui/carditem/StatusCardPathfinderStatus.kt @@ -0,0 +1,17 @@ +package icu.fur93.esp32_car.ui.carditem + +import android.annotation.SuppressLint +import androidx.compose.runtime.Composable +import icu.fur93.esp32_car.ui.component.CardItem +import icu.fur93.esp32_car.ui.component.StatusCardItemText + +@SuppressLint("ComposableNaming") +@Composable +fun StatusCardPathfinderStatus () : CardItem { + return CardItem( + title = "循迹状态", + content = { + StatusCardItemText("进行中") + } + ) +} \ No newline at end of file diff --git a/app/src/main/java/icu/fur93/esp32_car/ui/carditem/StatusCardSliderStatus.kt b/app/src/main/java/icu/fur93/esp32_car/ui/carditem/StatusCardSliderStatus.kt new file mode 100644 index 0000000..d6dd041 --- /dev/null +++ b/app/src/main/java/icu/fur93/esp32_car/ui/carditem/StatusCardSliderStatus.kt @@ -0,0 +1,17 @@ +package icu.fur93.esp32_car.ui.carditem + +import android.annotation.SuppressLint +import androidx.compose.runtime.Composable +import icu.fur93.esp32_car.ui.component.CardItem +import icu.fur93.esp32_car.ui.component.StatusCardItemText + +@SuppressLint("ComposableNaming") +@Composable +fun StatusCardSliderStatus () : CardItem { + return CardItem( + title = "速度推杆", + content = { + StatusCardItemText("0") + } + ) +} \ No newline at end of file diff --git a/app/src/main/java/icu/fur93/esp32_car/ui/carditem/StatusCardUltrasoundStatus.kt b/app/src/main/java/icu/fur93/esp32_car/ui/carditem/StatusCardUltrasoundStatus.kt new file mode 100644 index 0000000..ac46593 --- /dev/null +++ b/app/src/main/java/icu/fur93/esp32_car/ui/carditem/StatusCardUltrasoundStatus.kt @@ -0,0 +1,30 @@ +package icu.fur93.esp32_car.ui.carditem + +import android.annotation.SuppressLint +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import icu.fur93.esp32_car.ui.component.CardItem +import icu.fur93.esp32_car.ui.component.StatusCardItemText + +@SuppressLint("ComposableNaming") +@Composable +fun StatusCardUltrasoundStatus () : CardItem { + return CardItem( + title = "超声波状态", + content = { + Row( + modifier = Modifier.fillMaxWidth() + ) { + Column(Modifier.weight(1f)) { + StatusCardItemText("舵机角度 90") + } + Column(Modifier.weight(1f)) { + StatusCardItemText("舵机角度 20mm") + } + } + } + ) +} \ No newline at end of file diff --git a/app/src/main/java/icu/fur93/esp32_car/ui/carditem/StautsCardMotorStatus.kt b/app/src/main/java/icu/fur93/esp32_car/ui/carditem/StautsCardMotorStatus.kt new file mode 100644 index 0000000..bcdc6e5 --- /dev/null +++ b/app/src/main/java/icu/fur93/esp32_car/ui/carditem/StautsCardMotorStatus.kt @@ -0,0 +1,34 @@ +package icu.fur93.esp32_car.ui.carditem + +import android.annotation.SuppressLint +import androidx.compose.foundation.lazy.grid.GridCells +import androidx.compose.foundation.lazy.grid.LazyVerticalGrid +import androidx.compose.runtime.Composable +import icu.fur93.esp32_car.ui.component.CardItem +import icu.fur93.esp32_car.ui.component.StatusCardItemText + +@SuppressLint("ComposableNaming") +@Composable +fun StatusCardMotorStatus () : CardItem { + return CardItem( + title = "电机状态", + content = { + LazyVerticalGrid( + columns = GridCells.Fixed(2) + ) { + item { + StatusCardItemText("A 0 1 255") + } + item { + StatusCardItemText("D 0 1 255") + } + item { + StatusCardItemText("B 1 0 255") + } + item { + StatusCardItemText("C 1 0 255") + } + } + } + ) +} \ No newline at end of file diff --git a/app/src/main/java/icu/fur93/esp32_car/ui/component/CardButtonGroup.kt b/app/src/main/java/icu/fur93/esp32_car/ui/component/CardButtonGroup.kt new file mode 100644 index 0000000..10ee0b2 --- /dev/null +++ b/app/src/main/java/icu/fur93/esp32_car/ui/component/CardButtonGroup.kt @@ -0,0 +1,81 @@ +package icu.fur93.esp32_car.ui.component + +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.lazy.grid.GridCells +import androidx.compose.foundation.lazy.grid.LazyVerticalGrid +import androidx.compose.material3.Card +import androidx.compose.material3.Icon +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.vector.ImageVector +import androidx.compose.ui.unit.dp +import icu.fur93.esp32_car.ui.theme.CardButtonTypography + +data class CardButtonItem( + val text: String, + val icon: ImageVector, + val onClick: (() -> Unit)? = null, + val modifier: Modifier? = Modifier +) + +val CardButtonGroupGap = 8.dp + +@Composable +fun CardButtonGroup( + title: String, + buttons: List +) { + Text( + text = title, + style = CardButtonTypography.CardButtonGroupTitleTextStyle + ) + Spacer(Modifier.height(CardButtonGroupGap)) + LazyVerticalGrid( + columns = GridCells.Fixed(2), + horizontalArrangement = Arrangement.spacedBy(CardButtonGroupGap), + verticalArrangement = Arrangement.spacedBy(CardButtonGroupGap) + ) { + buttons.forEach { buttonItem -> + item { + CardButton(buttonItem) + } + } + } +} + +@Composable +fun CardButton( + item: CardButtonItem +) { + Card { + Column( + modifier = Modifier.fillMaxWidth().padding(12.dp), + verticalArrangement = Arrangement.SpaceBetween + ) { + Text( + text = item.text, + style = CardButtonTypography.CardButtonItemTextStyle + ) + Box( + modifier = Modifier.fillMaxWidth(), + contentAlignment = Alignment.BottomEnd + ) { + Icon( + imageVector = item.icon, + contentDescription = item.text, + modifier = Modifier.size(24.dp) + ) + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/icu/fur93/esp32_car/ui/theme/Type.kt b/app/src/main/java/icu/fur93/esp32_car/ui/theme/Type.kt index 3f47f5a..7b30854 100644 --- a/app/src/main/java/icu/fur93/esp32_car/ui/theme/Type.kt +++ b/app/src/main/java/icu/fur93/esp32_car/ui/theme/Type.kt @@ -2,6 +2,7 @@ package icu.fur93.esp32_car.ui.theme import androidx.compose.material3.Typography import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.font.Font import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.sp @@ -47,4 +48,15 @@ object CardTypography { val PageTitleTextStyle = TextStyle( fontSize = 32.sp, fontWeight = FontWeight.Black -) \ No newline at end of file +) + +object CardButtonTypography { + val CardButtonGroupTitleTextStyle = TextStyle( + fontSize = 18.sp, + fontWeight = FontWeight.SemiBold + ) + val CardButtonItemTextStyle = TextStyle( + fontSize = 18.sp, + fontWeight = FontWeight.Normal + ) +} \ No newline at end of file diff --git a/app/src/main/res/drawable/baseline_gamepad_24.xml b/app/src/main/res/drawable/baseline_gamepad_24.xml new file mode 100644 index 0000000..787eb79 --- /dev/null +++ b/app/src/main/res/drawable/baseline_gamepad_24.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/app/src/main/res/drawable/baseline_route_24.xml b/app/src/main/res/drawable/baseline_route_24.xml new file mode 100644 index 0000000..a20c4f5 --- /dev/null +++ b/app/src/main/res/drawable/baseline_route_24.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/app/src/main/res/drawable/motion_sensor_active_24.xml b/app/src/main/res/drawable/motion_sensor_active_24.xml new file mode 100644 index 0000000..0643727 --- /dev/null +++ b/app/src/main/res/drawable/motion_sensor_active_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable/outline_gamepad_24.xml b/app/src/main/res/drawable/outline_gamepad_24.xml new file mode 100644 index 0000000..de6fabb --- /dev/null +++ b/app/src/main/res/drawable/outline_gamepad_24.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/app/src/main/res/drawable/outline_joystick_24.xml b/app/src/main/res/drawable/outline_joystick_24.xml new file mode 100644 index 0000000..fe84cba --- /dev/null +++ b/app/src/main/res/drawable/outline_joystick_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable/outline_route_24.xml b/app/src/main/res/drawable/outline_route_24.xml new file mode 100644 index 0000000..639468b --- /dev/null +++ b/app/src/main/res/drawable/outline_route_24.xml @@ -0,0 +1,5 @@ + + + + +