-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMeadowApp.cs
86 lines (68 loc) · 2.12 KB
/
MeadowApp.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using Meadow;
using Meadow.Devices;
using Meadow.Foundation.Leds;
using Meadow.Hardware;
using Meadow.Logging;
using Meadow.Units;
using System;
using System.Threading;
using System.Threading.Tasks;
namespace CoreComputeBreakout;
public class MeadowApp : App<F7CoreComputeV2>
{
private Logger _logger;
private SPIDisplay _spiDisplay;
private I2CDisplay _i2cDisplay;
private IPwmPort _led;
private PwmLed _pwm;
public MeadowApp()
{
Initialize();
var test = new CcmPinTests(Device, _logger);
_ = Task.Run(() => BlinkyProc());
_ = Task.Run(() => SpiDisplayProc());
_ = Task.Run(() => test.TestPulsePWMs(Device, 10));
}
private void BlinkyProc()
{
_i2cDisplay.ShowText("LED", 0);
while (true)
{
CcmPinTests.PulsePwm(
_led,
() => _i2cDisplay.ShowText("Increase", 1),
() => _i2cDisplay.ShowText("Decrease", 1));
}
}
private void SpiDisplayProc()
{
while (true)
{
var now = DateTime.Now.ToString("HH:mm:ss"); ;
_logger.Info($"now: {now}");
_spiDisplay.ShowText(now, 1);
Thread.Sleep(1000);
}
}
void Initialize()
{
_logger = new Logger(new ConsoleLogProvider());
_logger.Info("Initialize hardware...");
var i2cdisplaybus = 3;
_logger.Info($"Creating I2C display on bus {i2cdisplaybus}...");
_i2cDisplay = new I2CDisplay(
Device.CreateI2cBus(i2cdisplaybus),
_logger);
var spidisplaybus = 5;
_logger.Info($"Creating SPI display on bus {spidisplaybus}...");
var spi = Device.CreateSpiBus();
_spiDisplay = new SPIDisplay(
spi,
Device.Pins.D17, // cs
Device.Pins.D18, // dc
Device.Pins.D19, // res
_logger);
_led = Device.CreatePwmPort(Device.Pins.D20, new Frequency(500, Frequency.UnitType.Hertz), dutyCycle: 0);
_led.Start();
}
}