Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Features/sotware/app #50

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
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
181 changes: 181 additions & 0 deletions app/lib/screens/ble2.dart
Original file line number Diff line number Diff line change
@@ -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<MyApp> {
BluetoothState _bluetoothState = BluetoothState.UNKNOWN;
BluetoothDevice? _device;
BluetoothConnection? _connection;
String dataToSend = "";
String sensorData = ""; // Received data (we will update this)

List<BluetoothDevice> _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
],
),
),
);
}
}
82 changes: 70 additions & 12 deletions app/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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
Binary file added docs/Assets/img/gamearc.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@
<h1>VR Multiplayer Golf Game</h1>
<p>Compete, socialize, and perfect your swing in an immersive virtual world!</p>
</div>
<div class="intro-box">
<h2>Introduction</h2>
<a href="https://youtu.be/Lre_sJt9n2I" target="_blank">
<button class="watch-button">Watch on YouTube</button>
</a>
</div>

</section>

<section id="about" class="full-screen about">
Expand Down Expand Up @@ -126,6 +133,14 @@ <h3>AWS</h3>
<img src="Assets/img/implementation/aws.jpg" alt="AWS">
<p>We leverage AWS for scalable cloud storage, multiplayer matchmaking, and real-time game hosting.</p>
</div>

<!-- GAME ARCHITECTURE -->
<div class="implementation-column">
<h3>Game Architecture</h3>
<img src="Assets/img/gamearc.jpeg" alt="gamearc">
<p>Developed Game Architecture which has Game Backend and Game Server using AWS services Mainly Amazon Gamelift.</p>
</div>

</div>
</div>
</section>
Expand Down
26 changes: 26 additions & 0 deletions docs/styles/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}