summaryrefslogtreecommitdiffstats
path: root/lib/data/data_providers/hybrid_notifier.dart
blob: 7381f5cc4abece3bf353a0181868776f43ca3e44 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// ignore_for_file: unused_local_variable

import 'package:flutter_ics_homescreen/export.dart';

class HybridNotifier extends StateNotifier<Hybrid> {
  HybridNotifier(super.state);

  void setHybridState(HybridState hybridState) {
    switch (hybridState) {
      case HybridState.idle:
        state = state.copyWith(
            hybridState: hybridState,
            topArrowState: ArrowState.blue,
            leftArrowState: ArrowState.blue,
            rightArrowState: ArrowState.blue,
            batteryState: BatteryState.white,
        );
        break;
      case HybridState.engineOutput:
        state = state.copyWith(
            hybridState: hybridState,
            topArrowState: ArrowState.red,
            leftArrowState: ArrowState.red,
            rightArrowState: ArrowState.blue,
            batteryState: BatteryState.red,
        );
        break;
      case HybridState.regenerativeBreaking:
        state = state.copyWith(
            hybridState: hybridState,
            topArrowState: ArrowState.blue,
            leftArrowState: ArrowState.blue,
            rightArrowState: ArrowState.green,
            batteryState: BatteryState.green
        );
        break;
      case HybridState.batteryOutput:
        state = state.copyWith(
            hybridState: hybridState,
            topArrowState: ArrowState.blue,
            leftArrowState: ArrowState.blue,
            rightArrowState: ArrowState.yellow,
            batteryState: BatteryState.yellow
        );
        break;
      default:
        state = state.copyWith(hybridState: hybridState);
        break;
    }
  }

  void updateHybridState(double speed, double engineSpeed, bool brake) {
    // Variable to store the current state
    HybridState currentState = state.hybridState;

    // Variable to store the previous state
    HybridState previousState = currentState;

    // Variable to store the average speed value
    double avgSpeed = 0.0;

    // Variable for storing the average value of RPM
    double avgRpm = 0.0;
 
    if (speed == 0 && engineSpeed == 0) {
      // Set idle state.
      currentState = HybridState.idle;
    } else if (engineSpeed > 0 && speed > 0) {
      // Set engine output state..
      currentState = HybridState.engineOutput;
    } else if (speed < 0 && brake) {
      // Set regenerative breaking state
      currentState = HybridState.regenerativeBreaking;
    } else if (speed > 0 && engineSpeed <= 0) {
      // Set battery output state
      currentState = HybridState.batteryOutput;
    }

    // Update hybrid state
    if (currentState != previousState) {
      setHybridState(currentState);
    }
  }
}