|
18 | 18 | #include <cmath>
|
19 | 19 | #include <cstdio>
|
20 | 20 | #include <cstring>
|
| 21 | +#include <random> |
21 | 22 | #include <thread>
|
22 | 23 |
|
23 | 24 | #include "../Memory/mem.h"
|
|
27 | 28 | #include "primitives.h"
|
28 | 29 |
|
29 | 30 | #define NUM_PRIMITIVES 0
|
30 |
| -#define NUM_PRIMITIVES_ARDUINO 35 |
| 31 | +#define NUM_PRIMITIVES_ARDUINO 37 |
31 | 32 |
|
32 | 33 | #define ALL_PRIMITIVES (NUM_PRIMITIVES + NUM_PRIMITIVES_ARDUINO)
|
33 | 34 |
|
@@ -558,6 +559,28 @@ def_prim(read_uart_sensor, oneToOneI32) {
|
558 | 559 | return true;
|
559 | 560 | }
|
560 | 561 |
|
| 562 | +std::random_device r; |
| 563 | +std::default_random_engine e(r()); |
| 564 | +std::uniform_int_distribution<int16_t> adc_dist(0, 1<<12); // 12 bit adc |
| 565 | + |
| 566 | +def_prim(nxt_touch_sensor, oneToOneU32) { |
| 567 | + const uint32_t port = arg0.uint32; |
| 568 | + const int16_t v = adc_dist(e); |
| 569 | + pop_args(1); |
| 570 | + printf("nxt_touch_sensor(%u) = %d\n", port, v < 2000); |
| 571 | + pushUInt32(v < 2000); |
| 572 | + return true; |
| 573 | +} |
| 574 | + |
| 575 | +def_prim(ev3_touch_sensor, oneToOneU32) { |
| 576 | + const uint32_t port = arg0.uint32; |
| 577 | + const int16_t v = adc_dist(e); |
| 578 | + pop_args(1); |
| 579 | + printf("ev3_touch_sensor(%u) = %d\n", port, v > 3000); |
| 580 | + pushUInt32(v > 3000); |
| 581 | + return true; |
| 582 | +} |
| 583 | + |
561 | 584 | def_prim(subscribe_interrupt, threeToNoneU32) {
|
562 | 585 | uint8_t pin = arg2.uint32; // GPIOPin
|
563 | 586 | uint8_t tidx = arg1.uint32; // Table Idx pointing to Callback function
|
@@ -661,6 +684,8 @@ void install_primitives() {
|
661 | 684 | install_primitive(stop_motor);
|
662 | 685 | install_primitive(setup_uart_sensor);
|
663 | 686 | install_primitive(read_uart_sensor);
|
| 687 | + install_primitive(nxt_touch_sensor); |
| 688 | + install_primitive(ev3_touch_sensor); |
664 | 689 | }
|
665 | 690 |
|
666 | 691 | //------------------------------------------------------
|
|
0 commit comments