View Poll Results: What do you think of this idea?
Terrible 1 20.00%
I'm cool with it 2 40.00%
Great Idea! 2 40.00%
Voters: 5. You may not vote on this poll

Thread Tools Display Modes
09-19-11, 06:37 AM   #1
Scaarf
A Murloc Raider
Join Date: Sep 2011
Posts: 9
Arduino Project - Threat Level Lamp

Hi guys,

First timer here, but ill get to the point.

I'm working on an university assignment, that requires the use of an Arduino electronic board, the assignment basically had to be awesome so i proposed to make a threat level lamp. Basically what happens is:

No Threat - Lamp is White
Threat Level Low - Lamp turns Green
Threat Level Medium - Lamp turns Yellow
Threat Level High - Lamp turns Red

Of course this is a really simple yet fun idea. I'm suppose to expand on that proposal idea to my lecturer.

I have extremely limited programming knowledge but can learn pretty well. But if you guys can point me out in the right directions, on how newbies can start learning the scripting of WoW addons and etc. It would be greatly appreciated. If you like I can even credit you on help by the end of the assignment.

You could even throw in suggestions and all, would love to hear what you think of it!

Hope to have a lot of talk with you all =)
  Reply With Quote
09-19-11, 07:05 AM   #2
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
You have a big problem ... WoW-AddOns are not allowed to communicate with the system. So you have no way to pass the info from the game to your board.
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
09-19-11, 07:07 AM   #3
Scaarf
A Murloc Raider
Join Date: Sep 2011
Posts: 9
thanks for the fast reply, but doesn't the G15 have something similar to it?

sorry, may be completely missing the mark as im as newbie as it gets.
  Reply With Quote
09-19-11, 08:10 AM   #4
Barjack
A Black Drake
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 89
I believe the G15 LCD stuff is built into WoW, and not something addons can directly access. When you extract UI data there are XML files related to this, but as far as I'm aware this isn't something that addons can override or interact with.

Even if you were to somehow write or acquire an emulator for the LCD (I have no idea if such a thing exists but I would guess not), I don't think threat is even something that WoW sends to be displayed on the LCD (at least according to the layout XML, it is not), so you still wouldn't end up with the data you need.

The only ways I can think of achieving what you want would be to either, 1) peek into WoW's memory directly, or 2) have an addon display threat on the screen in an easily-parsable way, and then write a program to read the screen. From there your program would send its data to the LED.

The first option is probably way too advanced, and uses mechanisms similar to what cheat programs would use, so you'll probably face very significant obstacles designed specifically to prevent what you want to do. This may also violate the ToS or EULA in some way (research this yourself). I wouldn't recommend this to someone new to programming in a million years.

The second is less difficult and probably less risky in terms of any violations (but I still wouldn't necessarily count on that, as they tend to be drawn very widely). But it is still comparatively difficult--you'll have to research yourself how to constantly grab screen data on whatever OS you're using and extract the data you need from those images. If you can do that, the addon part wouldn't be particularly difficult, but if you've never looked at Lua before obviously you will have to learn a little about that along with WoW's widget API so you can make a small coloured texture on-screen somewhere that changes with your threat level, which your program would have to capture and read from.

Honestly, I think both methods are probably way too ambitious for a student without significant programming experience to do as a simple (I assume undergrad) project.

In my opinion, it's best to take the restrictions imposed on addons at face value--addons cannot communicate with the outside world while WoW is running. So if I were you I'd either look at things that can be done by parsing SavedVariables (which isn't very exciting since you have to close WoW before you could run your program), or come up with a different idea. Trying to bypass the restrictions imposed on addons is a pretty advanced task and probably not worth the trouble.

Last edited by Barjack : 09-19-11 at 08:17 AM.
  Reply With Quote
09-19-11, 08:13 AM   #5
Scaarf
A Murloc Raider
Join Date: Sep 2011
Posts: 9
thanks very much for the reply, ill look into it and maybe change my way on working on it/ work on something else =)
  Reply With Quote
09-19-11, 08:54 AM   #6
Vlad
A Molten Giant
 
Vlad's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 793
Reading memory is always safer than giving your program read AND write privileges. On other hand, it's a bit risky and would require too much work outside your field to accomplish.

You COULD make a emulator, that emulates threat levels and gives signals to your dongle thing? I guess you just need some numbers going up and down at certain pace.
  Reply With Quote
09-19-11, 09:47 AM   #7
Scaarf
A Murloc Raider
Join Date: Sep 2011
Posts: 9
hm that's also a good idea, thanks. ill ask the professor
  Reply With Quote
09-19-11, 05:31 PM   #8
Coote
A Scalebane Royal Guard
 
Coote's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 440
I remember seeing a similar project once. Somebody used a light sensor of some sort, with a small frame in the bottom corner of the screen, and monitored it with the Arduino. It lit a series of lights based on their combo points. Your idea is definitely doable this way.
__________________

"This is the fifteen-thousandth four hundredth and ninety-eighth occurence".
  Reply With Quote
09-20-11, 04:14 AM   #9
Clyde_Mobster
A Murloc Raider
Join Date: Aug 2009
Posts: 4
First thing that comes to mind is a mod that reports your threat level to a certain chat channel, you could have a visual basic app to monitor that particular chat log for those lines, then sends it to your Arduino board and then to the lamp of course =)
  Reply With Quote
