Commit 0590385c authored by Giacomo Lavermicocca's avatar Giacomo Lavermicocca
Browse files

Fix bugs - add Array data pattern comunication

parent b4a4c919
Loading
Loading
Loading
Loading
+20 −112
Changes for AddOn/addon.cc: 20 added lines, 112 removed lines.
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@
#include <math.h>
#include <unistd.h>
#include <cstdio>
#include <iostream>

namespace demo {

@@ -53,9 +54,8 @@ void displayImage(__u16 bmp[], int res, int daddress, int file)
		block[i] = (bmp[i] & 0xfe) >> 1 |
			(bmp[i] & 0x01) << 7;
	}
	i2c_smbus_write_i2c_block_data(file, daddress, 16,
		(__u8 *)block);
	usleep(100000);
	i2c_smbus_write_i2c_block_data(file, daddress, 16, (__u8 *)block);
	//usleep(100000);
}

void  INThandler(int sig)
@@ -182,42 +182,11 @@ int SetFile(int _i2cbus, int _address) //Setta le variabili iniziali...
	return 0;
}

void Write(const FunctionCallbackInfo<Value>& args) {
	Isolate* isolate = args.GetIsolate();

	if (args.Length() < 4) {
		isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Wrong arguments")));
		return;
	}

	if (!args[0]->IsNumber() || !args[1]->IsNumber() || !args[2]->IsNumber() || !args[3]->IsNumber()) {
		isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Wrong type of arguments")));
		return;
	}

	int ROW = 0;
	int VALUE = 0;
	// get the param
	ROW = args[0]->ToInteger()->Value();
	VALUE = args[1]->ToInteger()->Value();

	int _i2cbus = args[2]->ToInteger()->Value();
	int _address = args[3]->ToInteger()->Value();

	SetFile(_i2cbus, _address);  //Devo settare /dev/i2c... tutte le volte

	i2c_smbus_write_byte_data(file, ROW, VALUE);

	close(file);

	args.GetReturnValue().Set(String::NewFromUtf8(isolate, "end of job"));
}

