Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
PowerHome General
 PowerHome Messageboard : PowerHome General
Subject Topic: Processing EEG output to control Insteon Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
Brandon
Newbie
Newbie
Avatar

Joined: December 29 2009
Location: United States
Online Status: Offline
Posts: 36
Posted: December 29 2009 at 16:33 | IP Logged Quote Brandon

Hello!

I am new to the PowerHome community (just discovered application last night) and am very excited. It seems I have found exactly what I was looking for.

I have purchased (2) Neurosky Mindset EEGs along with the Insteon PowerLinc Modem (PLM-Serial) and am interested in utilizing the brainwave activity from the EEGs to control (3) LampLinc 2456D3 modules

I am not a programmer (environmental engineer) but will be getting some help from a friend of mine who is comfortable with SQL, Ruby, and C.

I have installed the trial of PowerHome and have setup the PLM and the 3 LampLincs and have begun to work through the PowerHome User Manual.

Below is a workflow schematic of the project.




I look forward to getting acquainted with Powerhome and the forum community. I'd appreciate any links to forums or tutorials that I should be checking out.

Brandon
Back to Top View Brandon's Profile Search for other posts by Brandon
 
Brandon
Newbie
Newbie
Avatar

Joined: December 29 2009
Location: United States
Online Status: Offline
Posts: 36
Posted: January 02 2010 at 16:07 | IP Logged Quote Brandon

Help with Parsing a Global Variable into Multiple Global Variables

I setup the Socket Server Command Line Application and have passed mock EEG data to GLOBAL Variable = SOCKETSERVER

Structure of Global Variable SOCKETSERVER string

"EEG1ADDR: 69.10.10; EEG1MED: 090; EEG1ATT: 075; EEG2ADDR: 10.11.12; EEG2MED: 030; EEG2ATT: 040"

I would now like to parse the content of SOCKETSERVER into multiple global variables.

I tried to do it by using a Macro with the Set Global command formula being mid(SOCKETSERVER, 11 {,8}) for EEG1ADDR and received an error.


Brandon

Back to Top View Brandon's Profile Search for other posts by Brandon
 
BeachBum
Super User
Super User
Avatar

Joined: April 11 2007
Location: United States
Online Status: Offline
Posts: 1880
Posted: January 02 2010 at 16:42 | IP Logged Quote BeachBum

Try this: mid("SOCKETSERVER", 11 ,8)

Don’t know if that is really what your after. Socketserver is a string therefore needs quotes. 8 is optional.

__________________
Pete - X10 Oldie
Back to Top View BeachBum's Profile Search for other posts by BeachBum
 
Brandon
Newbie
Newbie
Avatar

Joined: December 29 2009
Location: United States
Online Status: Offline
Posts: 36
Posted: January 02 2010 at 17:18 | IP Logged Quote Brandon

BeachBum wrote:
Try this: mid("SOCKETSERVER", 11 ,8)

Don’t know if that is really what your after. Socketserver is a string therefore needs quotes. 8 is optional.


I tried your suggestion and it returns "ER" from the text "SOCKETSERVER". What I am trying to do is return text from the variable.

What was returned: ER
What I am trying to get out: 69.10.10
Back to Top View Brandon's Profile Search for other posts by Brandon
 
BeachBum
Super User
Super User
Avatar

Joined: April 11 2007
Location: United States
Online Status: Offline
Posts: 1880
Posted: January 02 2010 at 18:44 | IP Logged Quote BeachBum

I use something like this:

ph_setvar_a(3,27, posw(ph_getvar_s(3,21),"$$",ph_getvar_n(3,26)))

And then I do a mid to get the date into a global:

mid(ph_getvar_s(3,21), ph_getvar_n(3,26), ph_getvar_n(3,27) - ph_getvar_n(3,26) )


__________________
Pete - X10 Oldie
Back to Top View BeachBum's Profile Search for other posts by BeachBum
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: January 02 2010 at 19:20 | IP Logged Quote dhoward

For the sample global you've posted above, you can use this:
Code:
ph_regexdiff1(": ",";",ph_getglobal_s("SOCKETSERVER"),1,4,0,0,0)


This will extract out a single value from the string. In the code above, it extracts the 4th value. To change the code to extract out the first, second, third, etc. value, just change the "4" to be the instance you wish to extract. You can then use the Macro command "Set Global" to assign the extracted value to the global of your choice.

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
Brandon
Newbie
Newbie
Avatar

Joined: December 29 2009
Location: United States
Online Status: Offline
Posts: 36
Posted: January 02 2010 at 23:30 | IP Logged Quote Brandon

dhoward wrote:
You can then use the Macro command "Set Global" to assign the extracted value to the global of your choice.


How do I structure the Send Keys / TTS / Dim / Formula area for the Get Global command?

