[260] | 1 | #include "r2ca.h"
|
---|
[137] | 2 |
|
---|
[260] | 3 | void task1_setup();
|
---|
[137] | 4 |
|
---|
| 5 | void setup(){
|
---|
| 6 | Serial.begin(115200);
|
---|
| 7 | }
|
---|
| 8 |
|
---|
| 9 | void loop(){
|
---|
| 10 | Serial.print("idle : ");
|
---|
[260] | 11 | Serial.println(r2ca_idle_result);
|
---|
[137] | 12 | Serial.print("isr : ");
|
---|
[260] | 13 | Serial.println(r2ca_isr_result);
|
---|
[137] | 14 | Serial.print("dispatch : ");
|
---|
[260] | 15 | Serial.println(r2ca_dispatch_result);
|
---|
[137] | 16 | delay(1000);
|
---|
| 17 |
|
---|
[260] | 18 | task1_setup();
|
---|
[137] | 19 | }
|
---|
| 20 |
|
---|
| 21 | #define PSERIAL SerialUSB
|
---|
| 22 |
|
---|
| 23 | bool processing_connected = false;
|
---|
| 24 |
|
---|
| 25 | void establishContact() {
|
---|
| 26 | while (!PSERIAL.available()) {
|
---|
| 27 | PSERIAL.print('A'); // send a capital A
|
---|
| 28 | delay(300);
|
---|
| 29 | }
|
---|
| 30 | Serial.println("Processing Task : Connect!");
|
---|
| 31 | processing_connected = true;
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | void task1_setup()
|
---|
| 35 | {
|
---|
| 36 | PSERIAL.begin(115200);
|
---|
| 37 | while(!PSERIAL){
|
---|
| 38 | delay(1);
|
---|
| 39 | }
|
---|
| 40 | Serial.print("Processing Task : Start!");
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | int inByte = 0;
|
---|
| 44 | int last_connect = 0;
|
---|
| 45 |
|
---|
| 46 | #define TIMEOUT_MS 3000
|
---|
| 47 |
|
---|
[260] | 48 | void loop1()
|
---|
[137] | 49 | {
|
---|
| 50 | if(!processing_connected){
|
---|
| 51 | establishContact();
|
---|
| 52 | }else{
|
---|
| 53 | if((millis() - last_connect) > TIMEOUT_MS){
|
---|
| 54 | processing_connected = false;
|
---|
| 55 | Serial.println("Processing Task : Disconnect!");
|
---|
| 56 | }
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | uint16_t load;
|
---|
| 60 | uint16_t isr_cnt;
|
---|
| 61 | uint16_t dispatch_cnt;
|
---|
| 62 |
|
---|
[260] | 63 | load = 100 - map(r2ca_idle_result, 0, IDLE_TASK_IDLE_LOOP_10MS/10, 0, 100);
|
---|
| 64 | isr_cnt = (r2ca_isr_result > 0xffff)? 0xffff : r2ca_isr_result;
|
---|
| 65 | dispatch_cnt = (r2ca_dispatch_result > 0xffff)? 0xffff : r2ca_dispatch_result;
|
---|
[137] | 66 |
|
---|
| 67 | if (PSERIAL.available()){
|
---|
| 68 | inByte = PSERIAL.read();
|
---|
| 69 | last_connect = millis();
|
---|
| 70 |
|
---|
| 71 | PSERIAL.write((uint8_t)(load >> 8));
|
---|
| 72 | PSERIAL.write((uint8_t)load);
|
---|
| 73 | PSERIAL.write((uint8_t)(isr_cnt >> 8));
|
---|
| 74 | PSERIAL.write((uint8_t)isr_cnt);
|
---|
| 75 | PSERIAL.write((uint8_t)(dispatch_cnt >> 8));
|
---|
| 76 | PSERIAL.write((uint8_t)dispatch_cnt);
|
---|
| 77 | }
|
---|
| 78 | delay(1);
|
---|
| 79 | }
|
---|