How to tweak soruce code?

Hey all,


I would like to know how to make a few small changes to an existing source code. All I would like to be able to do right now is change the values for the output on some of the levels.

For example change 5% - 20% - 50% - 100% to 2% - 25% and so on.

Question one:

Its it possible to do this when the only code I have for the firmware is the set that is just the ones and zeros and lettering etc like this.


:1000400015191D20900FJLAK000768AA1BCA02
:1032KL90911241FBECFE9CDBF1034240E02
:100000234434C01D92A536B1660007E1F763D084C1C8Y756

That is not actual code just some gibberish I wrote that looks like what I am seeing.


Question two:

If so then what do I do?



I have 2 compilers downloaded. AVR 4 which I have always used to flash micros, and 6.2 which I downloaded to try out, but later read somewhere that its buggy and some users are "upgrading" to a more familiar experience with 6.1.


Any help would be super appreciated :)

Matt

The code you show is the compiled .hex file. There is nothing you can do with that. You need to get the .c source code file. It may very well be commented with instructions as to how to do the changes you're looking for. Then you can use a compiler to create the hex file, and flash the driver.

You could theoretically use a decompiler to disassemble the compiled source and reverse engineer it. Then you make your change, re-compile it and you’re done. At least that’s how it goes on paper.

But ideally you start with the source, tweak it, compile it, rinse and repeat until you are done. Whatever device you are programming for, whether it’s a hobbyist computer, router or even flashlight, there’s probably tons of code out there to experiment with if you look hard enough.

Reverse engineering your device’s firmware is probably not a good starting point for a new programmer :slight_smile:

Yes, but it is rather hard, running it through a disassembler makes it easier (But not easy).

Getting the C-source code (if it exist) is much easier.

There is also one small catch with the hex listing: it contains a checksum, i.e. any changes will make it invalid, if you do not update the checksum.

Thank you guys so much for jumping in on this. I realize taking a novice into these depths is a daunting task.


This does explain some of the problems I am having. I thought that was a C file for this reason.

I was sent that code by a pro who said to copy it into notepad and I could use it. I did this, but when I saved the file I was NOT able to save it as .hex and get my compiler to use it. I saved it again as .c and problem solved.

Does anyone know the reason I am not able to just save this file via notepad as .hex?

C is a powerful language, but I’ve heard it described as a gun pointed to your head by default.

May just be a Windows thing. You could always rename it in explorer...

Can the code author help you out? Or surely you can find something in ToyKeeper's repository that will do the job.

https://code.launchpad.net/~toykeeper/flashlight-firmware/trunk

Your right, it was a problem in windows. I actually got that to work now too. Were on a roll here men.


I wont be able to change the original firmware I wanted to cuz I dont have the source code, but I would like to give a try with one of the ones from Toykeepers box.

I'd like to try it with this one.

http://bazaar.launchpad.net/~toykeeper/flashlight-firmware/trunk/view/head:/Tom_E/eswitch.c


All I want to do is be able to change the values for the output percentages. The current values work great for a 6000+ma light, but with a 3 amp light the first 3 modes dont even produce light. What do I need to do in order to accomplish this?

That firmware is for a light with a E-switch only, meaning when a cell is inserted the light’s “computer” is constantly on, so a mode level of 0 is desired so the light has a mode with no output so it can appear to be off. Basically off is just another mode with E-switch only lights, but with 0 output. Note: There are those who will correct this explanation with the more correct terms, I just tend to explain things in the most general way possible…

Anyhow, for that particular firmware, the modes are in this line:
#define MODES 0,1,12,102,255

This line means 5 modes with levels separated by “,”. 0 is off, 255 is 100, so 50 is 127.5 (half of 255) but you have to round it to a full number without decimals. 127 or 128 is as close to 50% as you’ll get. 10’% would be 25 or 26 (25.5 can’t be used). The first three don’t produce light? Well, 0 is not supposed to, it’s the “off” mode for lights that are always on as long as a cell is inserted. Is the light your running it in only have a E-switch and no power switch? If not, this is not the firmware for you. That mode level 1 doesn’t produce light is not so strange with a 3 amp PWM driven driver. But 12 is around the mark where you should start to see some light. Increase it to 15 or slightly more and you should be seeing light.

Yes, I understand the e-switch. I have used this in a courui DO1 that was powered up to around 6 amps and it was great. I tried using it in my head lamp and the lows are too low. I essentially have off, off, off, low, med, high turbo. I think the version of that firmware I have may be a 6 mode that someone else has tweaked a little, because after viewing the readme I see I also dont have strobe. The press hold for me just jumps to high instead.

I do see the line of code in the C file your talking about. What I am the most confused about is how exactly to load this into my compiler, and which parts of that code to use. It appears to me that there are different sets of code there to be used with different drivers etc. Or am I wrong and all 500 lines are used each time?


When I open AVR 6.2 am I suppose to go in just like when I normally convert C to hex? Ie
New project
AVRGCC C executable file

And paste the code there and then edit the values, then build?

Hey!! Guess whose in the deep end of the cement pond now...







Yep, I actually got it. You guys are AWESOME!! Thank you for your help.

Baby steps today were.

1. Change mode values and amount of modes in TomE UI and one of Toykeepers.

2. Change XLPress value for strobe in TomE mom UI...


Stop laughing its a start.



I still have a couple more questions if you guys don't mind chiming in.

In this e-switch UI
http://bazaar.launchpad.net/~toykeeper/flashlight-firmware/trunk/view/head:/Tom_E/eswitch.c

1. If I wanted to disable the strobe totally rather than change the length of the press time it takes to activate it how would I do that? The values for strobe start at line 60.

2. This UI is designed for a 1 click off, so in order to cycle upward through the modes you have to do it fast when you first start out. If you click on to the first and then second, but delay too long before you go up to the 3rd level and so on what happens is you go off. How do I extend that window? By like say a half second.



3. In Toykeepers UI here
http://bazaar.launchpad.net/~toykeeper/flashlight-firmware/trunk/view/head:/ToyKeeper/Ferrero_Rocher/Ferrero_Rocher.c

Some of the lines say "Comment out to disable" What exactly does that mean?



Thanks again in advance.

Nice work vb. I'm not laughing as l reckon all you programmers out there are very clever. Its all Chinese to me.

Good stuff!

Comment out row 61. Commenting out something is as I described above, you put // in front of what ever you want to comment out. If a row doesn’t have // in front of it the compiler will consider it to be code and attempt to compile it. So you want row 61 to look like this: // #define ENABLE_STROBE

I don’t know this firmware and am not fond of analyzing others code, but at a quick glance I’d guess it’s this line: #define IDLE_TIME 75
If 75 is 1.2 seconds, then 106 is 1.7 seconds. The formula is X = seconds / 0.016.

It means that by putting // at the beginning of the line you are telling the compiler to ignore that line as code.

Thanks Mike, I do appreciate your help. Being able to squash the strobe on that will make it much better for a head lamp I think.

This is actually getting to be a little bit fun!!