I am a little confused about how formula results are then accessible as variables. Is the result of the ph_regexdiff1 formula always stored in a specific location?

Thanks,
Brandon
Back to Top View Brandon's Profile Search for other posts by Brandon
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: January 03 2010 at 00:09 | IP Logged Quote dhoward

Brandon,

The macro line would look like this:

10 Set Global EEG1ADDR ph_regexdiff1(": ",";",ph_getglobal_s("SOCKETSERVER"),1,4,0,0,0)

*Most* of the macro commands with the Send Keys/TTS/Dim/Formula field not grayed out are expecting a formula. A formula can be as simple as the number 1. You could also make the formula a string (strings must be enclosed in double or single quotes). So the following are all formulas:

1
"Test1"
'Test2'
5 * 2
"Test1" + ' ' + "Test2"
"The result of 5 * 2 is " + string(5 * 2)

A formula can result in either a string, a number, a date, a time, or a datetime. The key is that you cannot mix terms (string and number) without casting one or the other like I did with the result of 5 * 2 in the last formula.

The output of the ph_regexdiff1 formula is a string, the result of which will be assigned to the global. To validate your formulas, just right-click the field and select "Check Formula" to make sure that there are no errors.

Hope this helps,

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
Brandon
Newbie
Newbie
Avatar

Joined: December 29 2009
Location: United States
Online Status: Offline
Posts: 36
Posted: January 06 2010 at 18:38 | IP Logged Quote Brandon

dhoward
Hope this helps,

