I need a help with NANJG 105D driver program.

Hi,
i’m looking for someone, who could code a simple driver for NANJG 105D.
I need 5 modes:

100% of power, 80, 50, 20, 5 without eeprom saving last mode.

When light is off, and we trun it on, led will start always from 0% to 100% - with transition (soft start).
When we click two times, it will bling:
5 times if battery is full loaded, 4 if is 80, 3 if is 60, 2 if is 40, and one if less then 20.

Is anybody here who could help me to write driver like above or have already done ?

Best cheers!

It might not an exact match with what you have listed, but there is a brand new firmware available, named “Biscotti”. It was developed for the new C8 and referenced here:

Depending on how many 7135 are used the brightness levels might be suitable? Or you could adapt the source code to your own needs?

Thanks for the replay!
I’m trying to write simple program, but knowledge of electronics a little beyond me.
I’ve done a simple soft start from open source firmware from github, but as I reading all posts about modding
I know that this will not be the optimal for battery performance.

A lot of problems eliminated by the omission of memory but it’s for me still a big deal.

Best regards!

If you are a beginner I would simply modify an existing firmware or just flash the hex file directly. All you need is the driver, a computer, a programmer (don’t need the programmer if you have a dev board, like RPi, OPi,…), dupont cables or a soldering iron (some clips come with a little breakout board where the chip can be clipped in but it won’t work with soldered chips), a clip and some time.

Our user ToyKeeper has a FW repository here:
https://code.launchpad.net/~toykeeper/flashlight-firmware/trunk

Thanks!
I’ve a USBasp and I has already done writing new firmware to NanJG 105D.
But as I said, it’s hard to write something new is you’re beginner :slight_smile:

good. then I’d just get an existing source code, adapt to your needs, compile and flash. Some of the flashlight hex firmware files come with the source code.

Okey,
when I’m done I will upload here my source code and hex.
I hope that advanced members of this site will analyze my driver firmware :slight_smile:

How to manage reverse click? As i think i can not avoid saving in eeprom?

How to save last state for reverse click changing modes but if turn off flashlight for a 2 seconds, start from 0 ?

For now I have:

#define F_CPU 4800000

#include <avr/io.h>
#include <util/delay.h>

// Modes
uint8_t Modes[] = { 10, 100, 150, 200, 255};

int soft_modes_msDelay = 10;

// Soft start
int soft_start = 0;
int soft_end = 255;
int soft_msDelay = 5;

int main ( void )
{
DDRB = 2;
TCCR0A = 0b00100001;
TCCR0B = 0b00000001;

// Soft start
Change( soft_start, soft_end, soft_msDelay );
}

int Change( int from, int to, int delay )
{
while ( from != to )
{
OCR0B = from;
_delay( delay );

if ( from > to )
from–;
else
from++;
}
}

int _delay( int n )
{
while ( n-- )
_delay_ms( 1 );
}

How to detect a short power off in ATTiny13A ?
I mean how to program that, if I turn on flashlight and short click on button (power off) ?

The ‘.noinit’ method is elegant and does not require any hardware changes:

STAR_noinit

Very thanks!

Now switch by soft click working good :)

Is there any option to detect double soft click ?

Maybe after one click program will waiting for second click and then trigger action ?

Have anyone done it yet?

I have created BitBucket repository: https://bitbucket.org/uniti-public/light/src

I do it with another noinit variable that memorizes the previous on-time. If less than 256 ms, it was a double click.

volatile uint8_t noinit_prev_on_time __attribute__ ((section (".noinit")));
.
.
.
ISR(WDT_vect)     // WDT interrupt service routine
{                                               
    // Double click timeout
    if (noinit_prev_on_time < DOUBLE_CLICK_TIMEOUT) {   
                ++noinit_prev_on_time;
    }
.
.
.
int main(void)
{
    // Determine what mode we should fire up, read last mode that was saved
    if (noinit_decay) {     // long click, reset to start mode
        mode_idx = START_MODE;
        noinit_prev_on_time = 0;     // enable double click detection on initial start
    } else if (noinit_prev_on_time >= DOUBLE_CLICK_TIMEOUT) {     // short click, or first click of double click 
        mode_idx = noinit_mode + 1;
        if (mode_idx > LAST_MODE) {mode_idx = START_MODE;}  
    } else {mode_idx = HIDDEN_MODE;}     // second click of double-click, go to hidden mode
    noinit_decay = 0;     // set noinit data for next boot
    noinit_mode = mode_idx;
.
.

I use a 64 ms ISR and do 4 counts, but you can do it in other ways.

EDIT: Fixed early-morning typos :weary:

Thanks very much.
I don’t know what I do wrong, but always detecting double clicks :frowning:

https://bitbucket.org/uniti-public/light/src/f61f7df1edee080f82a8e4c49061e86208c29ad0/flashlight.c?at=master&fileviewer=file-view-default

And I just looking and thinking and if it does work, when I just jump to double click function, the single click will fired up too.
Hms…

Okey, to not firing up I add delay to the first click :slight_smile:
But it look like that ISR WatchDog doesn’t work.