Community

DigitalInputPortEventArgs - DateTime not set by event

Working through some basic “Getting to Know Meadow” functions, I am trying a basic switch example from the DevCamp2020:

Initialize() {
            dateLastAction = DateTime.Now;
            switchInput = Device.CreateDigitalInputPort(Device.Pins.D12, 
                InterruptMode.EdgeBoth,
                ResistorMode.Disabled,
                0.1, 0.0);

            switchInput.Changed += SwitchInput_OnClick;
}

 private void SwitchInput_OnClick(object sender, DigitalInputPortEventArgs e) {
            Console.WriteLine($"SwitchInput changed, state is {e.Value}, was {dateLastAction}, delta {e.Delta}");
            dateLastAction = DateTime.Now;
    }

When I run the app, I get the following output:

SwitchInput changed, state is True, was 01/01/0001 00:00:00, delta 719162.00:00:21.0430000
SwitchInput changed, state is False, was 01/01/1970 00:00:21, delta 00:00:01.7190000
SwitchInput changed, state is True, was 01/01/1970 00:00:22, delta 00:00:05.3430000
SwitchInput changed, state is False, was 01/01/1970 00:00:28, delta 00:00:00.8600000
SwitchInput changed, state is True, was 01/01/1970 00:00:28, delta 00:08:15.9430000
SwitchInput changed, state is False, was 01/01/1970 00:08:44, delta 00:00:01.4550000

e.New and e.Old don’t seem to get set to DateTime.Now, and I’m not seeing a means to do that, so that would mean managing a separate variable for monitoring Time-of-Click statuses.

Is this expected, or am I missing something?
Cheers.

Edit #1…it just occurred to me that the DateTime.Now might actually be system time on the F7Micro board, and so that means somehow setting the board’s date/time. Looking into that now.

Edit #2…that was it. Now on to reading the NIST time via the network!
Device.SetClock(new DateTime(2020, 6, 17, 9, 39, 0));