diff --git a/app/lib/screens/ble2.dart b/app/lib/screens/ble2.dart new file mode 100644 index 00000000..be9a6436 --- /dev/null +++ b/app/lib/screens/ble2.dart @@ -0,0 +1,181 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_bluetooth_serial/flutter_bluetooth_serial.dart'; +import 'dart:convert'; + +void main() { + runApp(MyApp()); +} + +class MyApp extends StatefulWidget { + @override + _MyAppState createState() => _MyAppState(); +} + +class _MyAppState extends State { + BluetoothState _bluetoothState = BluetoothState.UNKNOWN; + BluetoothDevice? _device; + BluetoothConnection? _connection; + String dataToSend = ""; + String sensorData = ""; // Received data (we will update this) + + List _devicesList = []; + bool isConnecting = false; + bool isConnected = false; + + @override + void initState() { + super.initState(); + _initBluetooth(); + } + + void _initBluetooth() async { + _bluetoothState = await FlutterBluetoothSerial.instance.state; + setState(() {}); + + FlutterBluetoothSerial.instance.onStateChanged().listen((state) { + setState(() { + _bluetoothState = state; + }); + }); + + // Fetch paired devices + _devicesList = await FlutterBluetoothSerial.instance.getBondedDevices(); + setState(() {}); + } + + // Connect to device and start listening for sensor data + void _connectToDevice(BluetoothDevice device) async { + setState(() { + isConnecting = true; + _device = device; + }); + + try { + BluetoothConnection.toAddress(_device!.address).then((connection) { + setState(() { + _connection = connection; + isConnected = true; + isConnecting = false; + }); + print('✅ Connected to the device'); + + // After successful connection, start listening for sensor data + _listenToSensorData(); + }).catchError((error) { + print('❌ Connection failed: $error'); + setState(() { + isConnecting = false; + isConnected = false; + }); + }); + } catch (e) { + print('❌ Cannot connect, error: $e'); + setState(() { + isConnecting = false; + }); + } + } + + // Listen to incoming sensor data + void _listenToSensorData() { + _connection!.input!.listen((data) { + String receivedData = utf8.decode(data); + + setState(() { + sensorData += receivedData; // Append data (sensor might send data in chunks) + }); + + print("📡 Received data: $receivedData"); + }).onDone(() { + // Handle disconnection + print('❌ Disconnected from device'); + setState(() { + isConnected = false; + _connection = null; + }); + }); + } + + // Send data to the device + void _sendData(String data) { + if (_connection != null && _connection!.isConnected) { + _connection!.output.add(utf8.encode(data)); + print("📤 Data sent: $data"); + } else { + print("⚠️ Connection not established"); + } + } + + @override + Widget build(BuildContext context) { + return MaterialApp( + home: Scaffold( + appBar: AppBar(title: Text('Bluetooth HC-05 Controller')), + body: Column( + children: [ + Text( + 'Bluetooth Status: ${_bluetoothState.toString().split('.')[1]}', + style: TextStyle(fontSize: 16), + ), + SizedBox(height: 10), + Text('Available Devices:', style: TextStyle(fontWeight: FontWeight.bold)), + Expanded( + child: ListView.builder( + itemCount: _devicesList.length, + itemBuilder: (context, index) { + final device = _devicesList[index]; + return ListTile( + title: Text(device.name ?? "Unknown Device"), + subtitle: Text(device.address), + trailing: ElevatedButton( + onPressed: isConnecting + ? null + : () => _connectToDevice(device), + child: isConnecting + ? CircularProgressIndicator() + : Text(isConnected && _device?.address == device.address + ? "Connected" + : "Connect"), + ), + ); + }, + ), + ), + TextField( + decoration: InputDecoration(labelText: 'Send Data'), + onChanged: (value) { + setState(() { + dataToSend = value; + }); + }, + ), + ElevatedButton( + onPressed: () => _sendData(dataToSend), + child: Text('Send'), + ), + SizedBox(height: 20), + Text( + 'Sensor Data:', + style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold), + ), + Container( + height: 150, + padding: EdgeInsets.all(8), + decoration: BoxDecoration( + border: Border.all(color: Colors.grey), + ), + child: SingleChildScrollView( + child: Text( + sensorData.isEmpty ? "No data received yet" : sensorData, + style: TextStyle(fontSize: 16), + ), + ), + ), + SizedBox(height: 10), + Expanded(child: Container()), // Just to fill space + ], + ), + ), + ); + } +} diff --git a/app/pubspec.yaml b/app/pubspec.yaml index dc9b5616..1044ac8a 100644 --- a/app/pubspec.yaml +++ b/app/pubspec.yaml @@ -1,34 +1,92 @@ name: flutter_application_1 description: "A new Flutter project." -publish_to: 'none' +# The following line prevents the package from being accidentally published to +# pub.dev using `flutter pub publish`. This is preferred for private packages. +publish_to: 'none' # Remove this line if you wish to publish to pub.dev +# The following defines the version and build number for your application. +# A version number is three numbers separated by dots, like 1.2.43 +# followed by an optional build number separated by a +. +# Both the version and the builder number may be overridden in flutter +# build by specifying --build-name and --build-number, respectively. +# In Android, build-name is used as versionName while build-number used as versionCode. +# Read more about Android versioning at https://developer.android.com/studio/publish/versioning +# In iOS, build-name is used as CFBundleShortVersionString while build-number is used as CFBundleVersion. +# Read more about iOS versioning at +# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html +# In Windows, build-name is used as the major, minor, and patch parts +# of the product and file versions while build-number is used as the build suffix. version: 1.0.0+1 environment: sdk: ^3.7.0 +# Dependencies specify other packages that your package needs in order to work. +# To automatically upgrade your package dependencies to the latest versions +# consider running `flutter pub upgrade --major-versions`. Alternatively, +# dependencies can be manually updated by changing the version numbers below to +# the latest version available on pub.dev. To see which dependencies have newer +# versions available, run `flutter pub outdated`. dependencies: flutter: sdk: flutter + flutter_blue_plus: ^1.35.3 + flutter_bluetooth_serial: ^0.4.0 + sensors_plus: ^3.0.3 + + # The following adds the Cupertino Icons font to your application. + # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.8 - google_sign_in: ^5.4.2 - firebase_auth: ^4.6.0 dev_dependencies: flutter_test: sdk: flutter + + # The "flutter_lints" package below contains a set of recommended lints to + # encourage good coding practices. The lint set provided by the package is + # activated in the `analysis_options.yaml` file located at the root of your + # package. See that file for information about deactivating specific lint + # rules and activating additional ones. flutter_lints: ^5.0.0 +# For information on the generic Dart part of this file, see the +# following page: https://dart.dev/tools/pub/pubspec + +# The following section is specific to Flutter packages. flutter: + + # The following line ensures that the Material Icons font is + # included with your application, so that you can use the icons in + # the material Icons class. uses-material-design: true - - assets: - - assets/images/vr_golf_logo.png - - assets/images/google_icon.png - - assets/images/create_room.png - - assets/images/join_room.png - - assets/images/avatar_setting.png - - assets/images/game_setting.png - - assets/images/help.png + # To add assets to your application, add an assets section, like this: + # assets: + # - images/a_dot_burr.jpeg + # - images/a_dot_ham.jpeg + + # An image asset can refer to one or more resolution-specific "variants", see + # https://flutter.dev/to/resolution-aware-images + + # For details regarding adding assets from package dependencies, see + # https://flutter.dev/to/asset-from-package + # To add custom fonts to your application, add a fonts section here, + # in this "flutter" section. Each entry in this list should have a + # "family" key with the font family name, and a "fonts" key with a + # list giving the asset and other descriptors for the font. For + # example: + # fonts: + # - family: Schyler + # fonts: + # - asset: fonts/Schyler-Regular.ttf + # - asset: fonts/Schyler-Italic.ttf + # style: italic + # - family: Trajan Pro + # fonts: + # - asset: fonts/TrajanPro.ttf + # - asset: fonts/TrajanPro_Bold.ttf + # weight: 700 + # + # For details regarding fonts from package dependencies, + # see https://flutter.dev/to/font-from-package diff --git a/docs/Assets/img/gamearc.jpeg b/docs/Assets/img/gamearc.jpeg new file mode 100644 index 00000000..3a79783c Binary files /dev/null and b/docs/Assets/img/gamearc.jpeg differ diff --git a/docs/index.html b/docs/index.html index e54d3f75..761ba4eb 100644 --- a/docs/index.html +++ b/docs/index.html @@ -43,6 +43,13 @@