void WriteAllFrames(const FunctionCallbackInfo<Value>& args) {
	Isolate* isolate = args.GetIsolate();

	if (args.Length() < 4) {
		isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Wrong number arguments")));
	if (!args[0]->IsArray()) {
		isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Array - Wrong type of arguments")));
		return;
	}

@@ -233,58 +202,28 @@ void WriteAllFrames(const FunctionCallbackInfo<Value>& args) {
	SetFile(_i2cbus, _address);  //Devo settare /dev/i2c... tutte le volte

	Local<Array> FirstArray = Local<Array>::Cast(args[0]);
	Local<Array> SecondArray;
	// ... init obj from arguments or wherever ...

	//// ... init obj from arguments or wherever ...

	int length = FirstArray->Length();
	int VALUE = 0;

	//for (int i = 0; i < length; i++)
	//{
	//	// do something with element
	//	SecondArray = Local<Array>::Cast(FirstArray->Get(Number::New(i)));
	//	for (int n = 0; n < 16; n++) {
	//		VALUE = SecondArray->Get(Number::New(n))->ToInteger()->Value();
	//		i2c_smbus_write_byte_data(file, n, VALUE);
	//	}
	//	usleep(50000 * velocity);
	//}

	close(file);

	args.GetReturnValue().Set(String::NewFromUtf8(isolate, "end of 'WRITE ALL FRAMES' job"));
}

void WriteSleep(const FunctionCallbackInfo<Value>& args) {
	Isolate* isolate = args.GetIsolate();
	for (int n = 0; n < length; n++) {
		VALUE = FirstArray->Get(n)->ToInteger()->Value();
		int i = n % 16;
		i2c_smbus_write_byte_data(file, i, VALUE);

	if (args.Length() < 5) {
		isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Wrong number arguments")));
		return;
		if (i == 15)
		{
			usleep(1000 * velocity);
		}

	if (!args[0]->IsNumber() || !args[1]->IsNumber() || !args[2]->IsNumber() || !args[3]->IsNumber() || !args[4]->IsNumber()) {
		isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Wrong type of arguments")));
		return;
		//std::cout << VALUE << " " << i;
		//std::cout << std::endl;
	}

	int ROW = 0;
	int VALUE = 0;
	// get the param
	ROW = args[0]->ToInteger()->Value();
	VALUE = args[1]->ToInteger()->Value();

	int _i2cbus = args[2]->ToInteger()->Value();
	int _address = args[3]->ToInteger()->Value();
	int delay = args[4]->ToInteger()->Value();

	SetFile(_i2cbus, _address);  //Devo settare /dev/i2c... tutte le volte

	i2c_smbus_write_byte_data(file, ROW, VALUE);

	sleep(delay);
	close(file);

	args.GetReturnValue().Set(String::NewFromUtf8(isolate, "end of job"));
	args.GetReturnValue().Set(String::NewFromUtf8(isolate, "end of 'WRITE ALL FRAMES' job"));
}

void Begin(const FunctionCallbackInfo<Value>& args) {
@@ -311,44 +250,13 @@ void Begin(const FunctionCallbackInfo<Value>& args) {
void Exit(const FunctionCallbackInfo<Value>& args) {
	//LOOP = false;
	Isolate* isolate = args.GetIsolate();
	Exit();
	args.GetReturnValue().Set(String::NewFromUtf8(isolate, "Exit"));
}

// This is the implementation of the "add" method
// Input arguments are passed using the
// const FunctionCallbackInfo<Value>& args struct
void Add(const FunctionCallbackInfo<Value>& args) {
  Isolate* isolate = args.GetIsolate();

  // Check the number of arguments passed.
  if (args.Length() < 2) {
    // Throw an Error that is passed back to JavaScript
    isolate->ThrowException(Exception::TypeError(
        String::NewFromUtf8(isolate, "Wrong number of arguments")));
    return;
  }

  // Check the argument types
  if (!args[0]->IsNumber() || !args[1]->IsNumber()) {
    isolate->ThrowException(Exception::TypeError(
        String::NewFromUtf8(isolate, "Wrong arguments")));
    return;
  }

  // Perform the operation
  double value = args[0]->NumberValue() + args[1]->NumberValue();
  Local<Number> num = Number::New(isolate, value);

  // Set the return value (using the passed in
  // FunctionCallbackInfo<Value>&)
  args.GetReturnValue().Set(num);
}

void Init(Local<Object> exports) {
  NODE_SET_METHOD(exports, "add", Add);
  NODE_SET_METHOD(exports, "Write", Write);

  NODE_SET_METHOD(exports, "WriteAllFrames", WriteAllFrames);
  NODE_SET_METHOD(exports, "WriteSleep", WriteSleep);
  NODE_SET_METHOD(exports, "Begin", Begin);
  NODE_SET_METHOD(exports, "Exit", Exit);
}
+2 −2
Changes for AddOn/build/Makefile: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -308,8 +308,8 @@ ifeq ($(strip $(foreach prefix,$(NO_LOAD),\
endif

quiet_cmd_regen_makefile = ACTION Regenerating $@
cmd_regen_makefile = cd $(srcdir); /usr/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py -fmake --ignore-environment "--toplevel-dir=." -I/root/Matrix8x8/AddOn1/build/config.gypi -I/usr/lib/node_modules/npm/node_modules/node-gyp/addon.gypi -I/root/.node-gyp/8.5.0/include/node/common.gypi "--depth=." "-Goutput_dir=." "--generator-output=build" "-Dlibrary=shared_library" "-Dvisibility=default" "-Dnode_root_dir=/root/.node-gyp/8.5.0" "-Dnode_gyp_dir=/usr/lib/node_modules/npm/node_modules/node-gyp" "-Dnode_lib_file=/root/.node-gyp/8.5.0/<(target_arch)/node.lib" "-Dmodule_root_dir=/root/Matrix8x8/AddOn1" "-Dnode_engine=v8" binding.gyp
Makefile: $(srcdir)/../../.node-gyp/8.5.0/include/node/common.gypi $(srcdir)/build/config.gypi $(srcdir)/binding.gyp $(srcdir)/../../../usr/lib/node_modules/npm/node_modules/node-gyp/addon.gypi
cmd_regen_makefile = cd $(srcdir); /usr/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py -fmake --ignore-environment "--toplevel-dir=." -I/root/matrix8x8_bicolor/AddOn/build/config.gypi -I/usr/lib/node_modules/npm/node_modules/node-gyp/addon.gypi -I/root/.node-gyp/8.6.0/include/node/common.gypi "--depth=." "-Goutput_dir=." "--generator-output=build" "-Dlibrary=shared_library" "-Dvisibility=default" "-Dnode_root_dir=/root/.node-gyp/8.6.0" "-Dnode_gyp_dir=/usr/lib/node_modules/npm/node_modules/node-gyp" "-Dnode_lib_file=/root/.node-gyp/8.6.0/<(target_arch)/node.lib" "-Dmodule_root_dir=/root/matrix8x8_bicolor/AddOn" "-Dnode_engine=v8" binding.gyp
Makefile: $(srcdir)/../../.node-gyp/8.6.0/include/node/common.gypi $(srcdir)/build/config.gypi $(srcdir)/binding.gyp $(srcdir)/../../../usr/lib/node_modules/npm/node_modules/node-gyp/addon.gypi
	$(call do_cmd,regen_makefile)

# "all" is a concatenation of the "all" targets from all the included
+11 −11
Changes for AddOn/build/Release/.deps/Release/obj.target/addon/addon.o.d: 11 added lines, 11 removed lines.
Original line number Diff line number Diff line
cmd_Release/obj.target/addon/addon.o := g++ '-DNODE_GYP_MODULE_NAME=addon' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DBUILDING_NODE_EXTENSION' -I/root/.node-gyp/8.5.0/include/node -I/root/.node-gyp/8.5.0/src -I/root/.node-gyp/8.5.0/deps/uv/include -I/root/.node-gyp/8.5.0/deps/v8/include  -fPIC -pthread -Wall -Wextra -Wno-unused-parameter -O3 -fno-omit-frame-pointer -fno-rtti -fno-exceptions -std=gnu++0x -MMD -MF ./Release/.deps/Release/obj.target/addon/addon.o.d.raw   -c -o Release/obj.target/addon/addon.o ../addon.cc
cmd_Release/obj.target/addon/addon.o := g++ '-DNODE_GYP_MODULE_NAME=addon' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DBUILDING_NODE_EXTENSION' -I/root/.node-gyp/8.6.0/include/node -I/root/.node-gyp/8.6.0/src -I/root/.node-gyp/8.6.0/deps/uv/include -I/root/.node-gyp/8.6.0/deps/v8/include  -fPIC -pthread -Wall -Wextra -Wno-unused-parameter -O3 -fno-omit-frame-pointer -fno-rtti -fno-exceptions -std=gnu++0x -MMD -MF ./Release/.deps/Release/obj.target/addon/addon.o.d.raw   -c -o Release/obj.target/addon/addon.o ../addon.cc
Release/obj.target/addon/addon.o: ../addon.cc \
 /root/.node-gyp/8.5.0/include/node/node.h \
 /root/.node-gyp/8.5.0/include/node/v8.h \
 /root/.node-gyp/8.5.0/include/node/v8-version.h \
 /root/.node-gyp/8.5.0/include/node/v8config.h \
 /root/.node-gyp/8.5.0/include/node/node_version.h ../i2c-dev.h \
 /root/.node-gyp/8.6.0/include/node/node.h \
 /root/.node-gyp/8.6.0/include/node/v8.h \
 /root/.node-gyp/8.6.0/include/node/v8-version.h \
 /root/.node-gyp/8.6.0/include/node/v8config.h \
 /root/.node-gyp/8.6.0/include/node/node_version.h ../i2c-dev.h \
 ../8x8font.h
../addon.cc:
/root/.node-gyp/8.5.0/include/node/node.h:
/root/.node-gyp/8.5.0/include/node/v8.h:
/root/.node-gyp/8.5.0/include/node/v8-version.h:
/root/.node-gyp/8.5.0/include/node/v8config.h:
/root/.node-gyp/8.5.0/include/node/node_version.h:
/root/.node-gyp/8.6.0/include/node/node.h:
/root/.node-gyp/8.6.0/include/node/v8.h:
/root/.node-gyp/8.6.0/include/node/v8-version.h:
/root/.node-gyp/8.6.0/include/node/v8config.h:
/root/.node-gyp/8.6.0/include/node/node_version.h:
../i2c-dev.h:
../8x8font.h:

AddOn/build/Release/addon.node

100644 → 100755
−152 B (18.2 KiB)

File changed.File mode changed from 100644 to 100755.

No diff preview for this file type.

−152 B (18.2 KiB)

File changed.File mode changed from 100644 to 100755.

No diff preview for this file type.

Loading