09-20-11, 05:17 AM   #10
Scaarf
A Murloc Raider
Join Date: Sep 2011
Posts: 9
@TMcMahon51
would u happen to know where to find more information on that project sounds, might give me more clues on what i want/can do.

@Clyde_Mobster
oh sounds great! could you elaborate into finer details on how i can get that to work, judging by the posts earlier it sounds like it wouldn't be possible, but if it works then i can continue with my idea concept!
  Reply With Quote
09-20-11, 05:48 AM   #11
Coote
A Scalebane Royal Guard
 
Coote's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 440
Originally Posted by Scaarf View Post
@TMcMahon51
would u happen to know where to find more information on that project sounds, might give me more clues on what i want/can do.
I believe it was on the old WoW forums, which are long gone.
__________________

"This is the fifteen-thousandth four hundredth and ninety-eighth occurence".
  Reply With Quote
09-20-11, 06:09 AM   #12
Clyde_Mobster
A Murloc Raider
Join Date: Aug 2009
Posts: 4
As for the wow mod, i've seen tons of 'chat announced' things in game from other player's mods, so I'm sure one could be written to announce/send your threat level to a particular chat channel. Chat logging should be turned on so it's sent to a .txt file within the WoW directory.

Then you'd have to have some sort of app that reads this txt file, based on what ever percentage range you want your lamp colors to be, it would send the signal to the Arduino board to activate that color.

My knowledge of Arduino is almost non existent... so I'm just assuming that there is a driver that allows you to hook up the board to the PC using an available port of some type. Making an app/script to read a txt file for a particular string is one of the easiest things to do. However i'm not sure about sending the signal to the board, this is something you'll need to research. My initial suggestion was creating an app with visual basic, it's easy and there's tons of sources out there.

Thats about all I can offer to ya, I'll keep checkin up on your status though, can't wait to see some pic's and your code on it =)
  Reply With Quote
09-20-11, 06:11 AM   #13
Scaarf
A Murloc Raider
Join Date: Sep 2011
Posts: 9
ah wouldve been really interesting learning about how he did it
  Reply With Quote
09-20-11, 10:44 AM   #14
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Clyde_Mobster View Post
Chat logging should be turned on so it's sent to a .txt file within the WoW directory. Then you'd have to have some sort of app that reads this txt file, ...
Chat log files are only written to disk when you log out or reload the UI, just like saved variable files, so you will not get information any faster reading from the chat log than reading from saved variables.
  Reply With Quote
09-20-11, 07:38 PM   #15
Scaarf
A Murloc Raider
Join Date: Sep 2011
Posts: 9
@Phanx
ah bummer, so it wont work as live time =\

@Clyde_Mobster
regardless of it not working as thought, thanks a lot of the information. seems useful for me to find out how it will work regardless.
  Reply With Quote
10-03-11, 05:08 PM   #16
Jpapertowels
A Defias Bandit
 
Jpapertowels's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2010
Posts: 3
You could do what I did that worked, though you will need knowledge of another language as well.

I created an addon on WoW that was a 1 pixel by 1 pixel frame that changed colors, then had an outside program (coded in Delphi 7) color-pick the pixel location and read out commands from it.
  Reply With Quote
10-04-11, 03:31 AM   #17
Scaarf
A Murloc Raider
Join Date: Sep 2011
Posts: 9
Originally Posted by Jpapertowels View Post
You could do what I did that worked, though you will need knowledge of another language as well.

I created an addon on WoW that was a 1 pixel by 1 pixel frame that changed colors, then had an outside program (coded in Delphi 7) color-pick the pixel location and read out commands from it.
oh sounds great, so that way i'll be able to do what i want right? will it be difficult in your opinion?


also would like to know if other people, have any good ideas that might be simple but creative enough =D
  Reply With Quote
10-04-11, 08:34 AM   #18
Vlad
A Molten Giant
 
Vlad's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 793
If you make an addon in-game that creates a 1x1 pixel (or larger if it fancies you) then make that addon change the color of the texture you are showing to white, red, green, yellow or what ever you wish it to; then you can can read the color from the pixel at position x,y on screen with a program -for example AutoIT3 has simple to use API for pixel color reading.

Then it is a mater of making the script running on the machine send those signals to your hardware, dunno what interface you use.