VR Multiplayer Golf Game

Compete, socialize, and perfect your swing in an immersive virtual world!

+
+

Introduction

+ + + +
+
@@ -126,6 +133,14 @@

AWS

AWS

We leverage AWS for scalable cloud storage, multiplayer matchmaking, and real-time game hosting.

+ + +
+

Game Architecture

+ gamearc +

Developed Game Architecture which has Game Backend and Game Server using AWS services Mainly Amazon Gamelift.

+
+
diff --git a/docs/styles/index.css b/docs/styles/index.css index 536aae0d..620b7c1f 100644 --- a/docs/styles/index.css +++ b/docs/styles/index.css @@ -675,3 +675,29 @@ tfoot th { padding: 8px 12px; } } +.intro-box { + background: rgba(255, 255, 255, 0.1); + padding: 20px; + border-radius: 10px; + text-align: center; + max-width: 400px; + margin-top: 20px; + box-shadow: 0 4px 10px rgba(255, 255, 255, 0.2); +} + +.watch-button { + background: #00ffcc; + color: black; + border: none; + padding: 10px 20px; + font-size: 1.2rem; + border-radius: 5px; + cursor: pointer; + transition: background 0.3s, transform 0.2s; +} + +.watch-button:hover { + background: #0099aa; + transform: scale(1.05); +} +