-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathGenlockDongle.ino
More file actions
143 lines (126 loc) · 4.99 KB
/
GenlockDongle.ino
File metadata and controls
143 lines (126 loc) · 4.99 KB
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
// GoPro hardware emu (MewPro Genlock Dongle)
//
// To comple please use Arduino IDE 1.5.7 (or later) and PinChangeInt 2.40-rc2 (or later)
// Copyright (c) 2015 orangkucing
//********************************************************
// c_I2C: I2C interface
//
// Note: in order to use MewPro Genlock Dongle reliably, THE FOLLOWING MODIFICATIONS TO STANDARD ARDUINO LIBRARY SOURCE IS
// STRONGLY RECOMMENDED:
//
// 1. hardware/arduino/avr/libraries/Wire/Wire.h
// old: #define BUFFER_LENGTH 32 --> new: #define BUFFER_LENGTH 64
// 2. hardware/arduino/avr/libraries/Wire/utility/twi.h
// #define TWI_BUFFER_LENGTH 32 --> new: #define TWI_BUFFER_LENGTH 64
#include <Wire.h>
#if BUFFER_LENGTH < 64
#error Please modify Arduino Wire library source code to increase the I2C buffer size
#endif
//********************************************************
// e_Shutter: A shutter without contact bounce or chatter
#define USE_SHUTTER
//********************************************************
// pin change interrupt
// please download PinChangeInt library from https://github.com/GreyGnome/PinChangeInt
//
// You can reduce the memory footprint of this handler by declaring that there will be no pin change interrupts
// on any one or two of the three ports. If only a single port remains, the handler will be declared inline
// reducing the size and latency of the handler.
#define NO_PORTB_PINCHANGES // to indicate that port b will not be used for pin change interrupts
// #define NO_PORTC_PINCHANGES // to indicate that port c will not be used for pin change interrupts
#define NO_PORTD_PINCHANGES // to indicate that port d will not be used for pin change interrupts
// *** New in version 1.5: ********************************
// You can reduce the code size by 20-50 bytes, and you can speed up the interrupt routine
// slightly by declaring that you don't care if the static variables PCintPort::pinState and/or
// PCintPort::arduinoPin are set and made available to your interrupt routine.
#define NO_PIN_STATE // to indicate that you don't need the pinState
#define NO_PIN_NUMBER // to indicate that you don't need the arduinoPin
// *********************************************************
// if there is only one PCInt vector in use the code can be inlined
// reducing latency and code size
// define DISABLE_PCINT_MULTI_SERVICE below to limit the handler to servicing a single interrupt per invocation.
#define DISABLE_PCINT_MULTI_SERVICE
#include <PinChangeInt.h>
// it is better to define this when RXI is connected to nothing (eg. Dongle #1 of single dongle configuration or Dongle #0)
#undef UART_RECEIVER_DISABLE
// define this in order to achieve improved boot-up stability
// by executing watchdog timer reset after every power-down.
// WARNING: to enable this requres Arduino Pro Mini's bootloader support
// watchdog timer (usual boards don't support this).
// To burn a bootloader supporting watchdog timer please refer
// https://andreasrohner.at/posts/Electronics/How-to-make-the-Watchdog-Timer-work-on-an-Arduino-Pro-Mini-by-replacing-the-bootloader/
#include <avr/wdt.h>
#undef SOFTWARE_RESET
// end of Options
//////////////////////////////////////////////////////////
#include <Arduino.h>
#include "MewPro.h"
// enable console output
boolean debug = false;
volatile boolean poweron = false;
boolean dontSendPW = false;
boolean heartBeatIsOn = false;
boolean isMaster = false;
unsigned long previous_shutter;
unsigned long timelapse = 0;
void setup()
{
// Remark. Arduino Pro Mini 328 3.3V 8MHz is too slow to catch up with the highest 115200 baud.
// cf. http://forum.arduino.cc/index.php?topic=54623.0
// Set 57600 baud or slower.
Serial.begin(57600);
#ifdef UART_RECEIVER_DISABLE
UCSR0B &= (~_BV(RXEN0));
#endif
pinMode(BPRDY, INPUT_PULLUP);
pinMode(PWRBTN, INPUT_PULLUP);
digitalWrite(HBUSRDY, LOW);
pinMode(HBUSRDY, OUTPUT);
pinMode(BUILTINLED, OUTPUT);
digitalWrite(BUILTINLED, HIGH);
setupShutter();
}
void loop()
{
static unsigned long lastHeartBeat = 0;
static boolean pwrbtn = true;
//if (digitalRead(BPRDY) == LOW && digitalRead(PWRBTN) == LOW) { // slave: power button of main camera depressed
if ((PINC & (_BV(1) | _BV(3))) == 0) { // speed up!
pwrbtn = false;
delayMicroseconds(10500);
while (digitalRead(PWRBTN) == LOW) {
;
}
} else if (!pwrbtn) {
emptyQueue();
pwrbtn = true;
poweron = true;
dontSendPW = true;
if (1) {
Serial.println("");
Serial.println("@"); // power on slaves
Serial.flush();
}
}
if (poweron) {
digitalWrite(BUILTINLED, LOW);
digitalWrite(HBUSRDY, HIGH);
resetI2C();
poweron = false;
}
if (heartBeatIsOn) {
if (millis() - lastHeartBeat >= 1000) {
SendHeartBeat();
lastHeartBeat += 1000;
}
} else {
lastHeartBeat = millis();
}
if (timelapse != 0) {
if (millis() - previous_shutter >= timelapse) {
queueIn("SR3");
timelapse = 0;
}
}
checkCommands();
}