Skip to content
Snippets Groups Projects
Commit 5bc38f82 authored by moon2's avatar moon2 :speech_balloon:
Browse files

added rev1 support

parent a21cf01b
No related branches found
No related tags found
No related merge requests found
...@@ -18,6 +18,8 @@ static const uint8_t bot_stages = 12; ...@@ -18,6 +18,8 @@ static const uint8_t bot_stages = 12;
static const uint8_t top_segment_map[] = {1,3,2,2,3,1,1,3,2,1,3,2}; //PETAL_SEGMENT_* static const uint8_t top_segment_map[] = {1,3,2,2,3,1,1,3,2,1,3,2}; //PETAL_SEGMENT_*
static const uint8_t bot_segment_map[] = {3,0,3,0,0,0,3,0,3,1,2,3}; //PETAL_SEGMENT_* static const uint8_t bot_segment_map[] = {3,0,3,0,0,0,3,0,3,1,2,3}; //PETAL_SEGMENT_*
static const uint8_t bot_stage_config[] = {0,1,2,3,5,6,7,8,9,10,11,12}; static const uint8_t bot_stage_config[] = {0,1,2,3,5,6,7,8,9,10,11,12};
#define DEFAULT_THRES_TOP 8000
#define DEFAULT_THRES_BOT 12000
#define AD7147_ADDR_TOP 0b101100 #define AD7147_ADDR_TOP 0b101100
#define AD7147_ADDR_BOT 0b101101 #define AD7147_ADDR_BOT 0b101101
#endif #endif
...@@ -27,8 +29,11 @@ static const uint8_t top_map[] = {2, 2, 2, 0, 0, 8, 8, 8, 6, 6, 4, 4}; ...@@ -27,8 +29,11 @@ static const uint8_t top_map[] = {2, 2, 2, 0, 0, 8, 8, 8, 6, 6, 4, 4};
static const uint8_t top_stages = 12; static const uint8_t top_stages = 12;
static const uint8_t bot_map[] = {1, 1, 3, 3, 5, 5, 7, 7, 9, 9}; static const uint8_t bot_map[] = {1, 1, 3, 3, 5, 5, 7, 7, 9, 9};
static const uint8_t bot_stages = 10; static const uint8_t bot_stages = 10;
static const uint8_t top_segment_map[] = {1,2,3,1,2,3,1,2,3,1,2,3}; //idk static const uint8_t top_segment_map[] = {1,2,0,1,2,1,2,0,1,2,1,2}; //idk
static const uint8_t bot_segment_map[] = {0,3,0,3,0,3,0,3,0,3,0,3}; //idk static const uint8_t bot_segment_map[] = {3,0,3,0,3,0,0,3,0,3}; //idk
static const uint8_t bot_stage_config[] = {0,1,2,3,4,5,6,7,8,9,10,11};
#define DEFAULT_THRES_TOP 2000
#define DEFAULT_THRES_BOT 12000
#define AD7147_ADDR_TOP 0b101101 #define AD7147_ADDR_TOP 0b101101
#define AD7147_ADDR_BOT 0b101100 #define AD7147_ADDR_BOT 0b101100
#endif #endif
...@@ -44,13 +49,12 @@ static const char *TAG = "captouch"; ...@@ -44,13 +49,12 @@ static const char *TAG = "captouch";
#define TIMEOUT_MS 1000 #define TIMEOUT_MS 1000
#define DEFAULT_THRES_TOP 8000
#define DEFAULT_THRES_BOT 12000
static struct ad714x_chip *chip_top; static struct ad714x_chip *chip_top;
static struct ad714x_chip *chip_bot; static struct ad714x_chip *chip_bot;
typedef struct{ typedef struct{
uint8_t config_mask;
uint16_t amb_values[4]; //ordered according to PETAL_SEGMENT_* uint16_t amb_values[4]; //ordered according to PETAL_SEGMENT_*
uint16_t cdc_values[4]; //ordered according to PETAL_SEGMENT_* uint16_t cdc_values[4]; //ordered according to PETAL_SEGMENT_*
uint16_t thres_values[4]; //ordered according to PETAL_SEGMENT_* uint16_t thres_values[4]; //ordered according to PETAL_SEGMENT_*
...@@ -212,8 +216,7 @@ static void captouch_init_chip(const struct ad714x_chip* chip, const struct ad71 ...@@ -212,8 +216,7 @@ static void captouch_init_chip(const struct ad714x_chip* chip, const struct ad71
} }
} }
void captouch_init(void) static void captouch_init_petals(){
{
for(int i = 0; i < 10; i++){ for(int i = 0; i < 10; i++){
for(int j = 0; j < 4; j++){ for(int j = 0; j < 4; j++){
petals[i].amb_values[j] = 0; petals[i].amb_values[j] = 0;
...@@ -224,7 +227,61 @@ void captouch_init(void) ...@@ -224,7 +227,61 @@ void captouch_init(void)
petals[i].thres_values[j] = DEFAULT_THRES_TOP; petals[i].thres_values[j] = DEFAULT_THRES_TOP;
} }
} }
petals[i].config_mask = 0;
}
for(int i = 0; i < bot_stages; i++){
petals[bot_map[i]].config_mask |= 1 << bot_segment_map[i];
}
for(int i = 0; i < top_stages; i++){
petals[top_map[i]].config_mask |= 1 << top_segment_map[i];
} }
}
int32_t captouch_get_petal_rad(uint8_t petal){
uint8_t cf = petals[petal].config_mask;
if(cf == 0b1110){ //LEFT, RIGHT, BASE
int32_t left = petals[petal].cdc_values[PETAL_SEGMENT_LEFT];
left -= petals[petal].amb_values[PETAL_SEGMENT_LEFT];
int32_t right = petals[petal].cdc_values[PETAL_SEGMENT_RIGHT];
right -= petals[petal].amb_values[PETAL_SEGMENT_RIGHT];
int32_t base = petals[petal].cdc_values[PETAL_SEGMENT_BASE];
base -= petals[petal].amb_values[PETAL_SEGMENT_BASE];
return (left + right)/2 - base;
}
if(cf == 0b111){ //LEFT, RIGHT, TIP
int32_t left = petals[petal].cdc_values[PETAL_SEGMENT_LEFT];
left -= petals[petal].amb_values[PETAL_SEGMENT_LEFT];
int32_t right = petals[petal].cdc_values[PETAL_SEGMENT_RIGHT];
right -= petals[petal].amb_values[PETAL_SEGMENT_RIGHT];
int32_t tip = petals[petal].cdc_values[PETAL_SEGMENT_TIP];
tip -= petals[petal].amb_values[PETAL_SEGMENT_TIP];
return (-left - right)/2 + tip;
}
if(cf == 0b1001){ //TIP, BASE
int32_t tip = petals[petal].cdc_values[PETAL_SEGMENT_TIP];
tip -= petals[petal].amb_values[PETAL_SEGMENT_TIP];
int32_t base = petals[petal].cdc_values[PETAL_SEGMENT_BASE];
base -= petals[petal].amb_values[PETAL_SEGMENT_BASE];
return tip - base;
}
return 0;
}
int32_t captouch_get_petal_phi(uint8_t petal){
uint8_t cf = petals[petal].config_mask;
if((cf == 0b1110) || (cf == 0b110) || (cf == 0b111)){ //LEFT, RIGHT, (BASE)
int32_t left = petals[petal].cdc_values[PETAL_SEGMENT_LEFT];
left -= petals[petal].amb_values[PETAL_SEGMENT_LEFT];
int32_t right = petals[petal].cdc_values[PETAL_SEGMENT_RIGHT];
right -= petals[petal].amb_values[PETAL_SEGMENT_RIGHT];
return left - right;
}
return 0;
}
void captouch_init(void)
{
captouch_init_petals();
chip_top = &chip_top_rev5; chip_top = &chip_top_rev5;
chip_bot = &chip_bot_rev5; chip_bot = &chip_bot_rev5;
......
...@@ -11,3 +11,5 @@ uint16_t captouch_get_petal_pad_raw(uint8_t petal, uint8_t pad, uint8_t amb); ...@@ -11,3 +11,5 @@ uint16_t captouch_get_petal_pad_raw(uint8_t petal, uint8_t pad, uint8_t amb);
void captouch_force_calibration(); void captouch_force_calibration();
void captouch_set_petal_pad_threshold(uint8_t petal, uint8_t pad, uint16_t thres); void captouch_set_petal_pad_threshold(uint8_t petal, uint8_t pad, uint16_t thres);
uint16_t read_captouch(); uint16_t read_captouch();
int32_t captouch_get_petal_phi(uint8_t petal);
int32_t captouch_get_petal_rad(uint8_t petal);
...@@ -10,20 +10,16 @@ def init(): ...@@ -10,20 +10,16 @@ def init():
def run(): def run():
hardware.display_fill(0) hardware.display_fill(0)
time.sleep_ms(30) time.sleep_ms(30)
for i in range(0,10,2): for i in range(10):
size = (hardware.get_captouch(i) * 4) + 4 size = (hardware.get_captouch(i) * 4) + 4
x = 70 + (utils.captouch_get_rad(i)/1000) x = 70 + (hardware.captouch_get_petal_rad(i)/1000)
x += (utils.captouch_get_phi(i)/600)*1j x += (hardware.captouch_get_petal_phi(i)/600)*1j
rot = cmath.exp(2j *math.pi * i / 10) rot = cmath.exp(2j *math.pi * i / 10)
x = x * rot x = x * rot
utils.draw_rect(int(x.imag+120-(size/2)),int(x.real+120-(size/2)),size,size,0b1111100000011111) col = 0b1111100000011111
for i in range(1,10,2): if i%2:
size = (hardware.get_captouch(i) * 4) + 4 col = 0b0000011111111111
x = 70 + (utils.captouch_get_rad(i)/1000) utils.draw_rect(int(x.imag+120-(size/2)),int(x.real+120-(size/2)),size,size,col)
x += (utils.captouch_get_phi(i)/600)*1j
rot = cmath.exp(2j *math.pi * i / 10)
x = x * rot
utils.draw_rect(int(x.imag+120-(size/2)),int(x.real+120-(size/2)),size,size,0b0000011111111111)
hardware.display_update() hardware.display_update()
def foreground(): def foreground():
......
...@@ -5,26 +5,6 @@ RED = 0b1111100000000000 ...@@ -5,26 +5,6 @@ RED = 0b1111100000000000
GREEN = 0b0000011111100000 GREEN = 0b0000011111100000
BLUE = 0b0000000000011111 BLUE = 0b0000000000011111
def captouch_get_phi(petal):
if(petal%2):
return 0
else:
l = captouch_get_petal_pad(petal,1)
r = captouch_get_petal_pad(petal,2)
b = captouch_get_petal_pad(petal,3)
return l - r
def captouch_get_rad(petal):
if(petal%2):
t = captouch_get_petal_pad(petal,0)
b = captouch_get_petal_pad(petal,3)
return t - b
else:
l = captouch_get_petal_pad(petal,1)
r = captouch_get_petal_pad(petal,2)
b = captouch_get_petal_pad(petal,3)
return (l + r)/2 - b
def clear_all_leds(): def clear_all_leds():
for i in range(40): for i in range(40):
set_led_rgb(i, 0, 0, 0) set_led_rgb(i, 0, 0, 0)
......
...@@ -74,6 +74,22 @@ STATIC mp_obj_t mp_captouch_get_petal_pad(size_t n_args, const mp_obj_t *args) { ...@@ -74,6 +74,22 @@ STATIC mp_obj_t mp_captouch_get_petal_pad(size_t n_args, const mp_obj_t *args) {
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_captouch_get_petal_pad_obj, 2, 3, mp_captouch_get_petal_pad); STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_captouch_get_petal_pad_obj, 2, 3, mp_captouch_get_petal_pad);
STATIC mp_obj_t mp_captouch_get_petal_rad(size_t n_args, const mp_obj_t *args) {
uint8_t petal = mp_obj_get_int(args[0]);
int32_t ret = captouch_get_petal_rad(petal);
return mp_obj_new_int(ret);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_captouch_get_petal_rad_obj, 1, 2, mp_captouch_get_petal_rad);
STATIC mp_obj_t mp_captouch_get_petal_phi(size_t n_args, const mp_obj_t *args) {
uint8_t petal = mp_obj_get_int(args[0]);
int32_t ret = captouch_get_petal_phi(petal);
return mp_obj_new_int(ret);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_captouch_get_petal_phi_obj, 1, 2, mp_captouch_get_petal_phi);
STATIC mp_obj_t mp_captouch_set_petal_pad_threshold(size_t n_args, const mp_obj_t *args) { STATIC mp_obj_t mp_captouch_set_petal_pad_threshold(size_t n_args, const mp_obj_t *args) {
uint8_t petal = mp_obj_get_int(args[0]); uint8_t petal = mp_obj_get_int(args[0]);
uint8_t pad = mp_obj_get_int(args[1]); uint8_t pad = mp_obj_get_int(args[1]);
...@@ -152,6 +168,8 @@ STATIC const mp_rom_map_elem_t mp_module_hardware_globals_table[] = { ...@@ -152,6 +168,8 @@ STATIC const mp_rom_map_elem_t mp_module_hardware_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_get_captouch), MP_ROM_PTR(&mp_get_captouch_obj) }, { MP_ROM_QSTR(MP_QSTR_get_captouch), MP_ROM_PTR(&mp_get_captouch_obj) },
{ MP_ROM_QSTR(MP_QSTR_captouch_get_petal_pad_raw), MP_ROM_PTR(&mp_captouch_get_petal_pad_raw_obj) }, { MP_ROM_QSTR(MP_QSTR_captouch_get_petal_pad_raw), MP_ROM_PTR(&mp_captouch_get_petal_pad_raw_obj) },
{ MP_ROM_QSTR(MP_QSTR_captouch_get_petal_pad), MP_ROM_PTR(&mp_captouch_get_petal_pad_obj) }, { MP_ROM_QSTR(MP_QSTR_captouch_get_petal_pad), MP_ROM_PTR(&mp_captouch_get_petal_pad_obj) },
{ MP_ROM_QSTR(MP_QSTR_captouch_get_petal_rad), MP_ROM_PTR(&mp_captouch_get_petal_rad_obj) },
{ MP_ROM_QSTR(MP_QSTR_captouch_get_petal_phi), MP_ROM_PTR(&mp_captouch_get_petal_phi_obj) },
{ MP_ROM_QSTR(MP_QSTR_captouch_set_petal_pad_threshold), MP_ROM_PTR(&mp_captouch_set_petal_pad_threshold_obj) }, { MP_ROM_QSTR(MP_QSTR_captouch_set_petal_pad_threshold), MP_ROM_PTR(&mp_captouch_set_petal_pad_threshold_obj) },
{ MP_ROM_QSTR(MP_QSTR_captouch_autocalib), MP_ROM_PTR(&mp_captouch_autocalib_obj) }, { MP_ROM_QSTR(MP_QSTR_captouch_autocalib), MP_ROM_PTR(&mp_captouch_autocalib_obj) },
{ MP_ROM_QSTR(MP_QSTR_get_button), MP_ROM_PTR(&mp_get_button_obj) }, { MP_ROM_QSTR(MP_QSTR_get_button), MP_ROM_PTR(&mp_get_button_obj) },
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment