Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Signal instance events #301

Open
wegendt-bosch opened this issue Mar 12, 2019 · 2 comments
Open

RFC: Signal instance events #301

wegendt-bosch opened this issue Mar 12, 2019 · 2 comments
Labels
enhancement New feature or request RFC Requests For Comments are ideas up for discussion. If accepted they result in implementation tasks.

Comments

@wegendt-bosch
Copy link
Contributor

Introduction

The root elements in platforms are system resources. They offer events, modalities and signals. Users can supply event handlers to these events, can read modalities and read and write signals. Modalities and events are singular in the sense that per application there is only one instance of each of them. In contrast to that signals can be set up multiple times in signal instances.

This makes it so that users can for example react to an event in the accelerometer but not to an MQTT message.

Current Situation

Currently events per signal instance are not supported.

Proposal

I propose adding events to signal instances. For example an MQTT topic signal offers an message event or a GPIO pin offers input events like risingEdge, fallingEdge.

Code Example

The platform could declare signal instance events like this:

signal topic(name : string, qos : uint32 = 0) : string {
  event message
  event sendError
  event sendSuccess
}

A user would react like this:

setup mqtt: MQTT {
  var t = topic("foo");
}

every mqtt.t.message {
  /* can't do a lot yet until events have payloads */
}
@wegendt-bosch wegendt-bosch added enhancement New feature or request RFC Requests For Comments are ideas up for discussion. If accepted they result in implementation tasks. labels Mar 12, 2019
@justindannguyen
Copy link

justindannguyen commented Nov 3, 2019

Dear @wegendt-bosch ,
This is what i am thinking and was looking for.
As your comments, event functions can't do alot yet because we don't have payload.

Can we implement something like this?

every mqtt.t.message {
    var payload = mqtt.t.read();
    /* implement stuff here */
}

or better ways we should modify the event function to add payload (maybe it may requires the changes in Mita)

@wegendt-bosch
Copy link
Contributor Author

wegendt-bosch commented Nov 11, 2019

PR #344 already allows the following:

import platforms.xdk110;

every MQTT.msgReceived(msg) { // msg has type array<500>. Reacts to *any* incoming message.
  println(msg);
}

The next step is then to implement this RFC, which should be a lot easier than #344, since its mostly language design and scoping. Then we would have full interactivity like this:

every mqtt.t.msgReceived(msg) {

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request RFC Requests For Comments are ideas up for discussion. If accepted they result in implementation tasks.
Projects
None yet
Development

No branches or pull requests

2 participants