forked from nanoframework/Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
147 lines (123 loc) · 4.9 KB
/
Program.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
using System;
using System.Diagnostics;
using System.Threading;
using nanoFramework.Hardware.Esp32;
namespace Test
{
public class Program
{
/// <summary>
/// This example shows how to use change default pins for devices and to use the Sleep methods in the
/// nanoFramework.Hardware.Esp32 nuget package.
///
/// Putting the Esp32 into deep sleep mode and starting after timer expires.
///
/// Other examples of Deep sleep are commented out
/// </summary>
public static void Main()
{
// How to set Alternate pins for Devices ( COM1/2/3, SPI1/2, I2C, PWM ) then open device as normal
Configuration.SetPinFunction(33, DeviceFunction.COM2_RX);
Configuration.SetPinFunction(32, DeviceFunction.COM2_TX);
// Sleep Test
Debug.WriteLine("ESP32 Sleep test started");
Debug.WriteLine("Check wakeup cause");
Sleep.WakeupCause cause = Sleep.GetWakeupCause();
Debug.WriteLine("Wakeup cause:" + cause.ToString());
switch (cause)
{
// System was woken up by timer
case Sleep.WakeupCause.Timer:
Debug.WriteLine("Wakup by timer");
break;
// System was woken up in normal running mode
case Sleep.WakeupCause.Undefined:
Debug.WriteLine("Set wakeup by timer for 10 seconds");
Sleep.EnableWakeupByTimer(new TimeSpan(0, 0, 0, 10));
Debug.WriteLine("Go to Deep sleep in 5 secs");
Debug.WriteLine("When coming out of deep sleep the system will reboot");
Thread.Sleep(5000);
Debug.WriteLine("Deep sleep now");
Sleep.StartDeepSleep();
break;
default:
break;
}
try
{
// Other examples of Sleep in Hardware.Esp32
//string message = "";
//try
//{
// // Wake up after a timer expires ( 60 seconds )
// Sleep.EnableWakeupByTimer(new TimeSpan(0, 0, 0, 60));
//}
//catch (Exception ex) { message = ex.Message; }
//try
//{
// // Wakeup when Pin12 is high
// Sleep.EnableWakeupByPin(Sleep.WakeupGpioPin.Pin12, 1);
//}
//catch (Exception ex) { message = ex.Message; }
//try
//{
// // Wakeup if either Pin12 or Pin13 are high
// Sleep.EnableWakeupByMultiPins(
// Sleep.WakeupGpioPin.Pin12 |
// Sleep.WakeupGpioPin.Pin13,
// Sleep.WakeupMode.AnyHigh );
//}
//catch (Exception ex) { message = ex.Message; }
//Debug.WriteLine(message);
//try
//{
// // Get the Wakeup cause
// cause = Sleep.GetWakeupCause();
//}
//catch (Exception ex) { message = ex.Message; }
//try
//{
// // Get the Wakeup Pin
// Sleep.WakeupGpioPin pin = Sleep.GetWakeupGpioPin();
//}
//catch (Exception ex) { message = ex.Message; }
//try
//{
// // Wake up when a touch pad is touched
// Sleep.EnableWakeupByTouchPad();
//}
//catch (Exception ex) { message = ex.Message; }
//try
//{
// // Get which touch pad woke up Esp32,
// // when cause is Sleep.EnableWakeupByTouchPad
// Sleep.TouchPad tp = Sleep.GetWakeupTouchpad();
//}
//catch (Exception ex) { message = ex.Message; }
//try
//{
// // Start Light Sleep
// EspNativeError err = Sleep.StartLightSleep();
//}
//catch (Exception ex) { message = ex.Message; }
//try
//{
// // Start Deep Sleep
// EspNativeError err = Sleep.StartDeepSleep();
//}
//catch (Exception ex) { message = ex.Message; }
}
catch (Exception )
{
// Do whatever please you with the exception caught
}
finally // Enter the infinite loop in all cases
{
while (true)
{
Thread.Sleep(200);
}
}
}
}
}