diff --git a/src/server/button.ts b/src/server/button.ts index 7242aac..89ba3e4 100644 --- a/src/server/button.ts +++ b/src/server/button.ts @@ -17,6 +17,7 @@ export const createButtonControl = async ( import('onoff') .then((onoff) => { let button: Gpio | undefined; + let lockout = false; const watchButton = () => { unwatchButton(); @@ -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(); + } + } }); }; diff --git a/src/shared/helperFunctions.ts b/src/shared/helperFunctions.ts index 7902863..a99199b 100644 --- a/src/shared/helperFunctions.ts +++ b/src/shared/helperFunctions.ts @@ -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 * diff --git a/src/shared/settings/button.ts b/src/shared/settings/button.ts index 6c949e8..9a202aa 100644 --- a/src/shared/settings/button.ts +++ b/src/shared/settings/button.ts @@ -1,4 +1,5 @@ -import { enumSetting, numberSetting } from './helper'; +import { appendUnit, multiplyAndAbbreviateNumber } from '../helperFunctions'; +import { booleanSetting, enumSetting, numberSetting } from './helper'; import { Setting } from './types'; /** @@ -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; diff --git a/src/shared/settings/photo.ts b/src/shared/settings/photo.ts index 4cc86d1..0127f8f 100644 --- a/src/shared/settings/photo.ts +++ b/src/shared/settings/photo.ts @@ -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 diff --git a/src/site/components/main/settings/ButtonSettings.tsx b/src/site/components/main/settings/ButtonSettings.tsx index 0ab83b0..5e7dcaf 100644 --- a/src/site/components/main/settings/ButtonSettings.tsx +++ b/src/site/components/main/settings/ButtonSettings.tsx @@ -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; @@ -31,6 +32,11 @@ export const ButtonSettings: React.FC = ({ status, button, > + + ) : (