Skip to content

Commit

Permalink
Scale QR code with --qr-scale factor, #115.
Browse files Browse the repository at this point in the history
  • Loading branch information
vmdocua committed Dec 3, 2024
1 parent edf02e2 commit b548538
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
26 changes: 16 additions & 10 deletions tools/reprostim-timesync-stimuli
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ def do_init(logfn: str) -> bool:
return True


def do_main(mode: Mode, logfn: str, display: int,
def do_main(mode: Mode, logfn: str,
display: int, qr_scale: float,
sound_codec: str, mute: bool,
ntrials: int, duration: float, interval: float,
keep_soundcode: bool) -> int:
Expand Down Expand Up @@ -272,7 +273,7 @@ def do_main(mode: Mode, logfn: str, display: int,
qrcode.make(json.dumps(rec)),
pos=(0, 0)
)
qr.size = qr.size *1
qr.size = qr.size * qr_scale
qr.draw()
win.flip()
tflip, tflip_str = get_times()
Expand Down Expand Up @@ -307,17 +308,20 @@ def do_main(mode: Mode, logfn: str, display: int,
help='Output log file name prefix.')
@click.option('-d', '--display', default=1, type=int,
help='Display number as an integer (default: 1).')
@click.option('-s', '--qr-scale', default=0.8, type=float,
help='Specify QR code scale factor in range 0..1. '
'Use 1.0 to fit full height (default: 0.8).')
@click.option('-a', '--audio-lib',
type=click.Choice([a.value for a in AudioLib],
case_sensitive=False),
default=AudioLib.PSYCHOPY_SOUNDDEVICE,
help='Specify audio library to be used.')
@click.option('-c', '--sound-codec',
type=click.Choice(['fsk', 'nfe'],
case_sensitive=False),
default='fsk',
type=click.Choice(['FSK', 'NFE'],
case_sensitive=True),
default='FSK',
help='Specify sound codec to produce audio code '
'(default: fsk).')
'(default: FSK).')
@click.option('-m', '--mute', is_flag=True, default=False,
help="Disable sound codes generation (default is False).")
@click.option('-t', '--trials', default=300, type=int,
Expand All @@ -338,6 +342,7 @@ def do_main(mode: Mode, logfn: str, display: int,
def main(ctx, mode: str,
output_prefix: str,
display: int,
qr_scale: float,
audio_lib: str,
sound_codec: str,
mute: bool,
Expand Down Expand Up @@ -372,10 +377,11 @@ def main(ctx, mode: str,
logger.error()
return -1

res = do_main(mode, output, display,
sound_codec, mute,
trials, duration, interval,
keep_soundcode)
res = do_main(mode, output,
display, qr_scale,
sound_codec, mute,
trials, duration, interval,
keep_soundcode)

end_ts: datetime = datetime.now()
logger.debug(f" Finished on: {end_ts}")
Expand Down
10 changes: 4 additions & 6 deletions tools/soundcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,12 @@ class SoundCodec(str, Enum):
# Frequency Shift Keying (FSK) where binary data is
# encoded as two different frequencies f0 and f1 with
# a fixed bit duration (baud rate or bit_rate).
FSK = "fsk"
FSK = "FSK"

# Numerical Frequency Encoding (NFE) numbers are mapped
# directly to specific frequencies
# can encode only some numeric hash.
NFE = "nfe"
NFE = "NFE"


# Class to provide general information about sound code
Expand Down Expand Up @@ -229,12 +229,10 @@ def __init__(self,
nfe_df=100, # used only in NFE
sample_rate=44100,
bit_duration=0.0070, # used only in FSK
#bit_duration=0.014,
nfe_duration=0.3, # used only in NFE
volume=0.95,
volume=0.80,
pre_delay=0.1,
#pre_f=1780,
pre_f=0,
pre_f=0, #1780
post_delay=0.1,
post_f=0 #3571
):
Expand Down

0 comments on commit b548538

Please sign in to comment.