⚛️ Atom 2 Smart Remote   🚚 FREE FEDEX SHIPPING from 397 USD   🌎 WORLDWIDE SHIPPING for 25 USD

AtomTime

Über

Lassen Sie uns eine einfache Mini-App erstellen, um die Zeit auf der SB Watch mit einer numerischen Tastatur einzustellen. Die Funktionalität wird ähnlich sein wie bei der TimeSmith-App, allerdings können Sie Atom und SB Watch direkt verbinden und benötigen kein Telefon. Diese Miniapp heißt Atom Time!

Technisch gesehen brauchen Sie nur Atom und eine SB Watch, aber diese App unterstützt auch PeekSmith 3 , um die eingegebene Zeit anzuzeigen und Ihnen eine visuelle Rückmeldung über die eingestellte Zeit zu geben. Wenn Sie keinen PeekSmith angeschlossen haben, wird dies ignoriert.

function main() {
  ps.connect('*');
  ps.print('AtomTime');
  sbwatch.connect('SBWatch-155309');
  // sbwatch.setTime('12:00');
}

let time = ''; // the time entered
let timeout = 0; // will contain a timeout ID
let mapping = [ // button layour
  '1', '2', '3',
  '4', '5', '6',
  '7', '8', '9',
  's', '0', 'x'
];
function send() {
  clearTimeout(timeout); // don't trigger send
  if (time === '') return; // nothing to set
  if (time === '9999') {
    sbwatch.setCurrentTime();
  } else {
    sbwatch.setTime(time);
  }
  time = ''; // reset to empty string
}

function onButtonClick(buttonId) {
  let key = mapping[buttonId];
  
  // send immediately
  if (key === 's') {
    send();
    return;
  }
  
  // delete the last number or add a new
  if (key === 'x') {
    if (strLen(time) > 0) time = strSub(time, 0, strLen(time) - 1);
  } else {
    time = time + key;
  }

  // delete the previous timer, and start a new with 4s
  clearTimeout(timeout);
  timeout = setTimeout(send, 4000);

  // display the time entered
  ps.print(`<${time}>`);
}

// displays the processed time, and hand movement indicator
function printFormattedTime(time, moving) {
  if (moving) time = `*${time}*`;
  ps.print(time);
}

// there are events coming from the SB Watch and the buttons of Atom
function onEvent(e) {
  console.log(e.value, e.type, e.source);
  if (e.source === 'sbwatch:hands' && e.type === 'started') {
    atom.vibrate('\'');
    printFormattedTime(e.value, true);
  }
  if (e.source === 'sbwatch:hands' && e.type === 'finished') {
    atom.vibrate('\'');
    printFormattedTime(e.value, false);
  }
  if (e.type === 'click' && e.source === 'atom:button') {
    onButtonClick(parseInt(e.value));
  }
}
ankreuzen