Skip to content

Commit

Permalink
Merge branch 'master' into v4.x
Browse files Browse the repository at this point in the history
  • Loading branch information
profezzorn committed May 14, 2020
2 parents 3e56a95 + ff85a10 commit ecb2717
Show file tree
Hide file tree
Showing 15 changed files with 403 additions and 292 deletions.
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ BOARD_TAG=Proffieboard-L433CC
# This should only need to be set if arduino is installed in a nonstandard location.
# ARDUINO_DIR:=/home/hubbe/lib/arduino-1.8.3

ifeq ($(strip $(BOARD_TAG)),Proffieboard-L433CC)
ifeq ($(findstring Proffieboard, $(BOARD_TAG)),Proffieboard)
USB_TYPE=USB_TYPE_CDC_MSC_WEBUSB
ARDUINO_LIBS=SPI Wire
include Proffieboard.mk
Expand Down Expand Up @@ -37,6 +37,9 @@ test1:
test1V:
$(MAKE) all TESTFLAGS=-DCONFIG_FILE_TEST=\\\"config/proffieboard_v1_verification_config.h\\\" BOARD_TAG=Proffieboard-L433CC OBJDIR=test-proffieboard-v1-verification

test2V:
$(MAKE) all TESTFLAGS=-DCONFIG_FILE_TEST=\\\"config/proffieboard_v2_verification_config.h\\\" BOARD_TAG=ProffieboardV2-L433CC OBJDIR=test-proffieboard-v2-verification

test2:
$(MAKE) all TESTFLAGS=-DCONFIG_FILE_TEST=\\\"config/default_v3_config.h\\\" BOARD_TAG=teensy36 OBJDIR=test-teensy36-default-v3

Expand Down Expand Up @@ -68,7 +71,7 @@ testB:
$(MAKE) all TESTFLAGS=-DCONFIG_FILE_TEST=\\\"config/td_proffieboard_config.h\\\" BOARD_TAG=Proffieboard-L433CC OBJDIR=test-proffieboard-td


test: style-test common-test blades-test sound-test test1 test2 test3 test4 test5 test6 test7 test8 test9 testA testB test1V
test: style-test common-test blades-test sound-test test1 test2 test3 test4 test5 test6 test7 test8 test9 testA testB test1V test2V
@echo Tests pass

# Check that there are no uncommitted changes
Expand Down
3 changes: 3 additions & 0 deletions ProffieOS.ino
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ SnoozeBlock snooze_config(snooze_touch, snooze_digital, snooze_timer);
#endif

const char version[] = "$Id: ce12a06a1e236b5101ec60c950530a9a4719a74d $";
const char install_time[] = __DATE__ " " __TIME__;

