Skip to content

Commit 4b2ac2a

Browse files
committed
slop city 2
1 parent a4bd465 commit 4b2ac2a

File tree

9 files changed

+44
-28
lines changed

9 files changed

+44
-28
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
.vscode/launch.json
55
.vscode/ipch
66
.DS_Store
7+
CLAUDE.md
8+
claude/
9+
claude/*

platformio.ini

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,27 @@ platform = nordicnrf52
1313
board = adafruit_feather_nrf52840
1414
framework = arduino
1515
upload_port = /dev/cu.usbmodem142444401
16-
lib_deps =
16+
build_flags =
17+
-std=c++17
18+
lib_deps =
1719
fastled/FastLED@^3.4.0
1820
mokolea/InputDebounce@^1.6.0
19-
; monitor_flags=
21+
; monitor_flags=
2022
; --encoding
2123
; hexlify
22-
; build_flags =
23-
; -DCFG_DEBUG=2
2424

2525

2626
[env:freemote-nrf52840-debug]
2727
platform = nordicnrf52
2828
board = adafruit_feather_nrf52840
2929
framework = arduino
3030
upload_port = /dev/cu.usbmodem142444401
31-
lib_deps =
31+
build_flags =
32+
-std=c++17
33+
-DCFG_DEBUG=2
34+
lib_deps =
3235
fastled/FastLED@^3.4.0
3336
mokolea/InputDebounce@^1.6.0
34-
; monitor_flags=
37+
; monitor_flags=
3538
; --encoding
36-
; hexlify
37-
build_flags =
38-
-DCFG_DEBUG=2
39+
; hexlify

src/BLECamera.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
#include "BLECamera.h"
22
#include "bluefruit.h"
33

4-
BLECamera::BLECamera(void) : BLEClientService("8000FF00-FF00-FFFF-FFFF-FFFFFFFFFFFF"), _remoteCommand(0xFF01), _remoteNotify(0xFF02)
4+
BLECamera::BLECamera(void)
5+
: BLEClientService("8000FF00-FF00-FFFF-FFFF-FFFFFFFFFFFF"),
6+
_remoteCommand(0xFF01),
7+
_remoteNotify(0xFF02),
8+
_shutterStatus(0),
9+
_focusStatus(0),
10+
_recordingStatus(0),
11+
_last_message(0),
12+
_focusHeld(false)
513
{
6-
rs = rs->access();
14+
rs = RemoteStatus::access();
715
}
816

917
void camera_notify_cb(BLEClientCharacteristic *chr, uint8_t *data, uint16_t len)
@@ -116,8 +124,8 @@ bool BLECamera::disableNotify(void)
116124

117125
bool BLECamera::pressTrigger(void)
118126
{
119-
// hack until I get this to work
120-
uint32_t timeout = millis() + 3000;
127+
// Timeout for focus and shutter operations
128+
uint32_t startTime = millis();
121129

122130
if (!_focusHeld)
123131
{
@@ -129,11 +137,12 @@ bool BLECamera::pressTrigger(void)
129137

130138
if (mode == AUTO_FOCUS)
131139
{
140+
// Wait for focus acquisition (with timeout)
132141
while (_focusStatus != 0x20)
133142
{
134143
yield();
135144

136-
if (timeout < millis())
145+
if ((millis() - startTime) >= 3000)
137146
{
138147
break;
139148
}
@@ -144,19 +153,20 @@ bool BLECamera::pressTrigger(void)
144153
// Release back to focus
145154
_remoteCommand.write16_resp(HOLD_FOCUS);
146155

147-
// Reset focus status
156+
// Reset shutter status
148157
_shutterStatus = 0x00;
149158

150159
// Shutter
151160
_remoteCommand.write16_resp(TAKE_PICTURE);
152161

153162
if (mode == AUTO_FOCUS)
154163
{
164+
// Wait for shutter completion (with timeout)
155165
while (_shutterStatus != 0x20)
156166
{
157167
yield();
158168

159-
if (timeout < millis())
169+
if ((millis() - startTime) >= 3000)
160170
{
161171
break;
162172
}
@@ -176,6 +186,8 @@ bool BLECamera::releaseTrigger(void)
176186

177187
// Let go?
178188
_remoteCommand.write16_resp(SHUTTER_RELEASED);
189+
190+
return true;
179191
}
180192

181193

src/BLECamera.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ class BLECamera : public BLEClientService
6363
BLEClientCharacteristic _remoteCommand;
6464
BLEClientCharacteristic _remoteNotify;
6565

66-
uint8_t _shutterStatus; //A0
67-
uint8_t _focusStatus; //3F
68-
uint8_t _recordingStatus; //D5
66+
volatile uint8_t _shutterStatus; //A0
67+
volatile uint8_t _focusStatus; //3F
68+
volatile uint8_t _recordingStatus; //D5
6969

7070
uint32_t _last_message;
7171

src/BLEHandler.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "BLEHandler.h"
22

3-
RemoteStatus *rs = rs->access();
3+
RemoteStatus *rs = RemoteStatus::access();
44

55
bool BLEHandler::InitBLE(BLECamera *newcam)
66
{
@@ -114,8 +114,6 @@ void BLEHandler::_connection_secured_callback(uint16_t conn_handle)
114114
return;
115115
}
116116

117-
delay(500);
118-
119117
// Connecting camera
120118
if (_camera_ref->enableNotify())
121119
{

src/InputHandler.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ bool Input::Init(BLECamera *newcam)
1414
selectSwitch.setup(SELECT_SWITCH_PIN, DEBOUNCE_DELAY, InputDebounce::PIM_EXT_PULL_DOWN_RES);
1515

1616
Input::readStartup();
17+
18+
return true;
1719
}
1820

1921
void Input::readStartup(void)

src/RemoteStatus.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ RemoteStatus::RemoteStatus(void)
66
speed = 100;
77
set(NONE);
88

9-
xTaskCreate(&update_wrapper, "update", 256, NULL, TASK_PRIO_LOW, &statusLoopHandle);
9+
xTaskCreate(&update_wrapper, "update", 512, NULL, TASK_PRIO_LOW, &statusLoopHandle);
1010
}
1111

1212
void RemoteStatus::set(Status s)

src/RemoteStatus.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ class RemoteStatus
5757
CRGB leds[1];
5858

5959

60-
bool updateColor;
60+
volatile bool updateColor;
6161
Color primaryColor;
6262
Color secondaryColor;
63-
bool alternate;
64-
bool phase;
65-
uint32_t speed;
63+
volatile bool alternate;
64+
volatile bool phase;
65+
volatile uint32_t speed;
6666

6767
TaskHandle_t statusLoopHandle;
6868

src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ void setup()
1818
pinMode(PIN_LED1, OUTPUT);
1919

2020
// Configure the Neopixel Status LED
21-
RemoteStatus *rs = rs->access();
21+
RemoteStatus *rs = RemoteStatus::access();
2222
rs->set(Status::BOOT);
2323

2424
// Setup button handling

0 commit comments

Comments
 (0)