Dave.
[/QUOTE wrote:


Yes, it did! Thanks

Brandon


Yes, it did! Thanks

Brandon
Back to Top View Brandon's Profile Search for other posts by Brandon
 
Brandon
Newbie
Newbie
Avatar

Joined: December 29 2009
Location: United States
Online Status: Offline
Posts: 36
Posted: January 18 2010 at 17:58 | IP Logged Quote Brandon

I'm having trouble with the Insteon On command

I'm trying to pass a global variable as the control for cmd2 of an Insteon On command for a lamplinc




When I do an integer("MINDSET1-ATT") it is evaluated to a 0 yet MINDSET1-ATT is set to 150.

Back to Top View Brandon's Profile Search for other posts by Brandon
 
grif091
Super User
Super User


Joined: March 26 2008
Location: United States
Online Status: Offline
Posts: 1357
Posted: January 18 2010 at 18:08 | IP Logged Quote grif091

Try   ph_getglobal_n("MINDSET1-ATT")   This worked in an Insteon command test here.

Edited by grif091 - January 18 2010 at 18:11


__________________
Lee G
Back to Top View grif091's Profile Search for other posts by grif091
 
Brandon
Newbie
Newbie
Avatar

Joined: December 29 2009
Location: United States
Online Status: Offline
Posts: 36
Posted: January 18 2010 at 18:10 | IP Logged Quote Brandon

sweet! thanks grif
Back to Top View Brandon's Profile Search for other posts by Brandon
 
Brandon
Newbie
Newbie
Avatar

Joined: December 29 2009
Location: United States
Online Status: Offline
Posts: 36
Posted: January 18 2010 at 18:44 | IP Logged Quote Brandon

Another Question::

Massaging Data in a Global Variable.

I am using ph_readfile to copy the EEG output (.txt file) into PowerHome and assign as a global variable.

Structure of EEG Output file (.txt):

Global Variable - MINDSET1-OUTPUT

Att: 40; Med: 51;
Att: 53; Med: 56;
Att: 53; Med: 61;
Att: 43; Med: 66;
Att: 44; Med: 77;
Att: 27; Med: 63;


Is there a way where I can lookup MINDSET1-OUTPUT and copy only the last line into a new global variable?

Back to Top View Brandon's Profile Search for other posts by Brandon
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: January 18 2010 at 19:11 | IP Logged Quote dhoward

Code:
ph_setglobal_s("NEW-GLOBAL",mid(ph_getglobal_s("MINDSET1-OUT PUT",lastpos(ph_getglobal_s("MINDSET1-OUTPUT"),"~r~n") + 2))


Didnt actually verify but the above should work.

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
Brandon
Newbie
Newbie
Avatar

Joined: December 29 2009
Location: United States
Online Status: Offline
Posts: 36
Posted: January 18 2010 at 22:49 | IP Logged Quote Brandon

dhoward wrote:
Code:
ph_setglobal_s("NEW-GLOBAL",mid(ph_getglobal_s("MINDSET1-OUT PUT",lastpos(ph_getglobal_s("MINDSET1-OUTPUT"),"~r~n") + 2))


Didnt actually verify but the above should work.

Dave.


Dave:

couldn't get the code above to work. will play around with some.

Back to Top View Brandon's Profile Search for other posts by Brandon
 
grif091
Super User
Super User


Joined: March 26 2008
Location: United States
Online Status: Offline
Posts: 1357
Posted: January 19 2010 at 04:21 | IP Logged Quote grif091

These statements work here. I used MINDSET1-DATA Global variable for the last line of data in MINDSET1-OUTPUT which was read from a file eegdata.txt.

ph_setglobal_s("MINDSET1-OUTPUT", ph_readfile("c:\temp\eegdata.txt"))

ph_setglobal_s("MINDSET1-DATA",mid(ph_getglobal_s("MINDSET1- OUTPUT"),lastpos(ph_getglobal_s("MINDSET1-OUTPUT"),"~r~n") + 2))

Note that the forum post is adding a blank in the MINDSET1-OUTPUT string that has to be removed once put into a macro.

This assumes there is no cr/nl after the last data line. If there is a cr/nl on the last line then change the + 2 to - 17.

Edited by grif091 - January 19 2010 at 11:21


__________________
Lee G
Back to Top View grif091's Profile Search for other posts by grif091
 
Brandon
Newbie
Newbie
Avatar

Joined: December 29 2009
Location: United States
Online Status: Offline
Posts: 36
Posted: January 19 2010 at 14:10 | IP Logged Quote Brandon

grif091 wrote:
These statements work here. I used MINDSET1-DATA Global variable for the last line of data in MINDSET1-OUTPUT which was read from a file eegdata.txt.

ph_setglobal_s("MINDSET1-OUTPUT", ph_readfile("c:\temp\eegdata.txt"))

ph_setglobal_s("MINDSET1-DATA",mid(ph_getglobal_s("MINDSET1- OUTPUT"),lastpos(ph_getglobal_s("MINDSET1-OUTPUT"),"~r~n") + 2))

Note that the forum post is adding a blank in the MINDSET1-OUTPUT string that has to be removed once put into a macro.

This assumes there is no cr/nl after the last data line. If there is a cr/nl on the last line then change the + 2 to - 17.


Thanks grif! I'll try it out when I get home.

I am happy to report that I was able to use my EEG to control 2 LampLincs last night. One light was controlled by my attention level and one by my meditation level.

Question:

I want to keep looping my macro that handles the .txt file with the EEG data as long as new data is being added to the file.

Is there a way where I can look at a file, and if the last line is a certain text ["Process has ended"] it will stop the loop?

End Question:

I am also happy to report that I am now a registered user of PowerHome.

Thanks,
Bt

Back to Top View Brandon's Profile Search for other posts by Brandon
 
grif091
Super User
Super User


Joined: March 26 2008
Location: United States
Online Status: Offline
Posts: 1357
Posted: January 19 2010 at 15:10 | IP Logged Quote grif091

Congratulations on joining Powerhome.

The statement I posted is Dave's suggestion with the addition of a right paren on the end of one of the imbedded ph_xxx commands.

There are Macro   Label XXXXX and Goto statements that allow looping within a Macro. Something like

Goto   if (ph_getglobal_s("MINDSET1-DATA") <> "Process has ended", "XXXXX", "Done")    

This has the effect of comparing the last line from the file to "Process has ended", if not equal the Goto goes to Label "XXXXX" which would be coded at the beginning of the Macro. Otherwise, the Goto goes to Label "Done" which is not defined so the next sequential Macro statement is executed, probably the end of the Macro.

The problem with this approach is the Macro constantly runs until it finds the "Process has ended" line in the file. The PC will be running in basically a process bound loop which is not good.

How do you invoke the Macro now? Ideally the Macro should run only when something new has been written to the file.


__________________
Lee G
Back to Top View grif091's Profile Search for other posts by grif091
 
Brandon
Newbie
Newbie
Avatar

Joined: December 29 2009
Location: United States
Online Status: Offline
Posts: 36
Posted: January 20 2010 at 17:55 | IP Logged Quote Brandon

grif091 wrote:
Congratulations on joining Powerhome.

How do you invoke the Macro now? Ideally the Macro should run only when something new has been written to the file.


I hear what you are saying. I am going to install the PowerHome File Monitor plugin to work with.

Brandon
Back to Top View Brandon's Profile Search for other posts by Brandon
 
Brandon
Newbie
Newbie
Avatar

Joined: December 29 2009
Location: United States
Online Status: Offline
Posts: 36
Posted: January 21 2010 at 15:01 | IP Logged Quote Brandon

Using PowerHome and the File Monitor plugin my project of controlling lights via EEG brainwave activity is off to a good start.

I was able to control 2 lamps last night via the brainwave activity of 1 EEG. One lamp was controlled by my Attention value and the other was controlled by my Meditation value.



Cool stuff! Thanks guys.
Back to Top View Brandon's Profile Search for other posts by Brandon
 

Page of 2 Next >>
  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum