Created
July 14, 2016 00:57
-
-
Save pentlander/f1974aeab2d26a2bde609a5c0fa24afe to your computer and use it in GitHub Desktop.
Vibrate to the contact's initials in morse code with Tasker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var dotLength = 110; | |
var dashLength = 3 * dotLength; | |
var pauseBetweenElements = 2 * dotLength; | |
var pauseBetweenWords = 3 * dotLength; | |
function nameToVibrations(fullName) { | |
var initials = getInitials(fullName); | |
var vibrations = initials.map(wordToMorseCode) | |
.map(morseCodeToVibrations) | |
.join(",".concat(pauseBetweenWords).concat(",")); | |
return "0,".concat(vibrations); | |
} | |
function inspect(value) { | |
console.log(value); | |
return value; | |
} | |
function morseCodeToVibrations(morseCode) { | |
console.log("Morse", morseCode); | |
var vibrations = ""; | |
for (var i = 0; i < morseCode.length; ++i) { | |
var code = morseCode[i]; | |
if (code === ".") { | |
vibrations = vibrations.concat(dotLength); | |
} else if (code === "-") { | |
vibrations = vibrations.concat(dashLength); | |
} | |
if (i === morseCode.length - 1) break; | |
vibrations = vibrations.concat(",".concat(pauseBetweenElements).concat(",")); | |
} | |
console.log(vibrations); | |
return vibrations; | |
} | |
function wordToMorseCode(word) { | |
var morseCode = [".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", | |
".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", | |
"-", "..-", "...-", ".--", "-..-", "-.--", "--.."]; | |
var encodedWord = ""; | |
for (var i = 0; i < word.length; ++i) { | |
var morseCodeIndex = word.charCodeAt(i) - 97; | |
encodedWord = encodedWord.concat(morseCode[morseCodeIndex]); | |
} | |
return encodedWord; | |
} | |
function getInitials(fullName) { | |
return fullName.toLowerCase() | |
.replace(/[^a-z ]/g, "") | |
.split(' ') | |
.map(function(name) { | |
firstLetter = name[0]; | |
return typeof firstLetter != undefined ? firstLetter : ""; | |
}); | |
} | |
var vibrations = nameToVibrations(String(global("SMSRN"))); | |
vibratePattern(vibrations); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment