Skip to content

Commit

Permalink
ref
Browse files Browse the repository at this point in the history
  • Loading branch information
denis-hik committed Feb 7, 2024
1 parent 78b5951 commit 7d67331
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 38 deletions.
6 changes: 3 additions & 3 deletions hub.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ void build() {
hub.Title(F("Status"));
hub.BeginWidgets();
hub.WidgetSize(50);
hub.Gauge_(F("spd"), tacho_kmh(), F("kmh"), F("Speed"), 0, 35);
hub.Gauge_(F("spd"), data.max_spd / (35 - data.max_spd), F("kmh"), F("Speed"), 0, 35);
hub.Gauge(getBat(), F("%"), F("Battery"));

hub.Title(F("Mode"));
hub.WidgetSize(100);
flag |= hub.Tabs(&data.mode, F("Pallette,Color,Radial,Stop"), F("Mode"));
flag |= hub.Tabs(&data.mode, F("Palette,Radial"), F("Mode"));

if (data.mode == 0) {
hub.WidgetSize(50);
Expand Down Expand Up @@ -71,6 +71,6 @@ void hub_tick() {

static GHtimer upd(1000);
if (upd) {
hub.sendUpdate(F("spd"), String(tacho_kmh()));
// hub.sendUpdate(F("spd"), String(tacho_kmh()));
}
}
36 changes: 11 additions & 25 deletions led.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,16 @@ void led_change() {
void led_tick() {
static GHtimer tmr(LED_PRD);
if (tmr) {
static uint16_t pos = 0;
pos += data.max_spd * LED_PRD / 1000; // (mm / s) * (ms / 1000) == mm
if (data.max_spd == 0) {
pos = 0;
}

uint16_t idx = pos * data.ledm / 1000; // mm * (leds / m / 1000) == leds

switch (data.mode) {
case 0: {
static uint16_t pos = 0;
pos += data.max_spd * LED_PRD / 1000; // (mm / s) * (ms / 1000) == mm
if (data.max_spd == 0) {
pos = 0;
}

uint16_t idx = pos * data.ledm / 1000; // mm * (leds / m / 1000) == leds

for (uint16_t i = 0; i < data.led_amount; i++) {
leds[i] = ColorFromPalette(paletteArr[data.pal], 255 - (idx + i) * 255 / data.pal_len, 255, LINEARBLEND);
Expand All @@ -43,22 +44,8 @@ void led_tick() {
cled1->showLeds(data.led_bri);
} break;

case 1: {
uint16_t spd = min(tacho_speed(), (uint16_t)(35 * 278));
cled->showColor(CHSV(map(data.max_spd, 0, 35 * 278, 120, 0), 255, 255), data.led_bri);
cled1->showColor(CHSV(map(data.max_spd, 0, 35 * 278, 120, 0), 255, 255), data.led_bri);
} break;


case 2: {
static uint16_t pos = 0;
pos += data.max_spd * LED_PRD / 1000; // (mm / s) * (ms / 1000) == mm
if (data.max_spd == 0) {
pos = 0;
}

uint16_t idx = pos * data.ledm / 1000; // mm * (leds / m / 1000) == leds

case 1: {
for (uint16_t i = 0; i < data.led_amount; i++) {
if (i > data.led_amount / 2) {
leds[data.led_amount - i - 1] = ColorFromPalette(paletteArr[data.pal], 255 - (idx + i) * 255 / data.pal_len, 255, LINEARBLEND);
Expand All @@ -70,13 +57,12 @@ void led_tick() {
cled1->showLeds(data.led_bri);
}break;

case 3: {
uint16_t spd = min(tacho_speed(), (uint16_t)(35 * 278));
case 2: {
cled->showColor(CHSV(255, 0, 0), data.led_bri);
cled1->showColor(CHSV(255, 0, 0), data.led_bri);
} break;

case4: {
case 3: {
if (data.max_spd == 0) {
for (uint16_t i = 0; i < data.led_amount; i++) {
static uint16_t pos = 0;
Expand Down
10 changes: 0 additions & 10 deletions tacho.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,6 @@ void tacho_init() {
pinMode(TACHO_PIN, INPUT_PULLUP);
}

uint16_t tacho_speed() {
return _speed_f;
}
uint16_t tacho_kmh() {
return _speed_f / 278;
}
uint32_t tacho_pulse() {
return _pulse;
}

void tacho_tick() {
if (_tprd) {
_speed = (data.diam * 3141592ul) / _tprd; // (2*Pi*D / (prd / 1000000))
Expand Down

0 comments on commit 7d67331

Please sign in to comment.