-
Notifications
You must be signed in to change notification settings - Fork 28
/
main.cpp
151 lines (118 loc) · 2.52 KB
/
main.cpp
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*------------------------------------------------*/
/*
Dis programm is used to produce a hardware trigger
for a Basler camera
Protocol:
Manually adjust trigger properties
Achtung Zeit ist in Mikrosekunden !
<T X Count_of_Trigger X Time_Trigger_on_us>
<TX10X1000000>
Beenden der PWM zwischendrin
<SX>
Baudrate: 115200
X is the seperator between the values
*/
/*------------------------Bibliotheken------------*/
#include "RawSerial.h"
#include "mbed.h"
#include <string>
#include <stdio.h>
#include <stdlib.h>
/*------------ Constant definitions --------------*/
#define BUFF_LENGTH 15
#define BAUDRATE 115200
//#define TX_PIN USBTX
//#define RX_PIN USBRX
#define TX_PIN PC_10
#define RX_PIN PC_11
#define LED_PIN_1 LED1
#define LED_PIN_2 LED2
#define LED_PIN_3 LED3
#define Trigger_Pin PC_6
RawSerial pc(TX_PIN, RX_PIN);
volatile char rx_buf[BUFF_LENGTH];
Timer timer_Stopper;
DigitalOut LED_Green(LED_PIN_1);
DigitalOut LED_Blue(LED_PIN_2);
DigitalOut LED_Red(LED_PIN_3);
DigitalOut Trigger(Trigger_Pin);
Ticker myTick;
// Global Values
char M_or_T; // T = Manually Trigger Mode
uint32_t Manually_Values[2];
uint32_t Automatic_Values[1];
volatile int flag_1 = 0;
volatile int flag_2 = 0;
int LED_ticker = 0;
int Threshold_Ticker = 0;
int STOP = 0;
void onTick() {
LED_Red = !LED_Red;
Trigger = !Trigger;
LED_ticker++;
if (LED_ticker >= 2 * Threshold_Ticker) {
myTick.detach();
LED_Red = 0;
Trigger = 0;
}
if (STOP == 1) {
myTick.detach();
LED_Red = 0;
Trigger = 0;
}
}
void serialCb() {
char *pch;
pch = strtok((char *)rx_buf, "X");
M_or_T = *pch;
if (M_or_T == 'T') {
pch = strtok(NULL, "X");
Manually_Values[0] = atoi(pch);
pch = strtok(NULL, "X");
Manually_Values[1] = atoi(pch);
}
switch (M_or_T) {
case 'T':
Threshold_Ticker = Manually_Values[0];
STOP = 0;
LED_ticker = 0;
myTick.attach_us(&onTick, Manually_Values[1]);
break;
case 'S':
STOP = 1;
break;
default:
break;
}
}
void callback() {
if (pc.getc() == '<') {
pc.putc('<');
for (int i = 0; i < 20; i++) {
rx_buf[i] = pc.getc();
if (rx_buf[i] != '>') {
pc.putc(rx_buf[i]);
}
if (rx_buf[i] == '>') {
pc.putc('>');
pc.putc('\n');
flag_1 = 1;
break;
}
}
}
}
int main() {
LED_Green = 0;
LED_ticker = 0;
Trigger = 0;
pc.baud(115200);
pc.attach(&callback, Serial::RxIrq);
pc.printf("Program started! \n");
while (1) {
if (flag_1 == 1) {
serialCb();
flag_1 = 0;
}
}
}