Skip to content

Instantly share code, notes, and snippets.

@wtsnz
Created September 11, 2011 22:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wtsnz/1210220 to your computer and use it in GitHub Desktop.
Save wtsnz/1210220 to your computer and use it in GitHub Desktop.
HaXe NME Vibrate for WebOS
// --- vibrateDevice---------------
value nme_vibrate_device()
{
#ifdef WEBOS
VibrateDevice();
return alloc_null(true);
#enif
}
DEFINE_PRIM(nme_vibrate_device,0);
package nme.ui;
#if !flash
class Haptic
{
static var nme_vibrate_device = nme.Loader.load("nme_vibrate_device", 0);
// returns null if device not supported
public function new()
{
//trace("new");
//nme_vibrate_device = nme.Loader.load("nme_vibrate_device", 0);
//ss
//trace("ready");
}
public function vibrate() : Void
{
trace("vibrating");
if (nme_vibrate_device() == true) {
trace("yeah");
} else {
trace("no");
}
nme_vibrate_device();
trace("called");
}
}
#end
So the basic idea is to create a new Haptic(), and then call the vibrate function.
EG:
import nme.ui.Haptic;
var vibration:Haptic;
vibration:Haptic = new Haptic();
vibration.vibrate();
see the Haptic.hx file for the class (File 2)
then I modified the \nekonme\webOS\System.cpp to add a void function called VibrateDevice() (This will eventually have arguments, but I'm not there yet!)
I also added a new function nme_vibrate_device() to the file \nekonme\project\common\ExternalInterface.cpp (I think this is the correct place..)
Although I am not sure whether this function can be a bool? Just return true if the VibrateDevice() function is avaliable, Nor am I sure about what the DEFINE_PRIM does.. Every other one has it, so I just copied.. (DEFINE_PRIM(name, args) I think..)
And my app doesn't make my device vibrate.. D:
#include "PDL.h"
#include <syslog.h>
namespace nme {
bool LaunchBrowser (const char *inUtf8URL) {
PDL_LaunchBrowser (inUtf8URL);
return true;
}
void ExternalInterface_Call (const char *functionName, const char **params, int numParams) {
//syslog (LOG_INFO, "Calling JS");
PDL_JSRegistrationComplete();
//PDL_CallJS("ready", NULL, 0);
PDL_CallJS (functionName, params, numParams);
/*PDL_RegisterJSHandler("setRotationSpeed", setRotationSpeed);
PDL_RegisterJSHandler("setAngle", setRotationSpeed);
PDL_RegisterJSHandler("pause", pause);
PDL_RegisterJSHandler("resume", resume);*/
}
void VibrateDevice(/*int *period, int *duration*/){
PDL_Vibrate(10, 1000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment