-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from WildernessLabs/jorge-samples-updates
Sample updates
- Loading branch information
Showing
47 changed files
with
2,574 additions
and
2,445 deletions.
There are no files selected for viewing
107 changes: 107 additions & 0 deletions
107
Source/Meadow F7 Feather/Bluetooth/MeadowBleLed/Connectivity/BluetoothServer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
using Meadow; | ||
using Meadow.Gateways.Bluetooth; | ||
using MeadowBleLed.Controllers; | ||
|
||
namespace MeadowBleLed.Connectivity; | ||
|
||
public class BluetoothServer | ||
{ | ||
readonly string ON = "73cfbc6f61fa4d80a92feec2a90f8a3e"; | ||
readonly string OFF = "6315119dd61949bba21def9e99941948"; | ||
readonly string PULSING = "d755180131fc435da9941e7f15e17baf"; | ||
readonly string BLINKING = "3a6cc4f2a6ab4709a9bfc9611c6bf892"; | ||
readonly string RUNNING_COLORS = "30df1258f42b4788af2ea8ed9d0b932f"; | ||
|
||
private CommandController commandController; | ||
|
||
ICharacteristic LedOn; | ||
ICharacteristic LedOff; | ||
ICharacteristic LedBlink; | ||
ICharacteristic LedPulse; | ||
ICharacteristic LedRunColors; | ||
|
||
public BluetoothServer() | ||
{ | ||
commandController = Resolver.Services.Get<CommandController>(); | ||
} | ||
|
||
private void LedOnCharacteristicValueSet(ICharacteristic c, object data) | ||
{ | ||
commandController.FireLedOn(); | ||
} | ||
|
||
private void LedOffCharacteristicValueSet(ICharacteristic c, object data) | ||
{ | ||
commandController.FireLedOff(); | ||
} | ||
|
||
private void LedBlinkCharacteristicValueSet(ICharacteristic c, object data) | ||
{ | ||
commandController.FireLedBlink(); | ||
} | ||
|
||
private void LedPulseCharacteristicValueSet(ICharacteristic c, object data) | ||
{ | ||
commandController.FireLedPulse(); | ||
} | ||
|
||
private void LedRunColorsCharacteristicValueSet(ICharacteristic c, object data) | ||
{ | ||
commandController.FireLedRunColors(); | ||
} | ||
|
||
public Definition GetDefinition() | ||
{ | ||
LedOn = new CharacteristicBool( | ||
name: nameof(LedOn), | ||
uuid: ON, | ||
permissions: CharacteristicPermission.Read | CharacteristicPermission.Write, | ||
properties: CharacteristicProperty.Read | CharacteristicProperty.Write); | ||
LedOn.ValueSet += LedOnCharacteristicValueSet; | ||
|
||
LedOff = new CharacteristicBool( | ||
name: nameof(LedOff), | ||
uuid: OFF, | ||
permissions: CharacteristicPermission.Read | CharacteristicPermission.Write, | ||
properties: CharacteristicProperty.Read | CharacteristicProperty.Write); | ||
LedOff.ValueSet += LedOffCharacteristicValueSet; | ||
|
||
LedBlink = new CharacteristicBool( | ||
name: nameof(LedBlink), | ||
uuid: BLINKING, | ||
permissions: CharacteristicPermission.Read | CharacteristicPermission.Write, | ||
properties: CharacteristicProperty.Read | CharacteristicProperty.Write); | ||
LedBlink.ValueSet += LedBlinkCharacteristicValueSet; | ||
|
||
LedPulse = new CharacteristicBool( | ||
name: nameof(LedPulse), | ||
uuid: PULSING, | ||
permissions: CharacteristicPermission.Read | CharacteristicPermission.Write, | ||
properties: CharacteristicProperty.Read | CharacteristicProperty.Write); | ||
LedPulse.ValueSet += LedPulseCharacteristicValueSet; | ||
|
||
LedRunColors = new CharacteristicBool( | ||
name: nameof(LedRunColors), | ||
uuid: RUNNING_COLORS, | ||
permissions: CharacteristicPermission.Read | CharacteristicPermission.Write, | ||
properties: CharacteristicProperty.Read | CharacteristicProperty.Write); | ||
LedRunColors.ValueSet += LedRunColorsCharacteristicValueSet; | ||
|
||
ICharacteristic[] characteristics = | ||
{ | ||
LedOn, | ||
LedOff, | ||
LedBlink, | ||
LedPulse, | ||
LedRunColors | ||
}; | ||
|
||
var service = new Service( | ||
name: "Service", | ||
uuid: 253, | ||
characteristics | ||
); | ||
|
||
return new Definition("MeadowRGB", service); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
Source/Meadow F7 Feather/Bluetooth/MeadowBleLed/Controllers/CommandController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using Meadow; | ||
using System; | ||
|
||
namespace MeadowBleLed.Controllers; | ||
|
||
public class CommandController | ||
{ | ||
public event EventHandler<bool> LedOnValueSet = default!; | ||
public event EventHandler<bool> LedOffValueSet = default!; | ||
public event EventHandler<bool> LedBlinkValueSet = default!; | ||
public event EventHandler<bool> LedPulseValueSet = default!; | ||
public event EventHandler<bool> LedRunColorsValueSet = default!; | ||
|
||
public CommandController() | ||
{ | ||
Resolver.Services.Add(this); | ||
} | ||
|
||
public void FireLedOn() | ||
{ | ||
LedOnValueSet?.Invoke(this, true); | ||
} | ||
|
||
public void FireLedOff() | ||
{ | ||
LedOffValueSet?.Invoke(this, true); | ||
} | ||
|
||
public void FireLedBlink() | ||
{ | ||
LedBlinkValueSet?.Invoke(this, true); | ||
} | ||
|
||
public void FireLedPulse() | ||
{ | ||
LedPulseValueSet?.Invoke(this, true); | ||
} | ||
|
||
public void FireLedRunColors() | ||
{ | ||
LedRunColorsValueSet?.Invoke(this, true); | ||
} | ||
} |
13 changes: 6 additions & 7 deletions
13
Source/Meadow F7 Feather/Bluetooth/MeadowBleLed/Controllers/LedController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
Source/Meadow F7 Feather/Bluetooth/MeadowBleLed/Controllers/MainController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using Meadow; | ||
using Meadow.Devices; | ||
using Meadow.Gateways; | ||
using MeadowBleLed.Connectivity; | ||
|
||
namespace MeadowBleLed.Controllers; | ||
|
||
public class MainController | ||
{ | ||
private IBluetoothAdapter bluetooth; | ||
|
||
private LedController ledController; | ||
private BluetoothServer bluetoothServer; | ||
private CommandController commandController; | ||
|
||
public MainController(F7FeatherV2 hardware, IBluetoothAdapter bluetooth) | ||
{ | ||
this.bluetooth = bluetooth; | ||
|
||
commandController = new CommandController(); | ||
|
||
ledController = new LedController(hardware.Pins.OnboardLedRed, hardware.Pins.OnboardLedGreen, hardware.Pins.OnboardLedBlue); | ||
//ledController = new LedController(hardware.Pins.D12, hardware.Pins.D11, hardware.Pins.D12); | ||
|
||
StartBluetoothServer(); | ||
} | ||
|
||
private void StartBluetoothServer() | ||
{ | ||
bluetoothServer = new BluetoothServer(); | ||
|
||
var definition = bluetoothServer.GetDefinition(); | ||
bluetooth.StartBluetoothServer(definition); | ||
|
||
commandController.LedOnValueSet += (s, e) => | ||
{ | ||
Resolver.Log.Info("LedOnValueSet"); | ||
ledController.TurnOn(); | ||
}; | ||
commandController.LedOffValueSet += (s, e) => | ||
{ | ||
Resolver.Log.Info("LedOffValueSet"); | ||
ledController.TurnOff(); | ||
}; | ||
commandController.LedBlinkValueSet += (s, e) => | ||
{ | ||
Resolver.Log.Info("LedBlinkValueSet"); | ||
ledController.StartBlink(); | ||
}; | ||
commandController.LedPulseValueSet += (s, e) => | ||
{ | ||
Resolver.Log.Info("LedPulseValueSet"); | ||
ledController.StartPulse(); | ||
}; | ||
commandController.LedRunColorsValueSet += (s, e) => | ||
{ | ||
Resolver.Log.Info("LedRunColorsValueSet"); | ||
ledController.StartRunningColors(); | ||
}; | ||
} | ||
} |
69 changes: 4 additions & 65 deletions
69
Source/Meadow F7 Feather/Bluetooth/MeadowBleLed/MeadowApp.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,21 @@ | ||
using Meadow; | ||
using Meadow.Devices; | ||
using Meadow.Gateways.Bluetooth; | ||
using MeadowBleLed.Controller; | ||
using MeadowBleLed.Controllers; | ||
using System.Threading.Tasks; | ||
|
||
namespace MeadowBleLed; | ||
|
||
// public class MeadowApp : App<F7FeatherV1> <- If you have a Meadow F7v1.* | ||
public class MeadowApp : App<F7FeatherV2> | ||
{ | ||
LedController ledController; | ||
|
||
readonly string ON = "73cfbc6f61fa4d80a92feec2a90f8a3e"; | ||
readonly string OFF = "6315119dd61949bba21def9e99941948"; | ||
readonly string PULSING = "d755180131fc435da9941e7f15e17baf"; | ||
readonly string BLINKING = "3a6cc4f2a6ab4709a9bfc9611c6bf892"; | ||
readonly string RUNNING_COLORS = "30df1258f42b4788af2ea8ed9d0b932f"; | ||
|
||
IDefinition bleTreeDefinition; | ||
|
||
ICharacteristic On; | ||
ICharacteristic Off; | ||
ICharacteristic StartPulse; | ||
ICharacteristic StartBlink; | ||
ICharacteristic StartRunningColors; | ||
|
||
public override Task Initialize() | ||
{ | ||
ledController = new LedController(); | ||
|
||
ledController.SetColor(Color.Red); | ||
Resolver.Log.Info("Initialize..."); | ||
|
||
bleTreeDefinition = GetDefinition(); | ||
Device.BluetoothAdapter.StartBluetoothServer(bleTreeDefinition); | ||
var ble = Device.BluetoothAdapter; | ||
|
||
On.ValueSet += (s, e) => { ledController.TurnOn(); }; | ||
Off.ValueSet += (s, e) => { ledController.TurnOff(); }; | ||
StartPulse.ValueSet += (s, e) => { ledController.StartPulse(); }; | ||
StartBlink.ValueSet += (s, e) => { ledController.StartBlink(); }; | ||
StartRunningColors.ValueSet += (s, e) => { ledController.StartRunningColors(); }; | ||
|
||
ledController.SetColor(Color.Green); | ||
var mainController = new MainController(Device, ble); | ||
|
||
return base.Initialize(); | ||
} | ||
|
||
Definition GetDefinition() | ||
{ | ||
var service = new Service( | ||
name: "MeadowRGBService", | ||
uuid: 253, | ||
On = new CharacteristicBool( | ||
name: nameof(On), | ||
uuid: ON, | ||
permissions: CharacteristicPermission.Read | CharacteristicPermission.Write, | ||
properties: CharacteristicProperty.Read | CharacteristicProperty.Write), | ||
Off = new CharacteristicBool( | ||
name: nameof(Off), | ||
uuid: OFF, | ||
permissions: CharacteristicPermission.Read | CharacteristicPermission.Write, | ||
properties: CharacteristicProperty.Read | CharacteristicProperty.Write), | ||
StartPulse = new CharacteristicBool( | ||
name: nameof(StartPulse), | ||
uuid: PULSING, | ||
permissions: CharacteristicPermission.Read | CharacteristicPermission.Write, | ||
properties: CharacteristicProperty.Read | CharacteristicProperty.Write), | ||
StartBlink = new CharacteristicBool( | ||
name: nameof(StartBlink), | ||
uuid: BLINKING, | ||
permissions: CharacteristicPermission.Read | CharacteristicPermission.Write, | ||
properties: CharacteristicProperty.Read | CharacteristicProperty.Write), | ||
StartRunningColors = new CharacteristicBool( | ||
name: nameof(StartRunningColors), | ||
uuid: RUNNING_COLORS, | ||
permissions: CharacteristicPermission.Read | CharacteristicPermission.Write, | ||
properties: CharacteristicProperty.Read | CharacteristicProperty.Write) | ||
); | ||
|
||
return new Definition("MeadowRGB", service); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"v":"1.0","osVersion":"1.9.0.0"} | ||
{"v":"1.0","osVersion":"1.10.0.2"} |
File renamed without changes.
Oops, something went wrong.