private void OnNfc(object sender, RoutedEventArgs e) { BluetoothAddress btAddress = new BluetoothAddress(new byte[] { 252, 27, 32, 49, 211, 152, 0, 0 }); BluetoothHandler.MakeConnection(btAddress); bluetoothIndicator.Fill = !BluetoothHandler.IsConnected() ? new SolidColorBrush(Colors.Red) : new SolidColorBrush(Colors.Green); }
private void OnBarcodeClick(object sender, RoutedEventArgs e) { try { var str = BluetoothHandler.GetStrFromBluetooth().Trim('\0').Split(','); long medicineCode = long.Parse(str[0]); string medicineName = str[1]; int month = int.Parse(str[2].Substring(0, 2)); int year = int.Parse(str[2].Substring(2, 4)); var medicine = new Medicine(medicineName, new DateTime(year, month, 1), medicineCode); List <Medicine> medicines = Dict; Predicate <Medicine> medicineFinder = m => { return(m.Code == medicineCode); }; if (medicines.Exists(medicineFinder)) { UpdateCounter(medicine, this); return; } medicines.Add(medicine); RowAdder.AddRow(medicine, this, medicines.Count, OnClickCheckBox); } catch (Exception exception) { bluetoothIndicator.Fill = new SolidColorBrush(Colors.Red); Console.WriteLine(exception); BluetoothHandler.Close(); } }
private async void mainInsertBTN_ClickAsync(object sender, EventArgs e) { int n = 0; try { SqlConnection connection = new SqlConnection( "Data Source = smartclosetdatabase.database.windows.net; Initial Catalog = smartclosetdb; User ID = HAGATZAR; Password = SCAMO236###; Connect Timeout = 30; Encrypt = True; TrustServerCertificate = False; ApplicationIntent = ReadWrite; MultiSubnetFailover = False;"); connection.Open(); SqlCommand command = new SqlCommand("(select min(CELLNUM) from (SELECT CELLNUM FROM CELLS except (SELECT CELLNUM FROM ITEMS WHERE username = '******' and incloset = 1)) diff)", connection); SqlDataReader reader = command.ExecuteReader(); Console.WriteLine("test1:{0}", reader); if (reader.HasRows) { reader.Read(); n = reader.GetInt32(0); } else { Console.WriteLine("No rows found."); } reader.Close(); } catch (SqlException err) { // Console.WriteLine(err); //todo } await BluetoothHandler.sendAsync(n - 1); Android.Content.Intent insert = new Android.Content.Intent(this, typeof(insertMainActivity)); insert.PutExtra("username", username); insert.PutExtra("currCell", n); StartActivity(insert); }
private void ConnectToBluetoothDevice() { ICollection <BluetoothDevice> pairedDevices = btAdapter.BondedDevices; if (pairedDevices.Count > 0) { foreach (BluetoothDevice device in pairedDevices) { string name = device.Name; string address = device.Address; Logger.Log($"Name: {name}\nAddress: {address}"); if (name == "AKO SI BLUETOOTH") { btDevice = device; break; } } } // TODO AUTO ON NARIN UNG BLUETOOTH BAGO GAWIN TO PARA DIRE-DIRETSO handler = new BluetoothHandler(this); btService = new BluetoothService(this, handler); btService.BtUUID = btDevice.GetUuids()[0].Uuid; // connect na //btService.StartClient(btDevice); }
protected override void OnStart() { base.OnStart(); handler = new BluetoothHandler(this); btService = new BluetoothService(this, handler); TurnOnBluetooth(); }
private async void mainDoneBTN_ClickAsync(object sender, EventArgs e) { if (n != 1) { await BluetoothHandler.sendAsync(9 - n); } Android.Content.Intent main2 = new Android.Content.Intent(this, typeof(MainActivity2)); main2.PutExtra("username", username); StartActivity(main2); }
public GattCallback(Bluetooth parent, ConnectionSource connection) { _parent = parent; _identifier = Encoding.UTF8.GetBytes(parent._identifier); _handler = new BluetoothHandler(connection) { DisconnectDevice = Disconnect, WriteValue = WriteValue, UpdateStatus = _parent.OnStatusUpdated, }; }
public PeripheralDelegate(Bluetooth parent, ConnectionSource connection) { _manager = parent._manager; _parent = parent; _adapterName = UIDevice.CurrentDevice.Name; _handler = new BluetoothHandler(connection) { WriteValue = WriteValue, DisconnectDevice = Disconnect, UpdateStatus = _parent.OnStatusUpdated, }; }
private void speechRecognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e) { var firstWord = e.Result.Words[0].Text.ToLower(); if (e.Result.Words.Count != 2 && firstWord != "medicine") { return; } var medicineName = e.Result.Words[1].Text.ToLower(); Medicine medicine = new Medicine(); for (int index = 0; index < _medicineList.MedicineVal.Count; index++) { medicine = _medicineList.MedicineVal[index]; if (medicine.Name.ToLower() != medicineName) { continue; } MedicineLbl.Content = medicineName.ToUpper(); UsagesText.Text = medicine.UserDesc; DangersText.Text = medicine.DangersDesc; if (medicine.ImagePath == string.Empty) { return; } BitmapImage bitImage = new BitmapImage(); bitImage.BeginInit(); bitImage.UriSource = new Uri(medicine.ImagePath); bitImage.EndInit(); ImageContent.Source = bitImage; break; } if (_medicineInfoDict.ContainsKey(medicine.Code) && BluetoothHandler.IsConnected()) { BluetoothHandler.SendAnglesToLaser(_medicineInfoDict[medicine.Code].DeltaAngle); Console.WriteLine("Got this medicine: {0}", medicine.Name); } _speechRecognizer.SpeechRecognized += speechRecognizer_SpeechRecognized; }
private void OnLaser(object sender, RoutedEventArgs e) { BluetoothAddress btAddress = new BluetoothAddress(new byte[] { 17, 71, 48, 49, 211, 152, 0, 0 }); BluetoothHandler.MakeConnection(btAddress); if (!BluetoothHandler.IsConnected()) { bluetoothIndicator.Fill = new SolidColorBrush(Colors.Red); } else { bluetoothIndicator.Fill = new SolidColorBrush(Colors.Green); } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); Xamarin.Essentials.Platform.Init(this, savedInstanceState); // Set our view from the "main" layout resource SetContentView(Resource.Layout.activity_main); Button signInBTN = FindViewById <Button>(Resource.Id.button1); Button signUpBTN = FindViewById <Button>(Resource.Id.button2); signInBTN.Click += mainSignInBTN_Click; signUpBTN.Click += mainSignUpBTN_Click; TextView connected = FindViewById <TextView>(Resource.Id.textView1); BluetoothHandler.connect(); connected.Text = "Connected"; }
private async void onClick(int curCell) { await BluetoothHandler.sendAsync(cellArr[curCell - 1] - 1); try { SqlConnection connection = new SqlConnection( "Data Source = smartclosetdatabase.database.windows.net; Initial Catalog = smartclosetdb; User ID = HAGATZAR; Password = SCAMO236###; Connect Timeout = 30; Encrypt = True; TrustServerCertificate = False; ApplicationIntent = ReadWrite; MultiSubnetFailover = False;"); connection.Open(); SqlCommand command = new SqlCommand("UPDATE items SET incloset = 0, numofselects = numofselects + 1, lastact=GetDate() WHERE incloset = 1 and username = '******' and cellnum = " + cellArr[curCell - 1] + "; ", connection); SqlDataReader reader = command.ExecuteReader(); } catch (SqlException err) { Console.WriteLine(err); //todo } Android.Content.Intent done = new Android.Content.Intent(this, typeof(DoneActivity)); done.PutExtra("username", username); done.PutExtra("currCell", cellArr[curCell - 1]); StartActivity(done); }
public override void OnViewCreated(View view, Bundle savedInstanceState) { base.OnViewCreated(view, savedInstanceState); // Bluetooth On/Off Switch btSwitch = view.FindViewById <Switch> (Resource.Id.swt_cli_dev_bt); btSwitch.CheckedChange += OnBluetoothSwitchChanged; // Bluetooth Connect Button btnConnect = view.FindViewById <Button>(Resource.Id.btn_cli_dev_connect); btnConnect.Click += OnBluetoothConnectClicked; // Bluetooth Discover Devices Button //btnDiscover = view.FindViewById <Button> (Resource.Id.btn_cli_dev_discover); //btnDiscover.Click += OnBluetoothDiscoverClicked; // Get default bluetooth adapter btAdapter = BluetoothAdapter.DefaultAdapter; ICollection <BluetoothDevice> pairedDevices = btAdapter.BondedDevices; if (pairedDevices.Count > 0) { foreach (BluetoothDevice device in pairedDevices) { string name = device.Name; string address = device.Address; Logger.Log($"Name: {name}\nAddress: {address}"); if (name == "AKO SI BLUETOOTH") { btDevice = device; } } } handler = new BluetoothHandler(this); btService = new BluetoothService(this.Context, handler); }
public void Dispose() { BluetoothHandler.Close(); }