The lua code I wrote explained:
Code:
-- I just use the UIParent frame since I then have to write less code :P
local t = UIParent:CreateTexture(nil, "BACKGROUND")
-- the top-left side of the screen
t:SetPoint("TOPLEFT")
-- this is 8x8 but you can set it to 1x1 to make it less visible
t:SetSize(8, 8)
-- default color at login (gray = no threat)
t:SetTexture(GetThreatStatusColor(nil))
-- we need to know: when you change your target to the new target threat levels
UIParent:RegisterEvent("PLAYER_TARGET_CHANGED")
-- we need to know: when you overaggro tank, or loose aggro and other threat level changes
UIParent:RegisterEvent("UNIT_THREAT_LIST_UPDATE")
-- hook the UIParent events so we can read off the data and change the texture color
UIParent:HookScript("OnEvent", function(_, event)
  if event == "PLAYER_TARGET_CHANGED" or event == "UNIT_THREAT_LIST_UPDATE" then
    -- nil/0 = no threat (gray), 1 = has threat but safe zone (yellow), 2 = has high threat (orange), 3 = tanking (red)
    local status = UnitThreatSituation("player", "target")
    -- we fetch the default game coloring system using the status value
    local r, g, b = GetThreatStatusColor(status)
    -- we apply the color to the texture
    t:SetTexture(r, g, b)
  end
end)
The AutoIT3 code I wrote to test it out, but not so much explained in details:
Code:
; pattern to match the game window
Local $title = "[TITLE:World of Warcraft; Class:GxWindowClass]"

; simple check to not waste our time
If Not WinExists($title) Then
	MsgBox(48, "Where is World of Warcraft?", "Run me when the game is running, bye!")
	Exit
EndIf

; set the handle to the window in focus
Local $game = WinGetHandle($title)

; this is called when reporting a threat level change
Func ThreatChange($status)
	; TODO: do your magic here, and to help you get started:
	; http://www.autoitscript.com/autoit3/docs/functions.htm
EndFunc

; check pixel at topleft location each 1/4th second
Local $pos = WinGetPos($title)
Local $x = $pos[0] + 10 ; change this (have to find where the in-game pixel is on the x-axis)
Local $y = $pos[1] + 34 ; change this (have to find where the in-game pixel is on the y-axis)
;~ MouseMove($x, $y) ; uncomment to see where the mouse movies, should be on top of the pixel, if not, keep trying!
;~ Exit ; should uncomment this too if working on finding the in-game texture
Local $color, $r, $g, $b, $rgb, $status, $laststatus
While 1
	Sleep(0.25)
	$color = PixelGetColor($x, $y, $game)
	$b = BitAND($color, 0xFF)
	$g = BitAND(BitShift($color, 8), 0xFF)
	$r = BitAND(BitShift($color, 16), 0xFF)
	$rgb = $r + $g + $b
	Switch $rgb
		Case 528
			$status = 0
		Case 629
			$status = 1
		Case 408
			$status = 2
		Case 255
			$status = 3
	EndSwitch
	If $laststatus <> $status Then
		$laststatus = $status
		ThreatChange($status)
	EndIf
WEnd

#cs

can use to test the pixel in-game (all the macros create the "addon") -have to /reloadui first if you want to change the function tough...
/run local t = UIParent:CreateTexture(nil, "BACKGROUND") _G.t=t
/run t:SetPoint("TOPLEFT")
/run t:SetSize(8, 8)
/run t:SetTexture(GetThreatStatusColor(nil))
/run UIParent:RegisterEvent("PLAYER_TARGET_CHANGED")
/run UIParent:RegisterEvent("UNIT_THREAT_LIST_UPDATE")
/run UIParent:HookScript("OnEvent", function(_, event) if event == "PLAYER_TARGET_CHANGED" or event == "UNIT_THREAT_LIST_UPDATE" then t:SetTexture(GetThreatStatusColor(UnitThreatSituation("player", "target"))) end end)

can use these to change the colors by force and check if the program responds
/run t:SetTexture(GetThreatStatusColor(0))
/run t:SetTexture(GetThreatStatusColor(1))
/run t:SetTexture(GetThreatStatusColor(2))
/run t:SetTexture(GetThreatStatusColor(3))

#ce
At the bottom of the au3 code there is a macro version of the "addon" for easier testing, hehe.

Last edited by Vlad : 10-04-11 at 09:48 AM.
  Reply With Quote
10-05-11, 09:19 AM   #19
Scaarf
A Murloc Raider
Join Date: Sep 2011
Posts: 9
omg great thanks a lot!

i'll have a closer look once i get the chance,
also wanna test it out but since my comp recently wiped i gotta reinstall WoW
  Reply With Quote

WoWInterface » General Discussion » Tech Chat » Arduino Project - Threat Level Lamp

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off