AI2 Component  (Version nb184)
Ev3Sound.java
Go to the documentation of this file.
1 // -*- mode: java; c-basic-offset: 2; -*-
2 // Copyright 2016 MIT, All rights reserved
3 // Released under the Apache License, Version 2.0
4 // http://www.apache.org/licenses/LICENSE-2.0
5 package com.google.appinventor.components.runtime;
6 
18 
19 import android.util.Log;
20 
21 import java.io.BufferedInputStream;
22 import java.io.File;
23 import java.io.FileInputStream;
24 import java.io.IOException;
25 import java.io.InputStream;
26 import java.io.UnsupportedEncodingException;
27 import java.nio.ByteBuffer;
28 import java.nio.ByteOrder;
29 import java.util.ArrayList;
30 import java.util.List;
31 
41 @DesignerComponent(version = YaVersion.EV3_SOUND_COMPONENT_VERSION,
42  description = "A component that provides a high-level interface to " +
43  "sound functionalities on LEGO MINDSTORMS EV3 robot.",
44  category = ComponentCategory.LEGOMINDSTORMS,
45  nonVisible = true,
46  iconName = "images/legoMindstormsEv3.png")
47 @SimpleObject
48 @UsesPermissions(permissionNames = "android.permission.INTERNET," +
49  "android.permission.WRITE_EXTERNAL_STORAGE," +
50  "android.permission.READ_EXTERNAL_STORAGE")
51 public class Ev3Sound extends LegoMindstormsEv3Base {
55  public Ev3Sound(ComponentContainer container) {
56  super(container, "Ev3Sound");
57  }
58 
62  @SimpleFunction(description = "Make the robot play a tone.")
63  public void PlayTone(int volume, int frequency, int milliseconds) {
64  String functionName = Thread.currentThread().getStackTrace()[1].getMethodName();
65 
66  if (volume < 0 || volume > 100 || frequency < 250 || frequency > 10000 || milliseconds < 0 || milliseconds > 0xffff) {
67  form.dispatchErrorOccurredEvent(this, functionName, ErrorMessages.ERROR_EV3_ILLEGAL_ARGUMENT, functionName);
68  return;
69  }
70 
72  true,
73  0,
74  0,
75  "cccc",
76  (byte) Ev3Constants.SoundSubcode.TONE,
77  (byte) volume,
78  (short) frequency,
79  (short) milliseconds);
80  sendCommand(functionName, command, true);
81  }
82 
86  @SimpleFunction(description = "Stop any sound on the robot.")
87  public void StopSound() {
88  String functionName = Thread.currentThread().getStackTrace()[1].getMethodName();
90  false,
91  0,
92  0,
93  "c",
95  sendCommand(functionName, command, false);
96  }
97 }
com.google.appinventor.components.runtime.util.YailList
Definition: YailList.java:26
com.google.appinventor.components.annotations.SimpleFunction
Definition: SimpleFunction.java:23
com.google.appinventor.components.runtime.util.ErrorMessages
Definition: ErrorMessages.java:17
com.google.appinventor.components.runtime.util.Ev3Constants.SoundSubcode
Definition: Ev3Constants.java:299
com.google.appinventor.components.runtime.util
-*- mode: java; c-basic-offset: 2; -*-
Definition: AccountChooser.java:7
com.google.appinventor.components.common.YaVersion
Definition: YaVersion.java:14
com.google.appinventor.components
com.google.appinventor.components.runtime.util.Ev3BinaryParser
Definition: Ev3BinaryParser.java:21
com.google.appinventor.components.runtime.Ev3Sound.Ev3Sound
Ev3Sound(ComponentContainer container)
Definition: Ev3Sound.java:55
com.google.appinventor.components.runtime.util.Ev3Constants.Opcode
Definition: Ev3Constants.java:15
com.google.appinventor.components.runtime.util.MediaUtil
Definition: MediaUtil.java:53
com.google.appinventor.components.annotations.DesignerComponent
Definition: DesignerComponent.java:22
com.google.appinventor.components.runtime.util.Ev3BinaryParser.encodeDirectCommand
static byte[] encodeDirectCommand(byte opcode, boolean needReply, int globalAllocation, int localAllocation, String paramFormat, Object... parameters)
Definition: Ev3BinaryParser.java:506
com.google.appinventor.components.runtime.Ev3Sound
Definition: Ev3Sound.java:51
com.google.appinventor.components.annotations.UsesPermissions
Definition: UsesPermissions.java:21
com.google.appinventor.components.runtime.LegoMindstormsEv3Base
Definition: LegoMindstormsEv3Base.java:24
com.google.appinventor.components.runtime.ComponentContainer
Definition: ComponentContainer.java:16
com.google.appinventor.components.runtime
Copyright 2009-2011 Google, All Rights reserved.
Definition: AccelerometerSensor.java:8
com.google.appinventor.components.common
Definition: ComponentCategory.java:7
com.google.appinventor.components.common.ComponentCategory
Definition: ComponentCategory.java:48
com.google.appinventor.components.annotations.SimpleObject
Definition: SimpleObject.java:23
com.google
com
com.google.appinventor.components.runtime.util.ErrorMessages.ERROR_EV3_ILLEGAL_ARGUMENT
static final int ERROR_EV3_ILLEGAL_ARGUMENT
Definition: ErrorMessages.java:216
com.google.appinventor.components.runtime.util.Ev3Constants
Definition: Ev3Constants.java:14
com.google.appinventor.components.annotations
com.google.appinventor