Skip to content

Commit

Permalink
renamed adapter state classes; moved smapleapp dir; added logo
Browse files Browse the repository at this point in the history
  • Loading branch information
Malachi Griffie committed Mar 31, 2017
1 parent 956aae4 commit 669b3e1
Show file tree
Hide file tree
Showing 67 changed files with 465 additions and 521 deletions.
314 changes: 154 additions & 160 deletions ble.net.api.sln → ble.net.sln

Large diffs are not rendered by default.

Binary file added etc/logo_64x64.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
112 changes: 112 additions & 0 deletions src/ble.net.sampleapp-android/MyApplication.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// Copyright Malachi Griffie
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

using System;
using System.Linq;
using System.Reflection;
using Acr.UserDialogs;
using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.OS;
using Android.Runtime;
using nexus.core;
using nexus.core.logging;
using nexus.protocols.ble;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using Application = Android.App.Application;
using Log = Android.Util.Log;

namespace ble.net.sampleapp.android
{
[Application( Debuggable = IS_DEBUG, AllowBackup = true, AllowClearUserData = true )]
public class MyApplication : Application
{
public const Boolean IS_DEBUG =
#if DEBUG
true;
#else
false;
#endif

protected MyApplication( IntPtr javaReference, JniHandleOwnership transfer )
: base( javaReference, transfer )
{
}

public override void OnCreate()
{
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
// ReSharper disable once InvertIf
if(IS_DEBUG)
{
//
// dump all entries to Android system log in debug mode
//
SystemLog.Instance.Id = Assembly.GetAssembly( GetType() ).GetName().Name;
SystemLog.Instance.AddSink(
entry =>
{
var message = entry.FormatMessageAndArguments() + " " +
entry.Data.Select( x => x?.ToString() + "" ).Join( " " );
switch(entry.Severity)
{
case LogLevel.Error:

Log.Error( entry.LogId, message );
break;
case LogLevel.Warn:
Log.Warn( entry.LogId, message );
break;
case LogLevel.Info:
Log.Info( entry.LogId, message );
break;
default:
Log.Debug( entry.LogId, message );
break;
}
} );
}
}
}

[Activity( Label = "BLE.net Sample App", Theme = "@style/MainTheme", MainLauncher = false,
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation )]
public class MainActivity : FormsAppCompatActivity
{
protected override void OnActivityResult( Int32 requestCode, Result resultCode, Intent data )
{
BluetoothLowEnergyAdapter.OnActivityResult( requestCode, resultCode, data );
}

protected override void OnCreate( Bundle bundle )
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;

base.OnCreate( bundle );

BluetoothLowEnergyAdapter.Init( this );
UserDialogs.Init( this );
Forms.Init( this, bundle );

LoadApplication(
new FormsApp( BluetoothLowEnergyAdapter.ObtainDefaultAdapter( ApplicationContext ), UserDialogs.Instance ) );
}
}