#include "common/state_machine.h"
#include "common/monitoring.h"
Expand Down Expand Up @@ -1016,6 +1017,8 @@ class Commands : public CommandParser {

if (!strcmp(cmd, "version")) {
STDOUT.println(version);
STDOUT.print("Installed: ");
STDOUT.println(install_time);
return true;
}
if (!strcmp(cmd, "reset")) {
Expand Down
6 changes: 2 additions & 4 deletions Proffieboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -401,12 +401,10 @@ endif
CPPFLAGS += -DMD -DUSB_TYPE=$(USB_TYPE) '-DUSB_PRODUCT=$(USB_PRODUCT)' '-DUSB_MANUFACTURER=$(USB_MANUFACTURER)'

# Get extra define flags from boards.txt
EXFLAGS := $(shell echo $(call PARSE_BOARD,$(BOARD_TAG),build.extra_flags) | grep -oE '(-D)\w+')
EXFLAGS := $(shell echo $(call PARSE_BOARD,$(BOARD_TAG),build.extra_flags) | grep -oE '(-D)[^ ]+')
$(call show_config_variable,EXTRA FLAGS,[COMPUTED])
XFLAGS=-ffast-math -fsingle-precision-constant -D__FPU_PRESENT=1 -march=armv7e-m -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mabi=aapcs -mslow-flash-data -DDOSFS_SDCARD=1 -DUSB_DID=0xffff -D_SYSTEM_CORE_CLOCK_=80000000L -D_ARDUINO_STM32L4

# TODO: Makefile selects proffieboard version
CPPFLAGS += -DPROFFIEBOARD_VERSION=1

# Strip only defines from extra flags as boards file appends user {build.usb}
CPPFLAGS += $(EXFLAGS) $(XFLAGS)
CPPFLAGS += -DUSB_VID=$(USB_VID)
Expand Down
9 changes: 0 additions & 9 deletions blades/blade_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ DEFINE_ALL_EFFECTS();
HANDLED_FEATURE_DRAG = 1 << 3,
HANDLED_FEATURE_MELT = 1 << 4,
HANDLED_FEATURE_LIGHTNING_BLOCK = 1 << 5,
HANDLED_FEATURE_PREON = 1 << 6,
};

#include "../styles/blade_style.h"
Expand Down Expand Up @@ -110,11 +109,6 @@ class BladeBase {
handled_features_ = (HandledFeature) ((int)handled_features_ | (int)feature);
}

// Returns true if the current style handles a particular effect type.
static bool IsHandled(HandledFeature effect) {
return (handled_features_ & effect) != 0;
}

static HandledFeature GetHandledTypes() {
return handled_features_;
}
Expand All @@ -137,9 +131,6 @@ class OneshotEffectDetector {
case EFFECT_STAB:
BladeBase::HandleFeature(HANDLED_FEATURE_STAB);
break;
case EFFECT_PREON:
BladeBase::HandleFeature(HANDLED_FEATURE_PREON);
break;
default:
break;
}
Expand Down
7 changes: 2 additions & 5 deletions blades/fastled_blade.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,8 @@ class FASTLED_Blade : public AbstractBlade, CommandParser, Looper {
}
void SB_PreOn(float* d) override {
AbstractBlade::SB_PreOn(d);
// This blade uses EFFECT_PREON, so we need to turn the power on now.
if (IsHandled(HANDLED_FEATURE_PREON)) {
Power(true);
delay(10);
}
Power(true);
delay(10);
}
void SB_Off(OffType off_type) override {
AbstractBlade::SB_Off(off_type);
Expand Down
6 changes: 2 additions & 4 deletions blades/simple_blade.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,8 @@ class Simple_Blade : public AbstractBlade, CommandParser, Looper {
void SB_PreOn(float* delay) override {
AbstractBlade::SB_PreOn(delay);
// This blade uses EFFECT_PREON, so we need to turn the power on now.
if (IsHandled(HANDLED_FEATURE_PREON)) {
battery_monitor.SetLoad(true);
Power(true);
}
battery_monitor.SetLoad(true);
Power(true);
}
void SB_Off(OffType off_type) override {
AbstractBlade::SB_Off(off_type);
Expand Down
3 changes: 1 addition & 2 deletions blades/spiled_pin.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define BLADES_SPILEDPIN_H

template<int CLOCK_PIN>
class SpiLedPin : public Looper {
class SpiLedPin {
public:
SpiLedPin(int pin,
int num_leds,
Expand Down Expand Up @@ -57,7 +57,6 @@ class SpiLedPin : public Looper {
}

void Set(int led, Color16 color) {
uint8_t *output = ((uint8_t *)displayMemory) + (led + 1) * (1 + Color8::num_bytes(byteorder_));
int MAX = std::max(color.r, std::max(color.g, color.b));
int output_level = (MAX + 2113) / 2117;
int mult = output_level == 0 ? 0 : 7930 / output_level;
Expand Down
87 changes: 53 additions & 34 deletions blades/ws2811_blade.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class WS2811_Blade : public AbstractBlade, CommandParser, Looper {
STDOUT.print("WS2811 Blade with ");
STDOUT.print(pin_.num_leds());
STDOUT.println(" leds.");
Power(true);
run_ = true;
CommandParser::Link();
Looper::Link();
AbstractBlade::Activate();
Expand All @@ -107,14 +107,14 @@ class WS2811_Blade : public AbstractBlade, CommandParser, Looper {
}
void set(int led, Color16 c) override {
color_buffer[led] = c;
}
}
void allow_disable() override {
if (!on_) allow_disable_ = true;
}
void SetStyle(BladeStyle* style) override{
TRACE("SetStyle");
AbstractBlade::SetStyle(style);
Power(true);
run_ = true;
}
BladeStyle* UnSetStyle() override {
TRACE("UnSetStyle");
Expand All @@ -127,17 +127,15 @@ class WS2811_Blade : public AbstractBlade, CommandParser, Looper {
void SB_On() override {
TRACE("SB_On");
AbstractBlade::SB_On();
Power(true);
run_ = true;
on_ = true;
power_off_requested_ = false;
}
void SB_PreOn(float* delay) override {
AbstractBlade::SB_PreOn(delay);
// This blade uses EFFECT_PREON, so we need to turn the power on now.
if (IsHandled(HANDLED_FEATURE_PREON)) {
Power(true);
power_off_requested_ = false;
}
run_ = true;
power_off_requested_ = false;
}
void SB_Off(OffType off_type) override {
TRACE("SB_Off");
Expand Down Expand Up @@ -171,61 +169,82 @@ class WS2811_Blade : public AbstractBlade, CommandParser, Looper {
void Help() override {
STDOUT.println(" blade on/off - turn ws2811 blade on off");
}
void PowerOff() {
if (!poweroff_delay_start_) {
poweroff_delay_start_ = millis();
}
if (millis() - poweroff_delay_start_ < poweroff_delay_ms_) {
return;
}
Power(false);
run_ = false;
power_off_requested_ = false;
}

#define BLADE_YIELD() do { \
YIELD(); \
/* If Power() was called.... */ \
if (current_blade != this) goto retry; \
} while(0)

protected:
void Loop() override {
STATE_MACHINE_BEGIN();
while (true) {
retry:
while (!powered_ || !current_style_) {
if (current_blade == this) current_blade = NULL;
YIELD();
if (!current_style_ || !run_) {
loop_counter_.Reset();
YIELD();
continue;
}
// Wait until it's our turn.
while (current_blade) YIELD();
if (allow_disable_ || power_off_requested_) {
if (!on_) {
if (!poweroff_delay_start_) {
poweroff_delay_start_ = millis();
}
if (millis() - poweroff_delay_start_ < poweroff_delay_ms_) {
YIELD();
continue;
}
poweroff_delay_start_ = 0;
}
Power(on_);
if (current_blade) {
continue;
}
current_blade = this;
if (power_off_requested_) {
PowerOff();
continue;
}

allow_disable_ = false;
current_style_->run(this);
while (!pin_.IsReadyForBeginFrame()) {
YIELD();
// If Power() was called....
if (current_blade != this) goto retry;

if (!powered_) {
if (allow_disable_) continue;
Power(true);
}

// Update pixels
while (!pin_.IsReadyForBeginFrame()) BLADE_YIELD();
pin_.BeginFrame();
for (int i = 0; i < pin_.num_leds(); i++) {
pin_.Set(i, color_buffer[i]);
if (!(i & 0x1f)) Looper::DoHFLoop();
}
while (!pin_.IsReadyForEndFrame()) {
YIELD();
// If Power() was called....
if (current_blade != this) goto retry;
}
while (!pin_.IsReadyForEndFrame()) BLADE_YIELD();
pin_.EndFrame();
loop_counter_.Update();
current_blade = NULL;
YIELD();

if (powered_ && allow_disable_) {
PowerOff();
run_ = false;
}
}
STATE_MACHINE_END();
}

private:
// Loop should run.
bool run_ = false;
// Blade is "on"
bool on_ = false;
// Blade has power
bool powered_ = false;
// Style has indicated that it's ok to shutd down until the next wakeup event.
bool allow_disable_ = false;
// We should power off and stop running, even if the blade is on.
bool power_off_requested_ = false;
uint32_t poweroff_delay_ms_;
uint32_t poweroff_delay_start_ = 0;
Expand Down
11 changes: 7 additions & 4 deletions buttons/button_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,21 @@ class ButtonBase : public Looper,
// the event itself, and the event with a count, dependinging on how
// may double-presses there has been. The count starts at FIRST, that way
// the first event can be distinguished from the rest.
void Send(uint32_t event) {
bool Send(uint32_t event) {
if (!prop.Event(button_, (EVENT)(event + (EVENT_SECOND_PRESSED - EVENT_FIRST_PRESSED) * press_count_))) {
// Only send the second event if the first event didn't trigger a response.
prop.Event(button_, (EVENT)event);
return prop.Event(button_, (EVENT)event);
}
return true;
}

// We send the click immediately, but we also hold a "saved" event
// which is sent a little bit later unless a double-click occurs.
void SendClick(uint32_t event) {
Send(event);
saved_event_ = event + (EVENT_SAVED_CLICK_SHORT - EVENT_CLICK_SHORT);
if (!Send(event)) {
// Don't save the event if it's already been handled.
saved_event_ = event + (EVENT_SAVED_CLICK_SHORT - EVENT_CLICK_SHORT);
}
}

void Loop() override {
Expand Down
38 changes: 18 additions & 20 deletions common/battery_monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,30 +47,31 @@ BatteryMonitor() : reader_(batteryLevelPin,
SetPinHigh(false);
}
void Loop() override {
if (reading_) {
if (!reader_.Done()) return;
if (monitor.ShouldPrint(Monitoring::MonitorBattery) ||
millis() - last_print_millis_ > 20000) {
STDOUT.print("Battery voltage: ");
STDOUT.println(battery());
last_print_millis_ = millis();
}

STATE_MACHINE_BEGIN();
last_voltage_read_time_ = micros();
while (true) {
while (micros() - last_voltage_read_time_ < 1000) YIELD();
while (!reader_.Start()) YIELD();
while (!reader_.Done()) YIELD();
float v = battery_now();
last_voltage_ = last_voltage_ * 0.997 + v * 0.003;
reading_ = false;
uint32_t now = micros();
float mul = powf(0.05, (now - last_voltage_read_time_) / 1000000.0);
last_voltage_read_time_ = now;
last_voltage_ = last_voltage_ * mul + v * (1 - mul);
if (IsLow()) {
low_count_++;
} else {
low_count_ = 0;
}
}
uint32_t now = micros();
if (now - last_voltage_read_time_ >= 1000) {
if (!reader_.Start())
return;
reading_ = true;
last_voltage_read_time_ = now;
}
if (monitor.ShouldPrint(Monitoring::MonitorBattery) ||
millis() - last_print_millis_ > 20000) {
STDOUT.print("Battery voltage: ");
STDOUT.println(battery());
last_print_millis_ = millis();
}
STATE_MACHINE_END();
}

bool IsLow() {
Expand Down Expand Up @@ -103,8 +104,6 @@ BatteryMonitor() : reader_(batteryLevelPin,
}
#if 0
if (!strcmp(cmd, "bstate")) {
STDOUT.print("reading = ");
STDOUT.println(reading_);
STDOUT.print("Next state: ");
STDOUT.println(reader_.state_machine_.next_state_);
STDOUT.print("ADC SMP: ");
Expand Down Expand Up @@ -143,7 +142,6 @@ BatteryMonitor() : reader_(batteryLevelPin,
uint32_t last_print_millis_;
uint32_t low_count_ = 0;
AnalogReader reader_;
bool reading_ = false;
};

BatteryMonitor battery_monitor;
Expand Down
Loading

0 comments on commit ecb2717

Please sign in to comment.