1

I am working on the tablet's display of a Pepper robot; I have a functional HTML index page comprising a list of questions—each question redirects to its respective HTML when clicked on—, 2 volume buttons and 2 other buttons—one that pops up an instruction image and the other one that closes the index page and gets back to the splash screen, which when clicked upon, reveals the index page. So far everything is working. The issue is that when I click a question—I get redirected to its HTML page, but then I get stuck there, as neither the 2 volume buttons nor the 2 other buttons work;

I made sure to include the following in each HTML page:

<script type="text/javascript" src="/libs/qimessaging/2/qimessaging.js"></script>
<script type="text/javascript" src="faq.js"></script>

I also reused the same JavaScript functions that worked for the index page.

I commented out some line:

btnPrevious.addEventListener('click', goToPreviousPage);

because I noticed it prevented the splash screen from disappearing when clicked on—i.e., the visibility attribute stays on visible instead of switching to hidden thus revealing the index page, but still, the 3 remaining buttons don't work anyway.

Here is my faq.js code:

/* global QiSession */

var serviceName = 'ADFAQ';
var volumeUpEvent = serviceName + '/VolumeUp';
var volumeDownEvent = serviceName + '/VolumeDown';
var volumeData = serviceName + '/Volume';

/* Clickable buttons */
var btnReturn = document.getElementById('return');
var btnHelp = document.getElementById('call_help');
var btnPrevious = document.getElementById('previous_page');
var btnVolUp = document.getElementById('volume-up');
var btnVolDown = document.getElementById('volume-down');

/* Help image and splash screen */ 
var helper = document.getElementById('helper');
var img = document.getElementById('click_on_me');
var memory;
var volume;
var audioDevice;

QiSession(connected, disconnected);

function connected (s) {
    console.log('QiSession connected');
    var questions = document.getElementById('questions');

    /* Associating buttons to their respective functions */
    btnHelp.addEventListener('click', showHelper);
    btnReturn.addEventListener('click', closeQuestions);
    //btnPrevious.addEventListener('click', goToPreviousPage);

    btnVolUp.addEventListener('click', raiseVolume);
    btnVolDown.addEventListener('click', lowerVolume);
    img.addEventListener('click', loadQuestions);
    questions.addEventListener('click', clickOnQuestion);


    s.service('ALMemory').then(function (m) {
        m.subscriber(serviceName + '/DialogEnded').then(function (subscriber) {
            subscriber.signal.connect(hideQuestions);
        });

        m.subscriber(serviceName + '/Pepper').then(function (subscriber) {
            subscriber.signal.connect(displayPepperHTML)
        });


        m.subscriber(serviceName + '/RaiseVolume').then(function (subscriber) {
            subscriber.signal.connect(raiseVolume);
        });
        m.subscriber(serviceName + '/LowerVolume').then(function (subscriber) {
            subscriber.signal.connect(lowerVolume);
        });

        memory = m;
    });

    s.service('ALAudioDevice').then(function (a) {

        a.getOutputVolume().then(assignVolume);
        audioDevice = a
    });
}

function disconnected () {
    console.log('QiSession disconnected');
}


function assignVolume(value){
    volume = value;
}

function raiseVolume (event) {

    var changed = 0;
    if(volume < 100) {
        volume =  Math.min(volume + 5, 100);
        audioDevice.setOutputVolume(volume);
        changed = 1;
    }
    memory.insertData(volumeData, volume);
    memory.raiseEvent(volumeUpEvent, changed);

}

function lowerVolume (event) {

    var changed = 0;
    if(volume > 30) {
        volume =  Math.max(volume - 5, 0);
        audioDevice.setOutputVolume(volume);
        changed = 1;
    }
    memory.insertData(volumeData, volume);
    memory.raiseEvent(volumeDownEvent, changed);

}

