1# Copyright 1998-2004 Ward Cunningham and Jim Wilson 2# Distributed under the GNU GPL V2 license. 3# See http://c2.com/morse 4# 5# This file is part of Morse. 6# 7# Morse is free software; you can redistribute it and/or modify 8# it under the terms of the GNU General Public License as published by 9# the Free Software Foundation; either version 2 of the License, or 10# (at your option) any later version. 11# 12# Morse is distributed in the hope that it will be useful, 13# but WITHOUT ANY WARRANTY; without even the implied warranty of 14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15# GNU General Public License for more details. 16# 17# You should have received a copy of the GNU General Public License along 18# with Morse; if not, write to the Free Software Foundation, Inc., 19# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 21 22# The next two functions are written in C++ and return bool. 23# Here, we assert they return 16-bit values. It seems to work. 24""" 25Module cw - send strings in Morse code 26 27Two functions are wrapped. One must be called first to initialize 28the sound subsystem. The other may then be called repeatedly to 29send message strings in Morse code. 30""" 31cdef extern short set_cw(double wpm, double freq, double volume) 32cdef extern short send_cw(int c) 33 34# Normally, a simple call to cw.set() will do, but the function 35# gives you control over the frequency (of the tone) and the 36# volume. You must call this function to initialize the SDL 37# before sending anything. 38 39def set(wpm = 20, freq = 1000, volume = 1): 40 """ 41 Set(wpm = 20, freq = 1000, volume = 1.0) sets the keying rate, 42 frequency (default: 1Khz), and loudness (default: maximum) 43 """ 44 if not set_cw(wpm, freq, volume): raise IOError 45 46# The C(++) version sends a single character. It is more Pythonic 47# to send a string. 48 49def send(s): 50 """ 51 Send("message") - sends your "message" in Morse code 52 """ 53 for c in s: send_cw(ord(c)) 54