-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.cs
79 lines (69 loc) · 2.64 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
using System;
namespace i2c
{
class Program
{
static void Main(string[] argv)
{
Action<ProximtyEventArgs> updater = (args) =>
{
OutputValue(args.Proximity, "Proximity Reading");
//OutputValue(args.RawValue, "Proximity Raw Value");
};
Action<string> logger = (msg) => { }; /*= Console.WriteLine*/;
try
{
Console.WriteLine("Starting Communication with VCNL4000");
var vcnl4000 = new VCNL4000("1", 100, updater, logger);
//vcnl4000.ProximityReading += sensor_ProximityReading;
var productId = vcnl4000.ProductID;
OutputValue(productId, "Product ID");
vcnl4000.Start();
//Console.WriteLine("Starting Communication with ADS1115");
//var ads1115 = new ADS1115("1");
//ads1115.Message += ads1115_Message;
//ads1115.SingleEndedConversionReading += ads1115_ConversionReading;
//ads1115.Start();
Console.WriteLine("Press Esc key to stop");
do
{
while (!Console.KeyAvailable)
{
// Do something
}
} while (Console.ReadKey(true).Key != ConsoleKey.Escape);
//ads1115.Stop();
vcnl4000.Stop();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
static void ads1115_Message(object sender, ConverterMessageEventArgs e)
{
OutputValue(e.Message, "Convertor");
}
private static void OutputValue(string response, string message)
{
Console.WriteLine(message + " Response: {0}", response);
}
private static void ads1115_ConversionReading(object sender, SingleEndedConversionEventArgs e)
{
var _sender = (ADS1115)sender;
OutputValue(e.Data, "Conversion Reading");
}
private static void OutputValue(int response, string message)
{
Console.WriteLine(message + " Response: {0} (0x{1})", response, response.ToString("X"));
}
private static void OutputValue(decimal response, string message)
{
Console.WriteLine(message + " Response: {0}", response);
}
private static void OutputValue(float response, string message)
{
Console.WriteLine(message + " Response: {0}", response);
}
}
}