Commit f73e7058 authored by Chris Morris's avatar Chris Morris
Browse files

Final submission

This is our final project version for HackPSU 2017. It is close to submitting time!
parent 5b688d13
Loading
Loading
Loading
Loading
+14 −3
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@
    <script src="js/ngi.polyfill.min.js"></script>
    <script src="GMLIB/system.js"></script>
    <script src="GMLIB/info.js"></script>
    <script src="js/ButtonManager.js"></script>

    <!-- Uncomment libraries as you need them: -->
    <!-- <script src="GMLIB/comm.js"></script> -->
@@ -20,8 +21,9 @@
    <!-- <script src="GMLIB/media.js"></script> -->
    <!-- <script src="GMLIB/nav.js"></script> -->
    <!-- <script src="GMLIB/phone.js"></script> -->
    <!-- <script src="GMLIB/ui.js"></script> -->
    <!-- <script src="GMLIB/voice.js"></script> -->
    <script src="GMLIB/ui.js"></script>
     <script src="GMLIB/voice.js"></script> 


  </head>
  <body>
@@ -31,11 +33,20 @@

        <!-- Remove all code inside #main and add your own! -->
        <h1>Facts</h1>
        <p>Press next for an animal fact, previous for a tech fact, or press back for a special tweet!</p>
        <p>
          <!-- Your VIN is: <span id="vin"></span>< -->
          <span id="funfact"></span>
        </p>
        <p>
          <div id="tweet">
          <blockquote class="twitter-tweet" data-lang="en">
            
            <p lang="en" dir="ltr" >
            Shoutout to <a href="https://twitter.com/GM?ref_src=twsrc%5Etfw">@GM</a> for sponsoring HackPSU and letting us develop software for their vehicles!</p>&mdash; Justin Leone (@LeoLeone_) <a href="https://twitter.com/LeoLeone_/status/927213544025788417?ref_src=twsrc%5Etfw">November 5, 2017</a></blockquote>
          <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
        </div>
        </p>
      </div>
    </div>

+119 −0
Original line number Diff line number Diff line
var gmExt = {};

(function(ctx0) {var buttonsAvailable = null;
    var DEFAULT_HZ_MS=250;
    
    function HardButtonManager() {
        var ctx = this;
        var valid = false;
        var subscription = {};
        var o = null;
        ctx.isValid = function() {
            return valid
        };
        var isSubscription = function(key) {
            if (Object.keys(subscription).length ===
                0) return true;
            return subscription[key] === true
        };
        var sendButtonClick = function(key) {
            var translated = translateKey(key);
            destroyKey(key);
            if (isSubscription(translated)) {
                if (ctx.action.onKeyUp !== undefined) ctx.action.onKeyUp(translated);
                if (ctx.action.onKeyClick !== undefined) ctx.action.onKeyClick(translated)
            }
        };
        ctx.getWatchButtonsHandle = function() {
            return ctx.gmWatcherID
        };
        ctx.finish = function() {
            if (ctx.gmWatcherID === null) return;
            for (var key in ctx.buttonCache) destroyKey(key);
            valid = false;
            ctx.buttonCache = null;
            gm.info.clearButtons(ctx.gmWatcherID);
            ctx.gmWatcherID = null
        };
        var onTimeout = function(key) {
            var translated = translateKey(key);
            if (isSubscription(translated)) ctx.action.onLongPress(translated)
        };
        var setNextLongPressNotification = function(key) {
            ctx.buttonCache[key] = setInterval(function() {
                onTimeout(key)
            }, ctx.action.interval)
        };
        var destroyKey = function(key) {
            if (!(key in ctx.buttonCache)) return;
            if (ctx.buttonCache[key] !== true) clearInterval(ctx.buttonCache[key]);
            delete ctx.buttonCache[key]
        };
        var translateKey = function(key) {
            if (isSubscription(key)) return key;
            switch (key) {
                case "SWC_NEXT":
                case "SWC_UP":
                case "SB_NEXT":
                    return "BTN_NEXT";
                    break;
                case "SWC_PREV":
                case "SB_PREV":
                case "SWC_DOWN":
                    return "BTN_PREV";
                    break;
                default:
                    return key;
                    break
            }
        };
        var watcherSuccessCallback = function(keyList) {
            var key;
            if (keyList.length == 0) {
                for (key in ctx.buttonCache) sendButtonClick(key);
                return
            }
            for (var i = 0; i < keyList.length; i++)
                if (!(keyList[i] in ctx.buttonCache)) {
                    ctx.buttonCache[keyList[i]] = true;
                    if (ctx.action.onLongPress !== undefined) setNextLongPressNotification(keyList[i]);
                    if (ctx.action.onKeyDown !==
                        undefined) {
                        key = translateKey(keyList[i]);
                        if (isSubscription(key)) ctx.action.onKeyDown(key)
                    }
                }
            for (key in ctx.buttonCache) {
                var found = false;
                for (var i = 0; i < keyList.length; i++)
                    if (keyList[i] === key) {
                        found = true;
                        break
                    }
                if (!found) sendButtonClick(key)
            }
        };
        var watcherFailureCallback = function() {
            console.log("hello world");
            if (ctx.action.onFailure) ctx.action.onFailure(new Error("Init error: Framework failed to watch buttons"));
            valid = false;
            ctx.finish()
        };
        if (arguments.length < 1) return;
        ctx.action = arguments[0];
        if (ctx.action.interval ===
            undefined) ctx.action.interval = DEFAULT_HZ_MS;
        if (arguments.length > 1) o = arguments[1];
        if (o)
            for (var i = 0; i < o.length; i++) subscription[o[i]] = true;
        if (!ctx.action.onKeyDown && (!ctx.action.onKeyUp && (!ctx.action.onKeyClick && !ctx.action.onLongPress))) return;
        ctx.buttonCache = [];
        ctx.gmWatcherID = gm.info.watchButtons(watcherSuccessCallback, watcherFailureCallback);
        valid = true
    }
    ctx0.newHardButtonManager = function(i, o) {
        var obj = new HardButtonManager(i, o);
        if (obj.isValid()) return obj;
        return null
    }
})(gmExt);
 No newline at end of file
+132 −8
Original line number Diff line number Diff line
// Your code goes here
var sportsFacts = ["Phil Kessel is a back to back Stanley Cup champion",
"Jim harbaugh has never won a big ten confernce championship",
"Traditional Soccer balls have 32 panels",
"The NBA didn't add the 3-point line until 1979 where it was callef a \"three-point field goa\"",
"Roger Bannister was the first man to run a mile in less than 4 minutes, but he only held the record for 46 days",
"The longest cricket match took place in 1939 between England and South Africa. After 14 days it ended with a tie",
"It would take 370 parking spaces to cover an ordinary soccer field.",
"The only 2 sports to be played on the moon are Javelin and Golf.",
"Jaromir Jagr is the oldest player in the NHL at 45 years old"];

var facts = ["Turtles can breathe out of their anus."
var techFacts = ["In 1986, Apple launched a clothing line",
"The first cell phone weighed nearly 2 pounds (800 g) and sold for $3,995",
"Google's name came from the mathmetical term Googol, which represents a 1 followed by 100 zeros 💻",
"In the 90s, BackRub was one of the working names for what ultimately became known as Google",
"Steve Jobs came up with many innovation ideas while on acid",
"Doug Engelbart created the very first computer mouse from wood in 1964",
"The first alarm clock ever made could only ring at 4am",
"The .gif file format is supposd to be pronounced \"gif\"",
"In 2012, at least 17 newborn girls were named Siri"];

var animalFacts = ["Turtles can breathe out of their anus",
"Wildebeests take turns sleeping, with some members of the herd looking out for predators during the night",
"At almost 19 feet long, the king cobra is the longest venomous snake in the world 🐍",
"A mole can dig a surface level tunnel at a rate of 18 feet per hour",
"The manatee's closest living animal relative is the elephant",
"Hippos produce their own sunscreen. They secrete a sticky, reddish sweat that scatters light",
"Aardvarks are extremely good diggers thanks to strong arms and spoon-shaped claws",
"Some female species of Tarantulas can live for up to 30 years",
"The worlds largest Tarantula, the Goliath Bird-Eater, can grow up to a foot in diameter",
"Corgis were originally bred for short legs as herding dogs so they could nip at the heels of cattle and sleep",
"The ancient Greek word for butterfly is \"psyche\", which is also the word for \"soul\" 👻"];




var randomFacts = ["Turtles can breathe out of their anus."
,"A human's eyes never grow from the day they were born."
,"Hay gente en los arboles."
,"Me gusta la escuela de Penn State."
,"Penn State Behrend is the best campus in PA."
,"Penn State Behrend is the best campus in the US."
,"It's 2:03 am and Michigan still sucks"
,"Behrend bois best bois."
,"\"I\" comes before \"e\", except after \"c.\""
,"The best, the best, the best, the best..."
,"We're just two lost souls swimming in a fish bowl, year after year.  Running over the same old ground, how we found the same old fears, I wish you were here."
,"Pink Floyd best Floyd."
,"Turtles never outgrow their shell; rather, their shell outgrows them."
,"This is the best project submission for this challenge.  Hands down.  GGWP, no Re."
,"This is the best project submission for this challenge.  Hands down."
,"REEEEEEEEEEEEE!"
,"It is presently 1:34 am at the time of typing this sentence."
,"I don't know what I'm doing, but I'm living life."
@@ -20,17 +53,108 @@ var facts = ["Turtles can breathe out of their anus."
,"1 like = 1 prayer"
,"Help me, I've been forced to type this.  If you don't click f to pay respects, I may never return."
,"Behrend > Main Campus"
,"Programming is the most meaningful part of my life, I cannot wait to live a life of no sleep, only code, counting starting from 0 when grabbing things and having no life."
,"I am the muffin man."
,"I am the walrus."];

,"Programming is the most meaningful part of my life, I cannot wait to live a life of no sleep, only code, counting starting from 0 when grabbing things and having no life."];
/*
var vinElem = document.getElementById('vin');
gm.info.getVehicleConfiguration(function(data) {
  vinElem.innerHTML = gm.info.getVIN();
});
*/


var handler = {};

handler.onKeyClick = function(key)
{
  switch(key)
  {

    /*
    case 'BTN_BACK':
      //to do when button pressed
      var fact = document.getElementById('funfact');
      {
        fact.innerHTML = randomFacts[Math.floor(Math.random() * randomFacts.length)];
        gm.ui.showAlert({
          alertTitle: 'Hey!',
          alertDetail: 'Don/t text and drive!'
        })
      }
      break;
*/
    case 'BTN_PREV':
      //to do when button pressed
      var fact = document.getElementById('funfact');
      {
        fact.innerHTML = techFacts[Math.floor(Math.random() * techFacts.length)];
        gm.voice.startTTS(function(){}, fact.innerHTML);
      }
      break;

    case 'BTN_NEXT':
    //to do when button pressed
      var fact = document.getElementById('funfact');
      {
        fact.innerHTML = animalFacts[Math.floor(Math.random() * animalFacts.length)];
        gm.voice.startTTS(function(){}, fact.innerHTML);
      }
      break;
/*
    case 'BTN_PLAY':
    //to do when button pressed
      var fact = document.getElementById('funfact');
      {
        fact.innerHTML = sportsFacts[Math.floor(Math.random() * sportsFacts.length)];
        gm.voice.startTTS(function(){}, fact.innerHTML);
      }
      break;
*/
    case 'BTN_BACK':
      gm.voice.startTTS(function(){}, 'Shoutout to @GM for sponsoring HackPSU and letting us develop software for their vehicles!');
      break;
  }
}

var btnmanager = gmExt.newHardButtonManager(handler, ['BTN_BACK', 'BTN_PREV', 'BTN_NEXT', 'BTN_PLAY']);







//var id = gm.info.watchButtons(handleButton1, ['BTN_NEXT']);


/*
function handleButton1(btnList) {

  if (btnList.indexOf('BTN_NEXT') >= 0) {
    //button is pressed
    var fact = document.getElementById('funfact');
    {
      fact.innerHTML = facts[Math.floor(Math.random() * facts.length)];
    }
  }  
  else {
    //button is released
    var fact = document.getElementById('funfact');
    {
      fact.innerHTML = facts[Math.floor(Math.random() * facts.length)];
    }
  }  
}
gm.info.clearButtons(id);
*/

//
//
//end changes


/*
var fact = document.getElementById('funfact');
{
  fact.innerHTML = facts[Math.floor(Math.random() * facts.length)];
}
*/

src/js/ngi.polyfill.min.js

100644 → 100755
+0 −0

File mode changed from 100644 to 100755.