kopia lustrzana https://github.com/pimoroni/pimoroni-pico
as7343: Fix channel and status order.
The astatus value was being interpreted as FZ, F2 and F1 causing bizarre readings and all other channels to be shifted one place. Additionally the datasheet has been updated to re-order F5, F7 and F8 to F7, F8, F5, so these channels have been re-ordered accordingly. Note: This will turn sensor output from confusing abject nonsense into what looks like pretty reasonable colour data and fixes #989.pull/993/head
rodzic
dfc1875374
commit
052dbce334
|
@ -30,7 +30,7 @@ namespace pimoroni {
|
|||
i2c->set_bits(address, reg::FIFO_MAP, 0, FIFO_MAP_CH5 | FIFO_MAP_CH4 | FIFO_MAP_CH3 | FIFO_MAP_CH2 | FIFO_MAP_CH1 | FIFO_MAP_CH0 | FIFO_MAP_ASTATUS);
|
||||
|
||||
// Set the PON bit
|
||||
i2c->reg_write_uint8(address, reg::ENABLE, ENABLE_WEN | ENABLE_SMUXEN | ENABLE_SP_EN | ENABLE_PON);
|
||||
i2c->reg_write_uint8(address, reg::ENABLE, ENABLE_WEN | ENABLE_SP_EN | ENABLE_PON);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -135,10 +135,23 @@ namespace pimoroni {
|
|||
}
|
||||
}
|
||||
|
||||
void AS7343::start_measurement() {
|
||||
if(running) return;
|
||||
i2c->set_bits(address, reg::ENABLE, 0, ENABLE_SMUXEN);
|
||||
running = true;
|
||||
}
|
||||
|
||||
void AS7343::stop_measurement() {
|
||||
i2c->set_bits(address, reg::ENABLE, 0, ENABLE_SMUXEN);
|
||||
running = false;
|
||||
}
|
||||
|
||||
void AS7343::read_fifo(uint16_t *buf) {
|
||||
uint16_t expected_results = read_cycles * 7;
|
||||
uint16_t result_slot = 0;
|
||||
|
||||
start_measurement();
|
||||
|
||||
while (i2c->reg_read_uint8(address, reg::FIFO_LVL) < expected_results) {
|
||||
sleep_ms(1);
|
||||
}
|
||||
|
|
|
@ -49,6 +49,9 @@ namespace pimoroni {
|
|||
public:
|
||||
struct reading {
|
||||
// Cycle 1
|
||||
uint16_t c1_astatus = 0; // (c1_astatus >> 8) & 0b10001111
|
||||
// 0b10000000 = saturated
|
||||
// 0b00001111 = gain lowest nibble
|
||||
uint16_t FZ = 0; // 428-480 nm
|
||||
uint16_t FY = 0; // 534-593 nm
|
||||
uint16_t FXL = 0; // 593-628 nm
|
||||
|
@ -56,11 +59,10 @@ namespace pimoroni {
|
|||
|
||||
uint16_t c1_vis_tl = 0; // Visible top-left
|
||||
uint16_t c1_vis_br = 0; // Visible bottom-right
|
||||
uint16_t c1_astatus = 0; // (c1_astatus >> 8) & 0b10001111
|
||||
// 0b10000000 = saturated
|
||||
// 0b00001111 = gain lowest nibble
|
||||
//uint16_t c1_fd = 0; // This is where flicker detect *would* be
|
||||
|
||||
// Cycle 2
|
||||
uint16_t c2_astatus = 0;
|
||||
uint16_t F2 = 0; // 408-448 nm
|
||||
uint16_t F3 = 0; // 448-500 mn
|
||||
uint16_t F4 = 0; // 500-534 nm
|
||||
|
@ -68,17 +70,47 @@ namespace pimoroni {
|
|||
|
||||
uint16_t c2_vis_tl = 0;
|
||||
uint16_t c2_vis_br = 0;
|
||||
uint16_t c2_astatus = 0;
|
||||
//uint16_t c2_fd = 0;
|
||||
|
||||
// Cycle 3
|
||||
uint16_t c3_astatus = 0;
|
||||
uint16_t F1 = 0; // 396-408 nm
|
||||
uint16_t F5 = 0; // 531-594 nm
|
||||
uint16_t F7 = 0; // 685-715 nm
|
||||
uint16_t F8 = 0; // 715-766 nm
|
||||
uint16_t F5 = 0; // 531-594 nm
|
||||
|
||||
uint16_t c3_vis_tl = 0;
|
||||
uint16_t c3_vis_br = 0;
|
||||
uint16_t c3_astatus = 0;
|
||||
//uint16_t c3_fd = 0;
|
||||
|
||||
float gain(uint8_t cycle) {
|
||||
uint8_t status = 0;
|
||||
switch(cycle) {
|
||||
case 1:
|
||||
status = c1_astatus & 0xf;
|
||||
break;
|
||||
case 2:
|
||||
status = c2_astatus & 0xf;
|
||||
break;
|
||||
case 3:
|
||||
status = c3_astatus & 0xf;
|
||||
break;
|
||||
}
|
||||
return status ? 1 << (status - 1) : 0.5f;
|
||||
}
|
||||
|
||||
bool saturated(uint8_t cycle) {
|
||||
switch(cycle) {
|
||||
case 1:
|
||||
return c1_astatus & 0x80;
|
||||
case 2:
|
||||
return c2_astatus & 0x80;
|
||||
case 3:
|
||||
return c3_astatus & 0x80;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
@ -95,6 +127,8 @@ namespace pimoroni {
|
|||
uint8_t read_cycles = 1;
|
||||
uint8_t ch_count = (uint8_t)channel_count::SIX_CHANNEL;
|
||||
|
||||
bool running = false;
|
||||
|
||||
|
||||
//--------------------------------------------------
|
||||
// Constructors/Destructor
|
||||
|
@ -120,6 +154,9 @@ namespace pimoroni {
|
|||
|
||||
void get_version(uint8_t &auxid, uint8_t &revid, uint8_t &hwid);
|
||||
|
||||
void start_measurement();
|
||||
void stop_measurement();
|
||||
|
||||
reading read();
|
||||
|
||||
void read_fifo(uint16_t *buf);
|
||||
|
|
|
@ -62,6 +62,8 @@ int main() {
|
|||
reading.F8
|
||||
);
|
||||
|
||||
printf("Gain: C1: %fx C2: %fx C3: %fx\n", reading.gain(1), reading.gain(2), reading.gain(3));
|
||||
|
||||
sleep_ms(1000);
|
||||
}
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue