Skip to content

Commit

Permalink
Introduce lockout time and stop capture feature to GPIO settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Lillifee committed May 2, 2023
1 parent cc837e3 commit 04bb849
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 5 deletions.
16 changes: 15 additions & 1 deletion src/server/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const createButtonControl = async (
import('onoff')
.then((onoff) => {
let button: Gpio | undefined;
let lockout = false;

const watchButton = () => {
unwatchButton();
Expand All @@ -33,7 +34,20 @@ export const createButtonControl = async (

button.watch((error, value) => {
logger.info('button control', error || value);
raspiControl.getStatus().running ? raspiControl.stop() : raspiControl.start();
if (!raspiControl.getStatus().running) {
if (lockout) return;

raspiControl.start();

if (settings.lockoutTime) {
setTimeout(() => (lockout = false), settings.lockoutTime);
lockout = true;
}
} else {
if (settings.stopCaptureOnTrigger) {
raspiControl.stop();
}
}
});
};

Expand Down
9 changes: 9 additions & 0 deletions src/shared/helperFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ export const abbreviateNumber =
return `${scaled.toFixed(usedFractionDigits)} ${suffix}${unit}`;
};

/**
* Multiply and abbreviate number.
* e.g. ms with multiplier 0.001 result in seconds
*/
export const multiplyAndAbbreviateNumber =
(unit = '', fractionDigits = -1, multiplier = 1) =>
(number?: number): string =>
abbreviateNumber(unit, fractionDigits)(number ? number * multiplier : number);

/**
* Format number and append unit
*
Expand Down
18 changes: 16 additions & 2 deletions src/shared/settings/button.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { enumSetting, numberSetting } from './helper';
import { appendUnit, multiplyAndAbbreviateNumber } from '../helperFunctions';
import { booleanSetting, enumSetting, numberSetting } from './helper';
import { Setting } from './types';

/**
Expand Down Expand Up @@ -44,7 +45,20 @@ export const buttonSettingDesc = {
edge: enumSetting('Edge', ['both', 'rising', 'falling'], 'rising'),

/** Debounce timeout */
debounceTimeout: numberSetting('Debounce timeout (ms)', 0, 1000, 10, 10),
debounceTimeout: numberSetting('Debounce timeout', 0, 1000, 10, 10, appendUnit('ms')),

/** Lock-out time */
lockoutTime: numberSetting(
'Lock-out time',
0,
600000,
0,
1000,
multiplyAndAbbreviateNumber('s', 0, 0.001),
),

/** Stop capture on GPIO trigger */
stopCaptureOnTrigger: booleanSetting('Stop capture on GPIO Trigger'),
};

export type ButtonSettingDesc = typeof buttonSettingDesc;
Expand Down
4 changes: 2 additions & 2 deletions src/shared/settings/photo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ export const photoSettingDesc = {
* Note that you should specify %04d at the point in the filename where you want a frame count number to appear.
* -t 30000 -tl 2000 -o image%04d.jpg
*
* no longer in use since cron is in use
* no longer in use since cron
*/
timelapse: numberSetting('Timelapse', 0, 60 * 60 * 24 * 1000, 3000, 1000),
// timelapse: numberSetting('Timelapse', 0, 60 * 60 * 24 * 1000, 3000, 1000),

/**
* Whether to run an autofocus cycle before capture
Expand Down
6 changes: 6 additions & 0 deletions src/site/components/main/settings/ButtonSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { NumberSetting } from './common/NumberSetting.js';
import { SettingsExpander } from './common/SettingsExpander.js';
import { SettingsRestore } from './common/SettingsRestore.js';
import { SettingsHeader, SettingsHeaderText, SettingsWrapper } from './common/Styled.js';
import { BooleanSetting } from './common/BooleanSetting.js';

export interface ButtonSettingsProps {
status: RaspiStatus;
Expand All @@ -31,6 +32,11 @@ export const ButtonSettings: React.FC<ButtonSettingsProps> = ({ status, button,
>
<EnumDropdownSetting {...button.edge} update={updateField('edge')} />
<NumberSetting {...button.debounceTimeout} update={updateField('debounceTimeout')} />
<NumberSetting {...button.lockoutTime} update={updateField('lockoutTime')} />
<BooleanSetting
{...button.stopCaptureOnTrigger}
update={updateField('stopCaptureOnTrigger')}
/>
</SettingsExpander>
) : (
<React.Fragment>
Expand Down

0 comments on commit 04bb849

Please sign in to comment.