Compare commits
	
		
			No commits in common. "1bb0a19f779e72e8eb4f11b8b655058af65173af" and "6f9444ab5c1952fa0397f0cb6a328cf576bb0f90" have entirely different histories.
		
	
	
		
			1bb0a19f77
			...
			6f9444ab5c
		
	
		
@ -145,7 +145,7 @@ int main(void)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        // after sending LEDs, run our program
 | 
					        // after sending LEDs, run our program
 | 
				
			||||||
        // to update the LED buffer for next time
 | 
					        // to update the LED buffer for next time
 | 
				
			||||||
        if ((ticnt & 0x7) == 0) {
 | 
					        if ((ticnt & 0x3) == 0) {
 | 
				
			||||||
            ui_render();
 | 
					            ui_render();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -62,12 +62,6 @@ void adc_read()
 | 
				
			|||||||
void adc_set_mode_lsens(uint8_t mode)
 | 
					void adc_set_mode_lsens(uint8_t mode)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    lsens_mode = mode;
 | 
					    lsens_mode = mode;
 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (mode == LSENS_OUTPUT) {
 | 
					 | 
				
			||||||
        lsens_gpio.GPIO_Pin = LSENS_A_PIN | LSENS_K_PIN;
 | 
					 | 
				
			||||||
        lsens_gpio.GPIO_Mode = GPIO_Mode_Out_PP;
 | 
					 | 
				
			||||||
        GPIO_Init(LSENS_PORT, &lsens_gpio);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
uint8_t adc_get_mode_lsens()
 | 
					uint8_t adc_get_mode_lsens()
 | 
				
			||||||
@ -85,7 +79,7 @@ static void lsens_start()
 | 
				
			|||||||
    // set cathode high, let it charge
 | 
					    // set cathode high, let it charge
 | 
				
			||||||
    LSENS_PORT->BSHR = LSENS_K_PIN;
 | 
					    LSENS_PORT->BSHR = LSENS_K_PIN;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // set anode low
 | 
					    // set anode floating
 | 
				
			||||||
    lsens_gpio.GPIO_Pin = LSENS_A_PIN;
 | 
					    lsens_gpio.GPIO_Pin = LSENS_A_PIN;
 | 
				
			||||||
    lsens_gpio.GPIO_Mode = GPIO_Mode_IPD;
 | 
					    lsens_gpio.GPIO_Mode = GPIO_Mode_IPD;
 | 
				
			||||||
    GPIO_Init(LSENS_PORT, &lsens_gpio);
 | 
					    GPIO_Init(LSENS_PORT, &lsens_gpio);
 | 
				
			||||||
 | 
				
			|||||||
@ -130,12 +130,12 @@ void userconf_load()
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        // program 0: flashing
 | 
					        // program 0: flashing
 | 
				
			||||||
        userconf.pep_conf[0][0] = 0x80;     // brightness
 | 
					        userconf.pep_conf[0][0] = 0x80;     // brightness
 | 
				
			||||||
        userconf.pep_conf[0][1] = 100;      // flash rate
 | 
					        userconf.pep_conf[0][1] = 200;      // flash rate
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // program 2: loops
 | 
					        // program 2: loops
 | 
				
			||||||
        userconf.pep_conf[2][0] = 0xc0;     // brightness
 | 
					        userconf.pep_conf[2][0] = 0xc0;     // brightness
 | 
				
			||||||
        userconf.pep_conf[2][1] = 1;        // looping rate
 | 
					        userconf.pep_conf[2][1] = 0;        // looping rate
 | 
				
			||||||
        userconf.pep_conf[2][3] = 2;        // decay rate
 | 
					        userconf.pep_conf[2][3] = 1;        // decay rate
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // program 4: alternating
 | 
					        // program 4: alternating
 | 
				
			||||||
        userconf.pep_conf[4][0] = 0x80;     // brightness
 | 
					        userconf.pep_conf[4][0] = 0x80;     // brightness
 | 
				
			||||||
 | 
				
			|||||||
@ -4,9 +4,6 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include <stdint.h>
 | 
					#include <stdint.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "ledprog_pep.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include "adc.h"
 | 
					 | 
				
			||||||
#include "config.h"
 | 
					#include "config.h"
 | 
				
			||||||
#include "led.h"
 | 
					#include "led.h"
 | 
				
			||||||
#include "lis2dw.h"
 | 
					#include "lis2dw.h"
 | 
				
			||||||
@ -24,9 +21,6 @@ enum {
 | 
				
			|||||||
static uint16_t pep_rnd;
 | 
					static uint16_t pep_rnd;
 | 
				
			||||||
static uint8_t pep_work[4];
 | 
					static uint8_t pep_work[4];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static uint16_t rand_program = 0;
 | 
					 | 
				
			||||||
static uint32_t rand_timeout = 0;
 | 
					 | 
				
			||||||
static uint16_t rand_flash_timeout;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
@ -168,11 +162,10 @@ static void pep_2_loops(uint8_t tick)
 | 
				
			|||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        pep_work[0] = rate;
 | 
					        pep_work[0] = rate;
 | 
				
			||||||
        pep_work[1]++;
 | 
					        pep_work[1]++;
 | 
				
			||||||
        pep_work[1] &= 0x3f;
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    bot = pep_work[1] * LED_PEP_COUNT;
 | 
					    bot = pep_work[1] * LED_PEP_COUNT;
 | 
				
			||||||
    bot >>= 6;
 | 
					    bot >>= 8;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (i = 0; i < LED_PEP_COUNT; i++) {
 | 
					    for (i = 0; i < LED_PEP_COUNT; i++) {
 | 
				
			||||||
        if (i == bot)        led.section.pep[i] = brite;
 | 
					        if (i == bot)        led.section.pep[i] = brite;
 | 
				
			||||||
@ -183,7 +176,7 @@ static void pep_2_loops(uint8_t tick)
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    top = pep_work[1] * LED_HAT_COUNT;
 | 
					    top = pep_work[1] * LED_HAT_COUNT;
 | 
				
			||||||
    top >>= 6;
 | 
					    top >>= 8;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (i = 0; i < LED_HAT_COUNT; i++) {
 | 
					    for (i = 0; i < LED_HAT_COUNT; i++) {
 | 
				
			||||||
        if (i == top)        led.section.hat[i] = brite;
 | 
					        if (i == top)        led.section.hat[i] = brite;
 | 
				
			||||||
@ -220,7 +213,7 @@ static void pep_3_neon_sign(uint8_t tick)
 | 
				
			|||||||
            target = rnd & 1;
 | 
					            target = rnd & 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            flicker_count[target] = prng_scale16(1, 4) << 1;
 | 
					            flicker_count[target] = prng_scale16(1, 4) << 1;
 | 
				
			||||||
            flicker_delay[target] = prng_scale16(6, 120);
 | 
					            flicker_delay[target] = prng_scale16(12, 240);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (rnd & 2) {
 | 
					            if (rnd & 2) {
 | 
				
			||||||
                flicker_count[target ^ 1] = flicker_count[target];
 | 
					                flicker_count[target ^ 1] = flicker_count[target];
 | 
				
			||||||
@ -399,37 +392,6 @@ static void pep_5_nom(uint8_t tick)
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void pep_6_random(uint8_t tick)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    if (rand_flash_timeout <= 2) {
 | 
					 | 
				
			||||||
        // light lsens
 | 
					 | 
				
			||||||
        adc_set_mode_lsens(LSENS_OUTPUT);
 | 
					 | 
				
			||||||
        LSENS_PORT->BSHR = LSENS_A_PIN;
 | 
					 | 
				
			||||||
        LSENS_PORT->BCR  = LSENS_K_PIN;
 | 
					 | 
				
			||||||
        if (!rand_flash_timeout) rand_flash_timeout = 600;
 | 
					 | 
				
			||||||
    } else {
 | 
					 | 
				
			||||||
        if (adc_get_mode_lsens() == LSENS_OUTPUT) {
 | 
					 | 
				
			||||||
            // restore lsens
 | 
					 | 
				
			||||||
            LSENS_PORT->BCR = LSENS_A_PIN;
 | 
					 | 
				
			||||||
            adc_set_mode_lsens(LSENS_READING_IDLE);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    rand_flash_timeout--;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (!rand_timeout) {
 | 
					 | 
				
			||||||
        rand_timeout = prng_scale16(20*128, 150*128);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        rand_program = 6 * prng_get8();
 | 
					 | 
				
			||||||
        rand_program >>= 8;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        ledprog_pep_init();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    rand_timeout--;
 | 
					 | 
				
			||||||
    ledprog_pep[rand_program](tick);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * make a sharp point at whatever direction is the ground
 | 
					 * make a sharp point at whatever direction is the ground
 | 
				
			||||||
 * note: probably won't be done before con
 | 
					 * note: probably won't be done before con
 | 
				
			||||||
@ -470,9 +432,8 @@ void (*ledprog_pep[8])(uint8_t) = {
 | 
				
			|||||||
    pep_3_neon_sign,
 | 
					    pep_3_neon_sign,
 | 
				
			||||||
    pep_4_alternate,
 | 
					    pep_4_alternate,
 | 
				
			||||||
    pep_5_nom,
 | 
					    pep_5_nom,
 | 
				
			||||||
    pep_6_random
 | 
					    pep_6_accelerometer,
 | 
				
			||||||
    //pep_6_accelerometer,
 | 
					    pep_7_heat
 | 
				
			||||||
    //pep_7_heat
 | 
					 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -499,9 +460,5 @@ void ledprog_pep_init()
 | 
				
			|||||||
    // per-program initialization
 | 
					    // per-program initialization
 | 
				
			||||||
    nom_timeout = 0;
 | 
					    nom_timeout = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if ((userconf.pep_prog_ena_map & ~0x80) != 6) {
 | 
					 | 
				
			||||||
        rand_flash_timeout = 3;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // there is none on this badge
 | 
					    // there is none on this badge
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -151,7 +151,7 @@ static uint32_t tinymt32_temper (tinymt32_t* s)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
uint16_t prng_scale16(uint16_t min, uint16_t max)
 | 
					uint16_t prng_scale16(uint16_t min, uint16_t max)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    uint32_t rnd;
 | 
					    uint16_t rnd;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    rnd = prng_get16();
 | 
					    rnd = prng_get16();
 | 
				
			||||||
    rnd *= (max - min);
 | 
					    rnd *= (max - min);
 | 
				
			||||||
 | 
				
			|||||||
@ -19,12 +19,12 @@
 | 
				
			|||||||
#define MODE_PROGRAM            1
 | 
					#define MODE_PROGRAM            1
 | 
				
			||||||
#define MODE_PARAMETER          2
 | 
					#define MODE_PARAMETER          2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define UI_CONF_SAVE_TIMEOUT    384
 | 
					#define UI_CONF_SAVE_TIMEOUT    512
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define UI_PROG_RUNTIME_MIN     (128*15)    // 15 seconds
 | 
					#define UI_PROG_RUNTIME_MIN     (128*15)    // 15 seconds
 | 
				
			||||||
#define UI_PROG_RUNTIME_MAX     (128*120)   // 120 seconds
 | 
					#define UI_PROG_RUNTIME_MAX     (128*120)   // 120 seconds
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define PROG_RANDOM             0x80
 | 
					#define PROG_REPEAT             0x80
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -51,18 +51,16 @@ void ui_btn_push_cb(uint8_t idx)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void ui_btn_hold_cb(uint8_t idx)
 | 
					void ui_btn_hold_cb(uint8_t idx)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    /*
 | 
					 | 
				
			||||||
    switch (idx) {
 | 
					    switch (idx) {
 | 
				
			||||||
        case 0: {   // left pepper hat
 | 
					        case 0: {   // left pepper hat
 | 
				
			||||||
            userconf.pep_prog_ena_map ^= PROG_RANDOM;
 | 
					            userconf.pep_prog_ena_map ^= PROG_REPEAT;
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        case 1: {   // right pepper hat
 | 
					        case 1: {   // right pepper hat
 | 
				
			||||||
            userconf.rgb_prog_ena_map ^= PROG_RANDOM;
 | 
					            userconf.rgb_prog_ena_map ^= PROG_REPEAT;
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    */
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void ui_btn_release_cb(uint8_t idx)
 | 
					void ui_btn_release_cb(uint8_t idx)
 | 
				
			||||||
@ -71,18 +69,18 @@ void ui_btn_release_cb(uint8_t idx)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    switch (idx) {
 | 
					    switch (idx) {
 | 
				
			||||||
        case 0: {   // left pepper hat
 | 
					        case 0: {   // left pepper hat
 | 
				
			||||||
            update = userconf.pep_prog_ena_map & ~(PROG_RANDOM);
 | 
					            update = userconf.pep_prog_ena_map & ~(PROG_REPEAT);
 | 
				
			||||||
            update++;
 | 
					            update++;
 | 
				
			||||||
            if (update > 6) update = 0;
 | 
					            if (update > 5) update = 0;
 | 
				
			||||||
            userconf.pep_prog_ena_map = update | (userconf.pep_prog_ena_map & PROG_RANDOM);
 | 
					            userconf.pep_prog_ena_map = update | (userconf.pep_prog_ena_map & PROG_REPEAT);
 | 
				
			||||||
            ledprog_pep_init();
 | 
					            ledprog_pep_init();
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        case 1: {   // right pepper hat
 | 
					        case 1: {   // right pepper hat
 | 
				
			||||||
            update = userconf.rgb_prog_ena_map & ~(PROG_RANDOM);
 | 
					            update = userconf.rgb_prog_ena_map & ~(PROG_REPEAT);
 | 
				
			||||||
            update++;
 | 
					            update++;
 | 
				
			||||||
            if (update > 3) update = 0;
 | 
					            if (update > 3) update = 0;
 | 
				
			||||||
            userconf.rgb_prog_ena_map = update | (userconf.rgb_prog_ena_map & PROG_RANDOM);
 | 
					            userconf.rgb_prog_ena_map = update | (userconf.rgb_prog_ena_map & PROG_REPEAT);
 | 
				
			||||||
            ledprog_rgb_init();
 | 
					            ledprog_rgb_init();
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@ -115,8 +113,8 @@ void ui_render()
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    tick++;
 | 
					    tick++;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    uint8_t prog_pep_idx = userconf.pep_prog_ena_map & ~(PROG_RANDOM);
 | 
					    uint8_t prog_pep_idx = userconf.pep_prog_ena_map & ~(PROG_REPEAT);
 | 
				
			||||||
    uint8_t prog_rgb_idx = userconf.rgb_prog_ena_map & ~(PROG_RANDOM);
 | 
					    uint8_t prog_rgb_idx = userconf.rgb_prog_ena_map & ~(PROG_REPEAT);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    switch (mode) {
 | 
					    switch (mode) {
 | 
				
			||||||
        case MODE_RUN: {
 | 
					        case MODE_RUN: {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user