STAR Firmware by JonnyC - Source Code and Explanation

Perhaps someone has use for this compilation without my markings, so I might as well add it here. The 6 Nanjg pictures are from Fasttech, as are my driver.

Just follow the link behind the picture.

Thanks for the pics HarleyQuin - clear driver pictures are always an asset.

I’ve started modifying the STAR (SRK_no_ramp_1.0.c) firmware to run the DQG 26650 EDC triple light. EDIT: which is an e-switch setup with a pretty unique method for controlling modes.

Very nice wight. How does the UI work? Richard gave me a slight nudge to finally get the dual switch program written, something I've been planning on doing for months but just haven't created the time.

Glad to hear that you're working on a dual switch program! I think many modders and users would love that. With 4 easy to define user inputs (2 short and 2 long presses) you can easily do up/down and special/off. That would satisfy basically all of the things people have asked for... as long as they build a dual-button light of course.

I'm not sure what you're asking me though. The UI should be the same as your original one if I've done things correctly. I don't own one of those flashlights, so I am unable to describe the stock UI. Ahh.. I probably wasn't clear in saying "a pretty unique method for controlling modes". I meant that the driver board does not use a PWM, serial, or other conventional way of controlling the modes. They are controlled through a series of 4 pins on the MCU. You bring them up like this for the 4 modes:
none: OFF
RUN_PIN: LOW
RUN_PIN & MODE1_PIN: MEDIUM
RUN_PIN & MODE2_PIN: HIGH
RUN_PIN & MODE3_PIN: TURBO

Ahhh whoops! I misread your post thinking that the light you were using this program on had two switches. Nevermind!

I’ve got my programmer and AVR Studio 5.1 set up (thanks Comfychair for your excellent howto). I’ve been looking at the STAR 1.1 version (and a few others people have posted here) and have a quick tip for us lazy people on how to calculate the voltage levels for ramping and low voltage cut off.

In the source code this comment is the original formula: Value = (V * 4700 * 255) / (23800 * 1.1)
For me that’s just unnecessarily long. If I understand it correctly, these values are not that accurate in terms of exact voltage, so why not make the formula simple instead? Like Value = V * 45.78? It’s the same thing (well, almost the same thing. Value = V * 45.779220779220779220779220779221 would be EXACTLY the same thing).
Sorry if this has been posted, I read through this thread but didn’t see it in that case.

Also, what is the reason for this:
#ifdef MODE_TURBO
#undef MODE_HIGH
#define MODE_HIGH MODE_HIGH_W_TURBO
#endif
As you are programming the modes yourself, why would you want to do this rather than just change the MODE_HIGH to what ever you wanted in the first place? Why have a MODE_HIGH_W_TURBO? Turbo mode is not selectable by soldering stars so I see no point in doing this. If you have edited turbo mode on or off you should be capable of editing the MODE_HIGH to be want you want it to be, it is simple enough. What is the reasoning behind having this MODE_HIGH_W_TURBO?

Wait, does the attiny13a have the ability to do floating-point math? Is it actually built in or does the compiler fake it? Does it use up a bunch of extra ROM space (for fake FP-handling code) if the program includes floating-point math?

I was assuming these were integer-only.

It’s not the code itself, it’s the comments on how to calculate the value from the desired voltage I was referring to. The end value used in the actual code has to be rounded to an integer either way.

This is for when someone programs a lot of different lights, and they can just set it and forget it and only worry about enabling or disabling turbo.

I’d think that someone who programs a lot of different lights would have a lot of different source files, I know I will :slight_smile: But I guess it’s down to personal preference…

Compile-time options are generally a good thing. They almost literally make the world go around.

Normally, it’s used so that a configuration script can auto-configure a program to build and run correctly based on what it detects about the host system, and compile-time options like that were probably part of the build process for 90% of the programs on your computer. The only real difference here is that it’s a human defining the parameters instead of a script.

Got mine in wight…just gotta solder some leads to it and give it a whirl :smiley:

Sweet, keep us posted. Looks like I’ll know whether my two bucks was a wasted investment long before I receive the product. ;~~)

I am changing the functionality of some of the features with the STAR 1.1 firmware and just want to make sure about what this line of code does:
PWM_LVL = modes[- -mode_idx];
This changes the PWM_LVL (output) to the level of the previous mode but does not actually change the mode itself. This means that if this line is executed while the light is on high, the output will switch to that of medium, but the light will still “think” it’s on high and remember high as current mode if switched off. Is that correct?

What are you wanting to do?

I want to understand what that line does exactly :slight_smile:

I am experimenting with different behavior for low voltage step down and critical volt shut of, such as not blinking “off” but blinking with the same PWM_LVL of the mode it will switch to after the warning flash, and am also contemplating weather I want the driver to remember this as the new mode, or keep original mode in memory but running PWM_LVL as the previous lower mode. To me it looks like that line just changes the output and not the mode, but I am no programmer so I just wanted to ask as I don’t have a good testing facility set up in order to test this myself… yet…

As my question is more about programming syntax than the actual firmware, disregard it. I have software developers at work, I will ask one of them.

Your understanding is correct.

Yup, that's just for Turbo. It's so that when you turn it off and back on it will switch back to Turbo, and not the previous level that it stepped down to.

EDIT: Oops, and yes, it does the same thing for the low voltage ramp down. You're correct in that it doesn't save the mode, that only happens when store_mode_idx is called.

Note you can also use this line to modify the turbo step down to a specific PWM value instead of the previous mode, simply replace PWM_LVL = modes[- -mode_idx]; with PWM_LVL = 180 (desired PWM value). That way you can have it step down to a level of your choice but still act normal and still be able to be bumped back up to turbo with a single click.

I use it like this in my small lights that need a large step down to not overheat.