Merge remote-tracking branch 'kiisu/kiisudev' into kiisu-mntm
@@ -0,0 +1,9 @@
|
||||
App(
|
||||
appid="kiisu_light",
|
||||
name="Kiisu ligh sensor ADC",
|
||||
apptype=FlipperAppType.EXTERNAL,
|
||||
entry_point="kiisu_light_adc_main",
|
||||
requires=["gui"],
|
||||
stack_size=1 * 1024,
|
||||
fap_category="System",
|
||||
)
|
||||
@@ -0,0 +1,145 @@
|
||||
/**
|
||||
* @file kiisu_light_ads.c
|
||||
* @brief Light level ADC.
|
||||
Based on ADC example.
|
||||
*/
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
|
||||
#include <gui/gui.h>
|
||||
#include <gui/elements.h>
|
||||
#include <input/input.h>
|
||||
|
||||
#include <lib/u8g2/u8g2.h>
|
||||
#include <lib/u8g2/u8g2_fonts.c>
|
||||
|
||||
#define FONT_HEIGHT (8u)
|
||||
|
||||
typedef float (*ValueConverter)(FuriHalAdcHandle* handle, uint16_t value);
|
||||
|
||||
typedef struct {
|
||||
const GpioPinRecord* pin;
|
||||
float value;
|
||||
ValueConverter converter;
|
||||
const char* suffix;
|
||||
} DataItem;
|
||||
|
||||
typedef struct {
|
||||
size_t count;
|
||||
DataItem* items;
|
||||
} Data;
|
||||
|
||||
const GpioPinRecord item_light = {.name = "LGHT", .channel = FuriHalAdcChannel4};
|
||||
const GpioPinRecord item_vref = {.name = "VREF", .channel = FuriHalAdcChannelVREFINT};
|
||||
const GpioPinRecord item_temp = {.name = "TEMP", .channel = FuriHalAdcChannelTEMPSENSOR};
|
||||
const GpioPinRecord item_vbat = {.name = "VBAT", .channel = FuriHalAdcChannelVBAT};
|
||||
|
||||
static void app_draw_callback(Canvas* canvas, void* ctx) {
|
||||
furi_assert(ctx);
|
||||
Data* data = ctx;
|
||||
|
||||
canvas_set_custom_u8g2_font(canvas, u8g_font_5x8); // lib/u8g2/u8g2_fonts.c
|
||||
|
||||
char buffer[64];
|
||||
int32_t x = 0, y = FONT_HEIGHT;
|
||||
for(size_t i = 0; i < data->count; i++) {
|
||||
if(i == canvas_height(canvas) / FONT_HEIGHT) {
|
||||
x = 64;
|
||||
y = FONT_HEIGHT;
|
||||
}
|
||||
|
||||
snprintf(
|
||||
buffer,
|
||||
sizeof(buffer),
|
||||
"%4s: %4.0f%s\n",
|
||||
data->items[i].pin->name,
|
||||
(double)data->items[i].value,
|
||||
data->items[i].suffix);
|
||||
canvas_draw_str(canvas, x, y, buffer);
|
||||
y += FONT_HEIGHT;
|
||||
|
||||
if(i == 0) { //Light level
|
||||
char line[32];
|
||||
snprintf(line, sizeof(line), "%4.0f%%", 100 - ((double)data->items[i].value / 1187 * 100));
|
||||
canvas_draw_str(canvas, x, y, line);
|
||||
y += FONT_HEIGHT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void app_input_callback(InputEvent* input_event, void* ctx) {
|
||||
furi_assert(ctx);
|
||||
FuriMessageQueue* event_queue = ctx;
|
||||
furi_message_queue_put(event_queue, input_event, FuriWaitForever);
|
||||
}
|
||||
|
||||
int32_t kiisu_light_adc_main(void* p) {
|
||||
UNUSED(p);
|
||||
|
||||
// Data
|
||||
Data data = {};
|
||||
data.count += 4; // Special channels
|
||||
data.items = malloc(data.count * sizeof(DataItem));
|
||||
size_t item_pos = 0;
|
||||
furi_hal_gpio_init(&gpio_ext_pc3, GpioModeAnalog, GpioPullDown, GpioSpeedHigh);
|
||||
data.items[item_pos].pin = &item_light;
|
||||
data.items[item_pos].converter = furi_hal_adc_convert_to_voltage;
|
||||
data.items[item_pos].suffix = "mV / 1187mV";
|
||||
item_pos++;
|
||||
data.items[item_pos].pin = &item_temp;
|
||||
data.items[item_pos].converter = furi_hal_adc_convert_temp;
|
||||
data.items[item_pos].suffix = "C";
|
||||
item_pos++;
|
||||
data.items[item_pos].pin = &item_vref;
|
||||
data.items[item_pos].converter = furi_hal_adc_convert_vref;
|
||||
data.items[item_pos].suffix = "mV";
|
||||
item_pos++;
|
||||
data.items[item_pos].pin = &item_vbat;
|
||||
data.items[item_pos].converter = furi_hal_adc_convert_vbat;
|
||||
data.items[item_pos].suffix = "mV";
|
||||
item_pos++;
|
||||
furi_assert(item_pos == data.count);
|
||||
|
||||
// Alloc message queue
|
||||
FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(InputEvent));
|
||||
|
||||
// Configure view port
|
||||
ViewPort* view_port = view_port_alloc();
|
||||
view_port_draw_callback_set(view_port, app_draw_callback, &data);
|
||||
view_port_input_callback_set(view_port, app_input_callback, event_queue);
|
||||
|
||||
// Register view port in GUI
|
||||
Gui* gui = furi_record_open(RECORD_GUI);
|
||||
gui_add_view_port(gui, view_port, GuiLayerFullscreen);
|
||||
|
||||
// Initialize ADC
|
||||
FuriHalAdcHandle* adc_handle = furi_hal_adc_acquire();
|
||||
furi_hal_adc_configure(adc_handle);
|
||||
|
||||
// Process events
|
||||
InputEvent event;
|
||||
bool running = true;
|
||||
while(running) {
|
||||
if(furi_message_queue_get(event_queue, &event, 100) == FuriStatusOk) {
|
||||
if(event.type == InputTypePress && event.key == InputKeyBack) {
|
||||
running = false;
|
||||
}
|
||||
} else {
|
||||
for(size_t i = 0; i < data.count; i++) {
|
||||
data.items[i].value = data.items[i].converter(
|
||||
adc_handle, furi_hal_adc_read(adc_handle, data.items[i].pin->channel));
|
||||
}
|
||||
view_port_update(view_port);
|
||||
}
|
||||
}
|
||||
|
||||
furi_hal_adc_release(adc_handle);
|
||||
view_port_enabled_set(view_port, false);
|
||||
gui_remove_view_port(gui, view_port);
|
||||
view_port_free(view_port);
|
||||
furi_message_queue_free(event_queue);
|
||||
furi_record_close(RECORD_GUI);
|
||||
free(data.items);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
After Width: | Height: | Size: 759 B |
@@ -0,0 +1,32 @@
|
||||
Filetype: Flipper Animation
|
||||
Version: 1
|
||||
|
||||
Width: 128
|
||||
Height: 47
|
||||
Passive frames: 1
|
||||
Active frames: 0
|
||||
Frames order: 0
|
||||
Active cycles: 0
|
||||
Frame rate: 2
|
||||
Duration: 3600
|
||||
Active cooldown: 0
|
||||
|
||||
Bubble slots: 2
|
||||
|
||||
Slot: 0
|
||||
X: 1
|
||||
Y: 23
|
||||
Text: Take the red pill
|
||||
AlignH: Right
|
||||
AlignV: Bottom
|
||||
StartFrame: 0
|
||||
EndFrame: 0
|
||||
|
||||
Slot: 1
|
||||
X: 1
|
||||
Y: 23
|
||||
Text: I can joke better
|
||||
AlignH: Right
|
||||
AlignV: Bottom
|
||||
StartFrame: 0
|
||||
EndFrame: 0
|
||||
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
@@ -0,0 +1,14 @@
|
||||
Filetype: Flipper Animation
|
||||
Version: 1
|
||||
|
||||
Width: 128
|
||||
Height: 64
|
||||
Passive frames: 4
|
||||
Active frames: 0
|
||||
Frames order: 0 1 2 3
|
||||
Active cycles: 0
|
||||
Frame rate: 1
|
||||
Duration: 10
|
||||
Active cooldown: 0
|
||||
|
||||
Bubble slots: 0
|
||||
|
After Width: | Height: | Size: 2.1 KiB |
@@ -0,0 +1,14 @@
|
||||
Filetype: Flipper Animation
|
||||
Version: 1
|
||||
|
||||
Width: 128
|
||||
Height: 64
|
||||
Passive frames: 1
|
||||
Active frames: 0
|
||||
Frames order: 0
|
||||
Active cycles: 0
|
||||
Frame rate: 1
|
||||
Duration: 10
|
||||
Active cooldown: 0
|
||||
|
||||
Bubble slots: 0
|
||||
|
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 1.8 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
@@ -3,12 +3,12 @@ Version: 1
|
||||
|
||||
Width: 128
|
||||
Height: 64
|
||||
Passive frames: 1
|
||||
Passive frames: 3
|
||||
Active frames: 0
|
||||
Frames order: 0
|
||||
Frames order: 0 1 2
|
||||
Active cycles: 0
|
||||
Frame rate: 1
|
||||
Duration: 3600
|
||||
Duration: 10
|
||||
Active cooldown: 0
|
||||
|
||||
Bubble slots: 0
|
||||
|
||||
@@ -6,4 +6,25 @@ Min butthurt: 0
|
||||
Max butthurt: 14
|
||||
Min level: 1
|
||||
Max level: 30
|
||||
Weight: 4
|
||||
|
||||
Name: LA_KiisuHappy_128x64
|
||||
Min butthurt: 0
|
||||
Max butthurt: 5
|
||||
Min level: 1
|
||||
Max level: 30
|
||||
Weight: 5
|
||||
|
||||
Name: LA_KiisuSad_128x64
|
||||
Min butthurt: 5
|
||||
Max butthurt: 14
|
||||
Min level: 1
|
||||
Max level: 30
|
||||
Weight: 5
|
||||
|
||||
Name: L1_Tv_128x47
|
||||
Min butthurt: 0
|
||||
Max butthurt: 14
|
||||
Min level: 1
|
||||
Max level: 30
|
||||
Weight: 4
|
||||
|
||||
|
Before Width: | Height: | Size: 488 B After Width: | Height: | Size: 304 B |
|
Before Width: | Height: | Size: 224 B After Width: | Height: | Size: 300 B |
|
Before Width: | Height: | Size: 448 B After Width: | Height: | Size: 304 B |
|
Before Width: | Height: | Size: 420 B After Width: | Height: | Size: 305 B |
|
Before Width: | Height: | Size: 330 B After Width: | Height: | Size: 303 B |
|
Before Width: | Height: | Size: 205 B After Width: | Height: | Size: 300 B |
|
Before Width: | Height: | Size: 362 B After Width: | Height: | Size: 835 B |
|
Before Width: | Height: | Size: 593 B After Width: | Height: | Size: 855 B |
|
Before Width: | Height: | Size: 752 B After Width: | Height: | Size: 884 B |
|
Before Width: | Height: | Size: 894 B After Width: | Height: | Size: 904 B |
|
Before Width: | Height: | Size: 737 B |
|
Before Width: | Height: | Size: 741 B |
|
Before Width: | Height: | Size: 613 B |
|
Before Width: | Height: | Size: 549 B |
|
Before Width: | Height: | Size: 547 B |
|
Before Width: | Height: | Size: 573 B |
|
Before Width: | Height: | Size: 576 B |
|
Before Width: | Height: | Size: 564 B After Width: | Height: | Size: 1.0 KiB |
|
Before Width: | Height: | Size: 357 B After Width: | Height: | Size: 871 B |
|
Before Width: | Height: | Size: 448 B After Width: | Height: | Size: 816 B |
|
Before Width: | Height: | Size: 368 B After Width: | Height: | Size: 753 B |
|
Before Width: | Height: | Size: 475 B After Width: | Height: | Size: 995 B |
|
Before Width: | Height: | Size: 515 B After Width: | Height: | Size: 829 B |
|
Before Width: | Height: | Size: 385 B After Width: | Height: | Size: 687 B |
|
Before Width: | Height: | Size: 262 B After Width: | Height: | Size: 1.0 KiB |
|
Before Width: | Height: | Size: 258 B After Width: | Height: | Size: 1.0 KiB |
|
Before Width: | Height: | Size: 368 B After Width: | Height: | Size: 788 B |
|
Before Width: | Height: | Size: 187 B After Width: | Height: | Size: 429 B |
|
Before Width: | Height: | Size: 389 B After Width: | Height: | Size: 738 B |
|
Before Width: | Height: | Size: 309 B After Width: | Height: | Size: 664 B |
|
Before Width: | Height: | Size: 296 B After Width: | Height: | Size: 614 B |
|
Before Width: | Height: | Size: 314 B After Width: | Height: | Size: 634 B |
|
Before Width: | Height: | Size: 291 B After Width: | Height: | Size: 592 B |
|
Before Width: | Height: | Size: 173 B After Width: | Height: | Size: 461 B |
|
Before Width: | Height: | Size: 121 B After Width: | Height: | Size: 265 B |
|
Before Width: | Height: | Size: 132 B After Width: | Height: | Size: 243 B |
|
Before Width: | Height: | Size: 117 B After Width: | Height: | Size: 257 B |
|
Before Width: | Height: | Size: 115 B After Width: | Height: | Size: 259 B |
|
Before Width: | Height: | Size: 472 B After Width: | Height: | Size: 263 B |
|
Before Width: | Height: | Size: 475 B After Width: | Height: | Size: 863 B |
|
Before Width: | Height: | Size: 283 B After Width: | Height: | Size: 660 B |
|
Before Width: | Height: | Size: 535 B After Width: | Height: | Size: 782 B |
|
Before Width: | Height: | Size: 518 B After Width: | Height: | Size: 782 B |
|
Before Width: | Height: | Size: 250 B After Width: | Height: | Size: 665 B |
|
Before Width: | Height: | Size: 239 B After Width: | Height: | Size: 650 B |
|
Before Width: | Height: | Size: 248 B After Width: | Height: | Size: 602 B |
|
Before Width: | Height: | Size: 248 B After Width: | Height: | Size: 667 B |
|
Before Width: | Height: | Size: 521 B After Width: | Height: | Size: 741 B |
@@ -130,9 +130,9 @@ void furi_hal_i2c_bus_handle_external_event(
|
||||
FuriHalI2cBusHandleEvent event) {
|
||||
if(event == FuriHalI2cBusHandleEventActivate) {
|
||||
furi_hal_gpio_init_ex(
|
||||
&gpio_ext_pc0, GpioModeAltFunctionOpenDrain, GpioPullNo, GpioSpeedLow, GpioAltFn4I2C3);
|
||||
&gpio_ext_pc0, GpioModeAltFunctionOpenDrain, GpioPullUp, GpioSpeedLow, GpioAltFn4I2C3);
|
||||
furi_hal_gpio_init_ex(
|
||||
&gpio_ext_pc1, GpioModeAltFunctionOpenDrain, GpioPullNo, GpioSpeedLow, GpioAltFn4I2C3);
|
||||
&gpio_ext_pc1, GpioModeAltFunctionOpenDrain, GpioPullUp, GpioSpeedLow, GpioAltFn4I2C3);
|
||||
|
||||
LL_I2C_InitTypeDef I2C_InitStruct;
|
||||
I2C_InitStruct.PeripheralMode = LL_I2C_MODE_I2C;
|
||||
|
||||
@@ -71,7 +71,7 @@ void furi_hal_power_init(void) {
|
||||
|
||||
furi_hal_i2c_acquire(&furi_hal_i2c_handle_power);
|
||||
// Find and init gauge
|
||||
size_t retry = 0;
|
||||
size_t retry = 2;
|
||||
while(retry > 0) {
|
||||
furi_hal_power.gauge_ok =
|
||||
bq27220_init(&furi_hal_i2c_handle_power, furi_hal_power_gauge_data_memory);
|
||||
@@ -85,7 +85,7 @@ void furi_hal_power_init(void) {
|
||||
retry--;
|
||||
}
|
||||
// Find and init charger
|
||||
retry = 0;
|
||||
retry = 2;
|
||||
while(retry > 0) {
|
||||
furi_hal_power.charger_ok = bq25896_init(&furi_hal_i2c_handle_power);
|
||||
if(furi_hal_power.charger_ok) {
|
||||
|
||||
@@ -5,11 +5,11 @@ bool furi_hal_version_do_i_belong_here(void) {
|
||||
}
|
||||
|
||||
const char* furi_hal_version_get_model_name(void) {
|
||||
return "Kiisu 4a";
|
||||
return "Kiisu 4";
|
||||
}
|
||||
|
||||
const char* furi_hal_version_get_model_code(void) {
|
||||
return "K4.A";
|
||||
return "K4.AB";
|
||||
}
|
||||
|
||||
const char* furi_hal_version_get_fcc_id(void) {
|
||||
|
||||