function showHelper (event) {
    if (btnHelp.innerHTML === '?') {
        helper.style.opacity = '1';
        helper.style.zIndex = '1';
        btnHelp.innerHTML = '←';
    } else {
        helper.style.opacity = '0';
        helper.style.zIndex = '-1';
        btnHelp.innerHTML = '?';
    }
    btnHelp.blur();
}

function loadQuestions (event) {
    memory.raiseEvent(serviceName + '/LoadQuestions', 1);
    img.style.visibility = 'hidden';
}

function goToPreviousPage () {
    window.location.href = "index.html";

}

function displayPepperHTML() {
    window.location.href = "pepper.html";
}


function closeQuestions (event) {
    if(location.href != "index.html")
    {window.location.href = "index.html";}
    memory.raiseEvent(serviceName + '/CloseQuestions', 1);
    btnReturn.blur();
}

function hideQuestions (data) {
    if (data !== 0) {
        img.style.visibility = 'visible';
        helper.style.opacity = '0';
        btnHelp.innerHTML = '?';
    }
}

function clickOnQuestion (event) {
    memory.raiseEvent(serviceName + '/' + event.target.id, 1);
}

Here is my non-functioning pepper.html code:

<!DOCTYPE html>
<html lang="fr">

<head>
    <title>Pepper</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=1280, user-scalable=no" />
    <link type="text/css" rel="stylesheet" href="css/style.css" />
    <link type="text/css" rel="stylesheet" href="css/faq.css" />
</head>

<body>

    <header>
        <h1>Bla bla bla</h1>
        <span class="buttons">
            <button id="previous_page" class="button-help"> ← </button>
            <button id="return" class="button-return">X</button>
        </span>

        <div id="helper" class="pop-up">
            <img src="img/interactionscreen_frf.png" alt="Bla bla bla">
        </div>
    </header>


    <ul id="questions">
        <p>
             Bla bla bla
        </p>

        <div class="volume-part">
            <div id="volume-up" class="Click-me">+</div>
            <img src="img/speaker.png" alt="Bla bla bla" style="vertical-align: middle;">
            <div id="volume-down" class="Click-me">-</div>
        </div>

    </ul>

    <script type="text/javascript" src="/libs/qimessaging/2/qimessaging.js"></script>
    <script type="text/javascript" src="faq.js"></script>

</body>

</html>

Thank you for your help.

I am expecting the pepper.html page to respond to both the volume and ← and X buttons, as the index.html should, since they use the exact same Javascript.

YHR78
  • 13
  • 4
  • Are all of your HTML files in the same directory? If they are in a sub-folder they will not be able to find the JS file. – JackU May 06 '19 at 08:56
  • @JackU Yes they are, I have thought about that, thank you for pointing it out. – YHR78 May 06 '19 at 09:04
  • First I would make sure the script is loaded and executing properly by adding a simple `console.log()` at the top and bottom of `faq.js` – Tzach Ovadia May 06 '19 at 09:07
  • @TzachOvadia Thank you for your suggestion, I have tried doing it–it works correctly with `index.html` – YHR78 May 06 '19 at 09:12
  • but not with pepper.html? – Tzach Ovadia May 06 '19 at 09:14
  • @TzachOvadia not with `pepper.html` that's what doesn't make sense to me. Thanks to you, I noticed that the line `QiSession(connected, disconnected);` was blocking the code, because it says `Uncaught ReferenceError: QiSession is not defined` , gonna work on this to see if it changes anything. – YHR78 May 06 '19 at 09:21
  • Actually this error doesn't change a thing, since the `index.html` is fully functional, albeit using the same `faq.js` code – YHR78 May 06 '19 at 09:37

1 Answers1

0

I was able to find some workaround: creating one JavaScript file for each HTML page, this is redundant and non-optimal I know, but at least it works.

This also made me realize that the commented-out line was blocking the program because the index.html page doesn't use the previous_page button, that's what led me to make a JS file for each HTML page.

If anybody has any other suggestions I am all ears.

Edit: I reduced the number of JS scripts to only 2. One for the index.html and the other for the identically-structured html pages of the other questions.

YHR78
  • 13
  • 4