[Activity( Theme = "@style/MainTheme", MainLauncher = true, NoHistory = true )]
public class SplashActivity : Activity
{
protected override void OnCreate( Bundle bundle )
{
base.OnCreate( bundle );
StartActivity( typeof(MainActivity) );
Finish();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<AndroidResgenFile>Resources\Resource.Designer.cs</AndroidResgenFile>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
<AndroidUseLatestPlatformSdk>true</AndroidUseLatestPlatformSdk>
<AndroidUseLatestPlatformSdk>False</AndroidUseLatestPlatformSdk>
<TargetFrameworkVersion>v6.0</TargetFrameworkVersion>
<AndroidSupportedAbis>armeabi,armeabi-v7a,x86</AndroidSupportedAbis>
<OutputPath>..\..\artifacts\bin\$(AssemblyName)\$(Configuration)\$(Platform)</OutputPath>
Expand Down Expand Up @@ -164,7 +164,6 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="MainActivity.cs" />
<Compile Include="MyApplication.cs" />
<Compile Include="Resources\Resource.Designer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand All @@ -180,19 +179,19 @@
<AndroidResource Include="Resources\layout\Toolbar.axml" />
<AndroidResource Include="Resources\values\styles.xml" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ble.net.sampleapp\ble.net.sampleapp.csproj">
<Project>{fa5cbcee-02ba-473d-bbc4-981add364135}</Project>
<Name>ble.net.sampleapp</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="Assets\" />
<Folder Include="Resources\drawable-hdpi\" />
<Folder Include="Resources\drawable-xhdpi\" />
<Folder Include="Resources\drawable-xxhdpi\" />
<Folder Include="Resources\drawable\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ble.net.sampleapp\ble.net.sampleapp.csproj">
<Project>{9e4d7784-b138-4cd6-9b55-2ba70648ac93}</Project>
<Name>ble.net.sampleapp</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
<Import Project="..\..\lib\packages\Xamarin.Android.Support.Vector.Drawable.23.3.0\build\Xamarin.Android.Support.Vector.Drawable.targets" Condition="Exists('..\..\lib\packages\Xamarin.Android.Support.Vector.Drawable.23.3.0\build\Xamarin.Android.Support.Vector.Drawable.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<package id="AndHUD" version="1.2.0" targetFramework="monoandroid60" />
<package id="ble.net" version="0.11.7" targetFramework="monoandroid60" />
<package id="ble.net-android" version="0.11.7" targetFramework="monoandroid60" />
<package id="DotNet.Contracts" version="1.10.20606.1" targetFramework="monoandroid60" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="monoandroid60" />
<package id="nexus.core" version="0.26.3" targetFramework="monoandroid60" />
<package id="Nito.AsyncEx" version="3.0.1" targetFramework="monoandroid60" />
Expand Down
File renamed without changes.
68 changes: 68 additions & 0 deletions src/ble.net.sampleapp-ios/MyApplication.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright Malachi Griffie
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

using System;
using System.Linq;
using System.Reflection;
using Acr.UserDialogs;
using Foundation;
using nexus.core;
using nexus.core.logging;
using nexus.protocols.ble;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;

namespace ble.net.sampleapp.ios
{
public class MyApplication
{
public const Boolean IS_DEBUG =
#if DEBUG
true;
#else
false;
#endif

internal static void Main( String[] args )
{
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
if(IS_DEBUG)
{
#pragma warning disable 162
SystemLog.Instance.Id = Assembly.GetAssembly( typeof(MyApplication) ).GetName().Name;
SystemLog.Instance.AddSink(
entry =>
{
var message = entry.FormatMessageAndArguments() + " " +
entry.Data.Select( x => x?.ToString() + "" ).Join( " " );
if(entry.Severity == LogLevel.Error)
{
Console.Error.WriteLine( message );
}
else
{
Console.Out.WriteLine( message );
}
} );
#pragma warning restore 162
}

UIApplication.Main( args, null, nameof( AppDelegate ) );
}
}

[Register( "AppDelegate" )]
public class AppDelegate : FormsApplicationDelegate
{
public override Boolean FinishedLaunching( UIApplication app, NSDictionary options )
{
Forms.Init();
LoadApplication( new FormsApp( BluetoothLowEnergyAdapter.ObtainDefaultAdapter(), UserDialogs.Instance ) );
return base.FinishedLaunching( app, options );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@
<CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
</PropertyGroup>
<ItemGroup>
<Compile Include="Application.cs" />
<Compile Include="AppDelegate.cs" />
<Compile Include="MyApplication.cs" />
<None Include="Entitlements.plist" />
<None Include="Info.plist" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down Expand Up @@ -145,7 +144,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ble.net.sampleapp\ble.net.sampleapp.csproj">
<Project>{fa5cbcee-02ba-473d-bbc4-981add364135}</Project>
<Project>{9e4d7784-b138-4cd6-9b55-2ba70648ac93}</Project>
<Name>ble.net.sampleapp</Name>
</ProjectReference>
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<package id="Acr.UserDialogs" version="6.3.7" targetFramework="xamarinios10" />
<package id="ble.net" version="0.11.7" targetFramework="xamarinios10" />
<package id="ble.net-ios" version="0.11.7" targetFramework="xamarinios10" />
<package id="DotNet.Contracts" version="1.10.20606.1" targetFramework="xamarinios10" />
<package id="nexus.core" version="0.26.3" targetFramework="xamarinios10" />
<package id="Splat" version="1.6.2" targetFramework="xamarinios10" />
<package id="Xamarin.Forms" version="2.3.3.180" targetFramework="xamarinios10" />
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
using ble.net.sampleapp.viewmodel;
using nexus.protocols.ble;
using Xamarin.Forms;
// ReSharper disable RedundantUsingDirective
using Microsoft.Azure.Mobile;
using Microsoft.Azure.Mobile.Analytics;
using Microsoft.Azure.Mobile.Crashes;
// ReSharper restore RedundantUsingDirective

namespace ble.net.sampleapp
{
Expand All @@ -28,18 +33,29 @@ public FormsApp( IBluetoothLowEnergyAdapter adapter, IUserDialogs dialogs )
async p =>
{
bleGattServerViewModel.Update( (BlePeripheralViewModel)p );
await
m_root.PushAsync(
new BleGattServerPage(
model: bleGattServerViewModel,
bleServiceSelectedCommand:
new Command(
async s =>
{
await m_root.PushAsync( new BleGattServicePage( (BleGattServiceViewModel)s ) );
} ) ) );
await m_root.PushAsync(
new BleGattServerPage(
model: bleGattServerViewModel,
bleServiceSelectedCommand:
new Command(
async s =>
{
await m_root.PushAsync( new BleGattServicePage( (BleGattServiceViewModel)s ) );
} ) ) );
} ) ) );
MainPage = m_root;
}

/// <inheritdoc />
protected override void OnStart()
{
base.OnStart();
#if RELEASE
MobileCenter.Start(
"ios=6b6689d5-0d94-476a-a632-81145dde8706;android=56864a4d-0dc3-4ab8-819b-bb5d412ba595",
typeof(Analytics),
typeof(Crashes) );
#endif
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<DefineConstants>TRACE</DefineConstants>
<DefineConstants>TRACE;RELEASE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
Expand Down Expand Up @@ -78,6 +78,18 @@
<HintPath>..\..\lib\packages\ble.net.0.11.7\lib\portable45-net45+win8\ble.net.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Azure.Mobile, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\lib\packages\Microsoft.Azure.Mobile.0.7.0\lib\portable-net45+wp8+wpa81+win8+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Microsoft.Azure.Mobile.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Azure.Mobile.Analytics, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\lib\packages\Microsoft.Azure.Mobile.Analytics.0.7.0\lib\portable-net45+wp8+wpa81+win8+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Microsoft.Azure.Mobile.Analytics.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Azure.Mobile.Crashes, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\lib\packages\Microsoft.Azure.Mobile.Crashes.0.7.0\lib\portable-net45+wp8+wpa81+win8+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Microsoft.Azure.Mobile.Crashes.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="nexus.core, Version=0.26.3.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\lib\packages\nexus.core.0.26.3\lib\portable45-net45+win8\nexus.core.dll</HintPath>
<Private>True</Private>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
<packages>
<package id="Acr.UserDialogs" version="6.3.7" targetFramework="portable45-net45+win8" />
<package id="ble.net" version="0.11.7" targetFramework="portable45-net45+win8" />
<package id="DotNet.Contracts" version="1.10.20606.1" targetFramework="portable45-net45+win8" />
<package id="Microsoft.Azure.Mobile" version="0.7.0" targetFramework="portable45-net45+win8" />
<package id="Microsoft.Azure.Mobile.Analytics" version="0.7.0" targetFramework="portable45-net45+win8" />
<package id="Microsoft.Azure.Mobile.Crashes" version="0.7.0" targetFramework="portable45-net45+win8" />
<package id="nexus.core" version="0.26.3" targetFramework="portable45-net45+win8" />
<package id="Splat" version="1.6.2" targetFramework="portable45-net45+win8" />
<package id="Xamarin.Forms" version="2.3.3.180" targetFramework="portable45-net45+win8+wp8+wpa81" />
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
HorizontalOptions="FillAndExpand">
<Label Text="{Binding Name}"
HorizontalOptions="StartAndExpand" />
<Label Text="{Binding Signal}"
<Label Text="{Binding Rssi}"
HorizontalOptions="End"
MinimumWidthRequest="30" />
</StackLayout>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public String Manufacturer

public Int32 Rssi => Model.Rssi;

public String Signal => Model.Rssi + (Model.Advertisement.TxPowerLevel > 0 ? "+" + Model.Advertisement.TxPowerLevel : "");
public String Signal => Model.Rssi + "+" + Model.Advertisement.TxPowerLevel;

public override Boolean Equals( Object other )
{
Expand All @@ -74,6 +74,18 @@ public override Int32 GetHashCode()
public void Update( IBlePeripheral device )
{
Advertisement = Model.Advertisement.ToString();
//Log.Debug(
// "Updating peripheral. name={0} flags={1} services={2} mfg={3} data={4} tx={5} service-data={6}",
// device.Advertisement?.DeviceName,
// device.Advertisement?.Flags,
// device.Advertisement?.Services.Select( x => x.ToString() ).Join( "," ),
// device.Advertisement?.ManufacturerSpecificData.Select(
// x => x.CompanyId + "|" + x.Data?.ToArray()?.EncodeToBase16String() ).Join( "," ),
// device.Advertisement?.RawData.Select( x => x.Type + "|" + x.Data?.ToArray()?.EncodeToBase16String() )
// .Join( "," ),
// device.Advertisement?.TxPowerLevel,
// device.Advertisement?.ServiceData.Select( x => x.Key + "|" + x.Value?.ToArray()?.EncodeToBase16String() )
// .Join( "," ) );

RaisePropertyChanged( nameof( Rssi ) );
RaisePropertyChanged( nameof( Name ) );
Expand Down
Loading

0 comments on commit 669b3e1

Please sign in to comment.