Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ with `--dart-define=RUSTY_DEBUG_SERVER_IP=your-ip`. (by default is 127.0.0.1)

## Build

Run `flutter pub run build_runner build` before the actual build, to run the code generators. (like
Run `dart run build_runner build` before the actual build, to run the code generators. (like
the JSON serializable objects)

### Note while debugging / developing
Expand Down
4 changes: 2 additions & 2 deletions app/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath 'com.android.tools.build:gradle:7.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand All @@ -26,6 +26,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
2 changes: 1 addition & 1 deletion app/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-all.zip
2 changes: 1 addition & 1 deletion app/lib/bloc/effect_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:rusty_controller/model/led_effects.dart';
import '../service/controller_service.dart';

class EffectBloc extends Bloc<EffectChangeEvent, LedEffect> {
EffectBloc(LedEffect effect) : super(effect) {
EffectBloc(super.effect) {
final service = serviceLocator.get<ControllerService>();

on<EffectSettingChangeEvent>((event, emit) async {
Expand Down
57 changes: 20 additions & 37 deletions app/lib/bloc/effects/breathing_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,31 @@ import 'package:rusty_controller/model/led_effects.dart';

class BreathingBloc
extends SpecificEffectBloc<BreathingEffectEvent, BreathingLedEffect> {
BreathingBloc(BreathingLedEffect effect) : super(effect) {
on<BreathingColorEvent>(
(event, emit) => emit(state..color = event.currentColor));
on<BreathingTimeEvent>(
(event, emit) => emit(state..timeToPeak = event.timeToPeak));
on<BreathingPeakEvent>((event, emit) => emit(state..peak = event.peak));
on<BreathingFromOffEvent>((event, emit) {
if (event.breatheFromOff) {
emit(state..breatheFromOff = true);
} else {
emit(state
..breatheFromOff = false
..color = state.color.withValue(1.0));
}
});
BreathingBloc(super.effect) {
on<BreathingEffectEvent>((event, emit) => emit(event.toEffect(state)));
}
}

abstract class BreathingEffectEvent {}
class BreathingEffectEvent {
HSVColor? color;
int? timeToPeak;
double? peak;
bool? breatheFromOff;

class BreathingColorEvent extends BreathingEffectEvent {
HSVColor currentColor;
BreathingEffectEvent(
{this.color, this.timeToPeak, this.peak, this.breatheFromOff});

double get initialValue => currentColor.value;
BreathingLedEffect toEffect(BreathingLedEffect currentEffect) {
HSVColor color = this.color ?? currentEffect.color;

BreathingColorEvent(this.currentColor);
}

class BreathingTimeEvent extends BreathingEffectEvent {
int timeToPeak;

BreathingTimeEvent(this.timeToPeak);
}

class BreathingPeakEvent extends BreathingEffectEvent {
double peak;
if (breatheFromOff == true) {
color = color.withValue(1.0);
}

BreathingPeakEvent(this.peak);
}

class BreathingFromOffEvent extends BreathingEffectEvent {
bool breatheFromOff;

BreathingFromOffEvent(this.breatheFromOff);
return BreathingLedEffect(
color: color,
timeToPeak: timeToPeak ?? currentEffect.timeToPeak,
peak: peak ?? currentEffect.peak,
breatheFromOff: breatheFromOff ?? currentEffect.breatheFromOff);
}
}
36 changes: 36 additions & 0 deletions app/lib/bloc/effects/candle_bloc.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import 'package:rusty_controller/bloc/specific_effect_bloc.dart';
import 'package:rusty_controller/model/led_effects.dart';

class CandleBloc
extends SpecificEffectBloc<CandleEffectEvent, CandleLedEffect> {
CandleBloc(super.effect) {
on<CandleEffectEvent>((event, emit) => emit(event.toEffect(state)));
}
}

class CandleEffectEvent {
double? hue;
double? saturation;
double? minValue;
double? maxValue;
double? variability;
int? interval;

CandleEffectEvent(
{this.hue,
this.saturation,
this.minValue,
this.maxValue,
this.variability,
this.interval});

CandleLedEffect toEffect(CandleLedEffect currentEffect) {
return CandleLedEffect(
hue: hue ?? currentEffect.hue,
saturation: saturation ?? currentEffect.saturation,
minValue: minValue ?? currentEffect.minValue,
maxValue: maxValue ?? currentEffect.maxValue,
variability: variability ?? currentEffect.variability,
interval: interval ?? currentEffect.interval);
}
}
35 changes: 13 additions & 22 deletions app/lib/bloc/effects/rainbow_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,22 @@ import 'package:rusty_controller/model/led_effects.dart';

class RainbowBloc
extends SpecificEffectBloc<RainbowEffectEvent, RainbowLedEffect> {
RainbowBloc(RainbowLedEffect effect) : super(effect) {
on<RainbowSaturationEvent>(
(event, emit) => emit(state..saturation = event.saturation));
on<RainbowValueEvent>((event, emit) => emit(state..value = event.value));
on<RainbowTimeEvent>(
(event, emit) => emit(state..timeToComplete = event.timeToComplete));
RainbowBloc(super.effect) {
on<RainbowEffectEvent>((event, emit) => emit(event.toEffect(state)));
}
}

abstract class RainbowEffectEvent {}
class RainbowEffectEvent {
double? saturation;
double? value;
double? timeToComplete;

class RainbowSaturationEvent extends RainbowEffectEvent {
double saturation;
RainbowEffectEvent({this.saturation, this.value, this.timeToComplete});

RainbowSaturationEvent(this.saturation);
}

class RainbowValueEvent extends RainbowEffectEvent {
double value;

RainbowValueEvent(this.value);
}

class RainbowTimeEvent extends RainbowEffectEvent {
double timeToComplete;

RainbowTimeEvent(this.timeToComplete);
RainbowLedEffect toEffect(RainbowLedEffect currentEffect) {
return RainbowLedEffect(
saturation: saturation ?? currentEffect.saturation,
value: value ?? currentEffect.value,
timeToComplete: timeToComplete ?? currentEffect.timeToComplete);
}
}
12 changes: 5 additions & 7 deletions app/lib/bloc/effects/static_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@ import 'package:rusty_controller/model/led_effects.dart';

class StaticBloc
extends SpecificEffectBloc<StaticEffectEvent, StaticLedEffect> {
StaticBloc(StaticLedEffect effect) : super(effect) {
on<StaticColorEvent>(
(event, emit) => emit(state..color = event.currentColor));
StaticBloc(super.effect) {
on<StaticEffectEvent>(
(event, emit) => emit(StaticLedEffect(color: event.currentColor)));
}
}

abstract class StaticEffectEvent {}

class StaticColorEvent extends StaticEffectEvent {
class StaticEffectEvent {
HSVColor currentColor;

double get initialValue => currentColor.value;

StaticColorEvent(this.currentColor);
StaticEffectEvent(this.currentColor);
}
2 changes: 1 addition & 1 deletion app/lib/bloc/specific_effect_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ abstract class SpecificEffectBloc<EffectEvent, State extends LedEffect>
const Duration(milliseconds: 100),
);

SpecificEffectBloc(State initialState) : super(initialState);
SpecificEffectBloc(super.initialState);

@override
void on<E extends EffectEvent>(
Expand Down
63 changes: 32 additions & 31 deletions app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:logger/logger.dart';
import 'package:rusty_controller/bloc/discovery_bloc.dart';
import 'package:rusty_controller/bloc/effect_bloc.dart';
import 'package:rusty_controller/bloc/effects/breathing_bloc.dart';
import 'package:rusty_controller/bloc/effects/candle_bloc.dart';
import 'package:rusty_controller/bloc/effects/rainbow_bloc.dart';
import 'package:rusty_controller/bloc/effects/static_bloc.dart';
import 'package:rusty_controller/extensions/color_extensions.dart';
Expand All @@ -15,19 +16,31 @@ import 'package:rusty_controller/service/controller_service.dart';
import 'package:rusty_controller/service/discovery_service.dart';
import 'package:rusty_controller/service/store_service.dart';

final log = Logger(level: Level.verbose, printer: PrettyPrinter());
final log = Logger(level: Level.trace, printer: PrettyPrinter());
final serviceLocator = GetIt.instance;

final defaultEffects = {
EffectType.off: OffLedEffect(),
EffectType.static: StaticLedEffect(color: Colors.black.toHSV()),
EffectType.breathing: BreathingLedEffect(
color: Colors.red.toHSV().withValue(0.0),
timeToPeak: maxBreathingTime,
peak: 1.0,
breatheFromOff: true),
color: Colors.red.toHSV().withValue(0.0),
timeToPeak: maxBreathingTime,
peak: 1.0,
breatheFromOff: true,
),
EffectType.candle: CandleLedEffect(
hue: 0,
saturation: 1.0,
minValue: 0.5,
maxValue: 0.8,
variability: 1.0,
interval: 100,
),
EffectType.rainbow: RainbowLedEffect(
saturation: 1.0, value: 0.5, timeToComplete: maxRainbowTime),
saturation: 1.0,
value: 0.5,
timeToComplete: maxRainbowTime,
),
};

void main() {
Expand Down Expand Up @@ -66,48 +79,36 @@ void setupDependencies() {
defaultValue:
defaultEffects[EffectType.breathing] as BreathingLedEffect);

if (savedBreathing.timeToPeak < minBreathingTime ||
savedBreathing.timeToPeak > maxBreathingTime) {
savedBreathing.timeToPeak = maxBreathingTime;
}

if (savedBreathing.peak < 0.0 || savedBreathing.peak > 1.0) {
savedBreathing.peak = 1.0;
}

return BreathingBloc(savedBreathing);
},
);
serviceLocator.registerSingletonAsync(
() async {
final savedCandle = await storeService.get<CandleLedEffect>(
defaultValue: defaultEffects[EffectType.candle] as CandleLedEffect);

return CandleBloc(savedCandle);
},
);
serviceLocator.registerSingletonAsync(
() async {
final savedRainbow = await storeService.get<RainbowLedEffect>(
defaultValue: defaultEffects[EffectType.rainbow] as RainbowLedEffect);

if (savedRainbow.timeToComplete < minRainbowTime ||
savedRainbow.timeToComplete > maxRainbowTime) {
savedRainbow.timeToComplete = maxRainbowTime;
}

if (savedRainbow.saturation < 0.0 || savedRainbow.saturation > 1.0) {
savedRainbow.saturation = 1.0;
}

if (savedRainbow.value < 0.0 || savedRainbow.value > 1.0) {
savedRainbow.value = 1.0;
}

return RainbowBloc(savedRainbow);
},
);
}

class BaseScreen extends StatelessWidget {
const BaseScreen({Key? key}) : super(key: key);
const BaseScreen({super.key});

@override
Widget build(BuildContext context) {
return const GetMaterialApp(
home: Scaffold(
return GetMaterialApp(
themeMode: ThemeMode.dark,
darkTheme: ThemeData.dark(useMaterial3: true),
home: const Scaffold(
body: ScaffoldMessenger(
child: SafeArea(child: HomeScreen()),
),
Expand Down
Loading