Compare commits
	
		
			62 Commits
		
	
	
		
			PCB_Rev_1.
			...
			4843cc15c9
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 4843cc15c9 | |||
| 0b9ef67c39 | |||
| 94e34fb593 | |||
| ad6332acd4 | |||
| f514ee62fc | |||
| b0ddece378 | |||
| d5508137d3 | |||
| 27437555f8 | |||
| 1c0ab060ff | |||
| 2b5039b8ab | |||
| c3e71d4759 | |||
| 3c0a7c3c59 | |||
| 818d5843b3 | |||
| 872f577d35 | |||
| cda2bb7afc | |||
| dab826b862 | |||
| 6e0b7581eb | |||
| 3fffc1f0b1 | |||
| c0a6069006 | |||
| a74f02fc61 | |||
| 606bf4e3ee | |||
| e68a0b4d3e | |||
| 86e289f56f | |||
| 7a84b80126 | |||
| 0bc6d01a5f | |||
| 6ba4c40166 | |||
| fa23e72fbc | |||
| 7bd01a108a | |||
| 355b00a6cc | |||
| b361db164d | |||
| 16ec5d6e6d | |||
| d940d7aa78 | |||
| 7167efd1b1 | |||
| cc4a23f6df | |||
| 00b28e5d5e | |||
| 8b4e55d2dd | |||
| e6fa1e1ccd | |||
| efae15867a | |||
| 7187d512e5 | |||
| 5824a32ad2 | |||
| 055183ce90 | |||
| 6ae9c273cb | |||
| d92818d4e5 | |||
| 1ace7a8d6a | |||
| 39fc8af955 | |||
| 9571f5bbcc | |||
| b029243760 | |||
| 152a324c9d | |||
| f2e0e70647 | |||
| 8e6941b5bc | |||
| f3ce691b7d | |||
| aefbdc43bc | |||
| 08c00efbdf | |||
| cdbeb2b8c3 | |||
| cfc6b144f3 | |||
| e1ca503bd2 | |||
| d68b562126 | |||
| 2217d68026 | |||
| acb3c97c02 | |||
| 70ea944dc3 | |||
| cff7c7b29c | |||
| ea4895c262 | 
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1 @@
 | 
			
		||||
Bestellung.xlsx
 | 
			
		||||
							
								
								
									
										1
									
								
								Hardware/.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						@@ -28,3 +28,4 @@ fp-info-cache
 | 
			
		||||
*.csv
 | 
			
		||||
 | 
			
		||||
gerber/
 | 
			
		||||
*-backups/
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								Hardware/BOM_Reichelt.xlsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										74603
									
								
								Hardware/Device.kicad_sym
									
									
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										443
									
								
								Hardware/oiler SMD.kicad_pro
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,443 @@
 | 
			
		||||
{
 | 
			
		||||
  "board": {
 | 
			
		||||
    "design_settings": {
 | 
			
		||||
      "defaults": {
 | 
			
		||||
        "board_outline_line_width": 0.049999999999999996,
 | 
			
		||||
        "copper_line_width": 0.19999999999999998,
 | 
			
		||||
        "copper_text_italic": false,
 | 
			
		||||
        "copper_text_size_h": 1.5,
 | 
			
		||||
        "copper_text_size_v": 1.5,
 | 
			
		||||
        "copper_text_thickness": 0.3,
 | 
			
		||||
        "copper_text_upright": false,
 | 
			
		||||
        "courtyard_line_width": 0.049999999999999996,
 | 
			
		||||
        "dimension_precision": 4,
 | 
			
		||||
        "dimension_units": 3,
 | 
			
		||||
        "dimensions": {
 | 
			
		||||
          "arrow_length": 1270000,
 | 
			
		||||
          "extension_offset": 500000,
 | 
			
		||||
          "keep_text_aligned": true,
 | 
			
		||||
          "suppress_zeroes": false,
 | 
			
		||||
          "text_position": 0,
 | 
			
		||||
          "units_format": 1
 | 
			
		||||
        },
 | 
			
		||||
        "fab_line_width": 0.09999999999999999,
 | 
			
		||||
        "fab_text_italic": false,
 | 
			
		||||
        "fab_text_size_h": 1.0,
 | 
			
		||||
        "fab_text_size_v": 1.0,
 | 
			
		||||
        "fab_text_thickness": 0.15,
 | 
			
		||||
        "fab_text_upright": false,
 | 
			
		||||
        "other_line_width": 0.09999999999999999,
 | 
			
		||||
        "other_text_italic": false,
 | 
			
		||||
        "other_text_size_h": 1.0,
 | 
			
		||||
        "other_text_size_v": 1.0,
 | 
			
		||||
        "other_text_thickness": 0.15,
 | 
			
		||||
        "other_text_upright": false,
 | 
			
		||||
        "pads": {
 | 
			
		||||
          "drill": 0.762,
 | 
			
		||||
          "height": 1.524,
 | 
			
		||||
          "width": 1.524
 | 
			
		||||
        },
 | 
			
		||||
        "silk_line_width": 0.12,
 | 
			
		||||
        "silk_text_italic": false,
 | 
			
		||||
        "silk_text_size_h": 1.0,
 | 
			
		||||
        "silk_text_size_v": 1.0,
 | 
			
		||||
        "silk_text_thickness": 0.15,
 | 
			
		||||
        "silk_text_upright": false,
 | 
			
		||||
        "zones": {
 | 
			
		||||
          "45_degree_only": false,
 | 
			
		||||
          "min_clearance": 0.19999999999999998
 | 
			
		||||
        }
 | 
			
		||||
      },
 | 
			
		||||
      "diff_pair_dimensions": [],
 | 
			
		||||
      "drc_exclusions": [],
 | 
			
		||||
      "meta": {
 | 
			
		||||
        "filename": "board_design_settings.json",
 | 
			
		||||
        "version": 2
 | 
			
		||||
      },
 | 
			
		||||
      "rule_severities": {
 | 
			
		||||
        "annular_width": "error",
 | 
			
		||||
        "clearance": "error",
 | 
			
		||||
        "copper_edge_clearance": "error",
 | 
			
		||||
        "courtyards_overlap": "error",
 | 
			
		||||
        "diff_pair_gap_out_of_range": "error",
 | 
			
		||||
        "diff_pair_uncoupled_length_too_long": "error",
 | 
			
		||||
        "drill_out_of_range": "error",
 | 
			
		||||
        "duplicate_footprints": "warning",
 | 
			
		||||
        "extra_footprint": "warning",
 | 
			
		||||
        "footprint_type_mismatch": "error",
 | 
			
		||||
        "hole_clearance": "error",
 | 
			
		||||
        "hole_near_hole": "error",
 | 
			
		||||
        "invalid_outline": "error",
 | 
			
		||||
        "item_on_disabled_layer": "error",
 | 
			
		||||
        "items_not_allowed": "error",
 | 
			
		||||
        "length_out_of_range": "error",
 | 
			
		||||
        "malformed_courtyard": "error",
 | 
			
		||||
        "microvia_drill_out_of_range": "error",
 | 
			
		||||
        "missing_courtyard": "ignore",
 | 
			
		||||
        "missing_footprint": "warning",
 | 
			
		||||
        "net_conflict": "warning",
 | 
			
		||||
        "npth_inside_courtyard": "ignore",
 | 
			
		||||
        "padstack": "error",
 | 
			
		||||
        "pth_inside_courtyard": "ignore",
 | 
			
		||||
        "shorting_items": "error",
 | 
			
		||||
        "silk_over_copper": "warning",
 | 
			
		||||
        "silk_overlap": "warning",
 | 
			
		||||
        "skew_out_of_range": "error",
 | 
			
		||||
        "through_hole_pad_without_hole": "error",
 | 
			
		||||
        "too_many_vias": "error",
 | 
			
		||||
        "track_dangling": "warning",
 | 
			
		||||
        "track_width": "error",
 | 
			
		||||
        "tracks_crossing": "error",
 | 
			
		||||
        "unconnected_items": "error",
 | 
			
		||||
        "unresolved_variable": "error",
 | 
			
		||||
        "via_dangling": "warning",
 | 
			
		||||
        "zone_has_empty_net": "error",
 | 
			
		||||
        "zones_intersect": "error"
 | 
			
		||||
      },
 | 
			
		||||
      "rule_severitieslegacy_courtyards_overlap": true,
 | 
			
		||||
      "rule_severitieslegacy_no_courtyard_defined": false,
 | 
			
		||||
      "rules": {
 | 
			
		||||
        "allow_blind_buried_vias": false,
 | 
			
		||||
        "allow_microvias": false,
 | 
			
		||||
        "max_error": 0.005,
 | 
			
		||||
        "min_clearance": 0.0,
 | 
			
		||||
        "min_copper_edge_clearance": 0.049999999999999996,
 | 
			
		||||
        "min_hole_clearance": 0.25,
 | 
			
		||||
        "min_hole_to_hole": 0.25,
 | 
			
		||||
        "min_microvia_diameter": 0.19999999999999998,
 | 
			
		||||
        "min_microvia_drill": 0.09999999999999999,
 | 
			
		||||
        "min_silk_clearance": 0.0,
 | 
			
		||||
        "min_through_hole_diameter": 0.3,
 | 
			
		||||
        "min_track_width": 0.19999999999999998,
 | 
			
		||||
        "min_via_annular_width": 0.049999999999999996,
 | 
			
		||||
        "min_via_diameter": 0.39999999999999997,
 | 
			
		||||
        "use_height_for_length_calcs": true
 | 
			
		||||
      },
 | 
			
		||||
      "track_widths": [
 | 
			
		||||
        0.0,
 | 
			
		||||
        0.5,
 | 
			
		||||
        1.0,
 | 
			
		||||
        2.0
 | 
			
		||||
      ],
 | 
			
		||||
      "via_dimensions": [
 | 
			
		||||
        {
 | 
			
		||||
          "diameter": 0.0,
 | 
			
		||||
          "drill": 0.0
 | 
			
		||||
        },
 | 
			
		||||
        {
 | 
			
		||||
          "diameter": 0.7,
 | 
			
		||||
          "drill": 0.35
 | 
			
		||||
        },
 | 
			
		||||
        {
 | 
			
		||||
          "diameter": 1.0,
 | 
			
		||||
          "drill": 0.6
 | 
			
		||||
        },
 | 
			
		||||
        {
 | 
			
		||||
          "diameter": 2.0,
 | 
			
		||||
          "drill": 1.0
 | 
			
		||||
        }
 | 
			
		||||
      ],
 | 
			
		||||
      "zones_allow_external_fillets": false,
 | 
			
		||||
      "zones_use_no_outline": true
 | 
			
		||||
    },
 | 
			
		||||
    "layer_presets": []
 | 
			
		||||
  },
 | 
			
		||||
  "boards": [],
 | 
			
		||||
  "cvpcb": {
 | 
			
		||||
    "equivalence_files": []
 | 
			
		||||
  },
 | 
			
		||||
  "erc": {
 | 
			
		||||
    "erc_exclusions": [],
 | 
			
		||||
    "meta": {
 | 
			
		||||
      "version": 0
 | 
			
		||||
    },
 | 
			
		||||
    "pin_map": [
 | 
			
		||||
      [
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        1,
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        2
 | 
			
		||||
      ],
 | 
			
		||||
      [
 | 
			
		||||
        0,
 | 
			
		||||
        2,
 | 
			
		||||
        0,
 | 
			
		||||
        1,
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        1,
 | 
			
		||||
        0,
 | 
			
		||||
        2,
 | 
			
		||||
        2,
 | 
			
		||||
        2,
 | 
			
		||||
        2
 | 
			
		||||
      ],
 | 
			
		||||
      [
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        1,
 | 
			
		||||
        0,
 | 
			
		||||
        1,
 | 
			
		||||
        0,
 | 
			
		||||
        1,
 | 
			
		||||
        2
 | 
			
		||||
      ],
 | 
			
		||||
      [
 | 
			
		||||
        0,
 | 
			
		||||
        1,
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        1,
 | 
			
		||||
        1,
 | 
			
		||||
        2,
 | 
			
		||||
        1,
 | 
			
		||||
        1,
 | 
			
		||||
        2
 | 
			
		||||
      ],
 | 
			
		||||
      [
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        1,
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        2
 | 
			
		||||
      ],
 | 
			
		||||
      [
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        2
 | 
			
		||||
      ],
 | 
			
		||||
      [
 | 
			
		||||
        1,
 | 
			
		||||
        1,
 | 
			
		||||
        1,
 | 
			
		||||
        1,
 | 
			
		||||
        1,
 | 
			
		||||
        0,
 | 
			
		||||
        1,
 | 
			
		||||
        1,
 | 
			
		||||
        1,
 | 
			
		||||
        1,
 | 
			
		||||
        1,
 | 
			
		||||
        2
 | 
			
		||||
      ],
 | 
			
		||||
      [
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        1,
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        1,
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        2
 | 
			
		||||
      ],
 | 
			
		||||
      [
 | 
			
		||||
        0,
 | 
			
		||||
        2,
 | 
			
		||||
        1,
 | 
			
		||||
        2,
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        1,
 | 
			
		||||
        0,
 | 
			
		||||
        2,
 | 
			
		||||
        2,
 | 
			
		||||
        2,
 | 
			
		||||
        2
 | 
			
		||||
      ],
 | 
			
		||||
      [
 | 
			
		||||
        0,
 | 
			
		||||
        2,
 | 
			
		||||
        0,
 | 
			
		||||
        1,
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        1,
 | 
			
		||||
        0,
 | 
			
		||||
        2,
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        2
 | 
			
		||||
      ],
 | 
			
		||||
      [
 | 
			
		||||
        0,
 | 
			
		||||
        2,
 | 
			
		||||
        1,
 | 
			
		||||
        1,
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        1,
 | 
			
		||||
        0,
 | 
			
		||||
        2,
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        2
 | 
			
		||||
      ],
 | 
			
		||||
      [
 | 
			
		||||
        2,
 | 
			
		||||
        2,
 | 
			
		||||
        2,
 | 
			
		||||
        2,
 | 
			
		||||
        2,
 | 
			
		||||
        2,
 | 
			
		||||
        2,
 | 
			
		||||
        2,
 | 
			
		||||
        2,
 | 
			
		||||
        2,
 | 
			
		||||
        2,
 | 
			
		||||
        2
 | 
			
		||||
      ]
 | 
			
		||||
    ],
 | 
			
		||||
    "rule_severities": {
 | 
			
		||||
      "bus_definition_conflict": "error",
 | 
			
		||||
      "bus_entry_needed": "error",
 | 
			
		||||
      "bus_label_syntax": "error",
 | 
			
		||||
      "bus_to_bus_conflict": "error",
 | 
			
		||||
      "bus_to_net_conflict": "error",
 | 
			
		||||
      "different_unit_footprint": "error",
 | 
			
		||||
      "different_unit_net": "error",
 | 
			
		||||
      "duplicate_reference": "error",
 | 
			
		||||
      "duplicate_sheet_names": "error",
 | 
			
		||||
      "extra_units": "error",
 | 
			
		||||
      "global_label_dangling": "warning",
 | 
			
		||||
      "hier_label_mismatch": "error",
 | 
			
		||||
      "label_dangling": "error",
 | 
			
		||||
      "lib_symbol_issues": "warning",
 | 
			
		||||
      "multiple_net_names": "warning",
 | 
			
		||||
      "net_not_bus_member": "warning",
 | 
			
		||||
      "no_connect_connected": "warning",
 | 
			
		||||
      "no_connect_dangling": "warning",
 | 
			
		||||
      "pin_not_connected": "error",
 | 
			
		||||
      "pin_not_driven": "error",
 | 
			
		||||
      "pin_to_pin": "warning",
 | 
			
		||||
      "power_pin_not_driven": "error",
 | 
			
		||||
      "similar_labels": "warning",
 | 
			
		||||
      "unannotated": "error",
 | 
			
		||||
      "unit_value_mismatch": "error",
 | 
			
		||||
      "unresolved_variable": "error",
 | 
			
		||||
      "wire_dangling": "error"
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  "libraries": {
 | 
			
		||||
    "pinned_footprint_libs": [],
 | 
			
		||||
    "pinned_symbol_libs": []
 | 
			
		||||
  },
 | 
			
		||||
  "meta": {
 | 
			
		||||
    "filename": "oiler SMD.kicad_pro",
 | 
			
		||||
    "version": 1
 | 
			
		||||
  },
 | 
			
		||||
  "net_settings": {
 | 
			
		||||
    "classes": [
 | 
			
		||||
      {
 | 
			
		||||
        "bus_width": 12.0,
 | 
			
		||||
        "clearance": 0.2,
 | 
			
		||||
        "diff_pair_gap": 0.25,
 | 
			
		||||
        "diff_pair_via_gap": 0.25,
 | 
			
		||||
        "diff_pair_width": 0.2,
 | 
			
		||||
        "line_style": 0,
 | 
			
		||||
        "microvia_diameter": 0.3,
 | 
			
		||||
        "microvia_drill": 0.1,
 | 
			
		||||
        "name": "Default",
 | 
			
		||||
        "pcb_color": "rgba(0, 0, 0, 0.000)",
 | 
			
		||||
        "schematic_color": "rgba(0, 0, 0, 0.000)",
 | 
			
		||||
        "track_width": 0.25,
 | 
			
		||||
        "via_diameter": 0.8,
 | 
			
		||||
        "via_drill": 0.4,
 | 
			
		||||
        "wire_width": 6.0
 | 
			
		||||
      }
 | 
			
		||||
    ],
 | 
			
		||||
    "meta": {
 | 
			
		||||
      "version": 2
 | 
			
		||||
    },
 | 
			
		||||
    "net_colors": null
 | 
			
		||||
  },
 | 
			
		||||
  "pcbnew": {
 | 
			
		||||
    "last_paths": {
 | 
			
		||||
      "gencad": "",
 | 
			
		||||
      "idf": "",
 | 
			
		||||
      "netlist": "Rehoiler SMD.net",
 | 
			
		||||
      "specctra_dsn": "",
 | 
			
		||||
      "step": "",
 | 
			
		||||
      "vrml": ""
 | 
			
		||||
    },
 | 
			
		||||
    "page_layout_descr_file": ""
 | 
			
		||||
  },
 | 
			
		||||
  "schematic": {
 | 
			
		||||
    "annotate_start_num": 0,
 | 
			
		||||
    "drawing": {
 | 
			
		||||
      "default_line_thickness": 6.0,
 | 
			
		||||
      "default_text_size": 50.0,
 | 
			
		||||
      "field_names": [],
 | 
			
		||||
      "intersheets_ref_own_page": false,
 | 
			
		||||
      "intersheets_ref_prefix": "",
 | 
			
		||||
      "intersheets_ref_short": false,
 | 
			
		||||
      "intersheets_ref_show": false,
 | 
			
		||||
      "intersheets_ref_suffix": "",
 | 
			
		||||
      "junction_size_choice": 3,
 | 
			
		||||
      "label_size_ratio": 0.25,
 | 
			
		||||
      "pin_symbol_size": 25.0,
 | 
			
		||||
      "text_offset_ratio": 0.08
 | 
			
		||||
    },
 | 
			
		||||
    "legacy_lib_dir": "",
 | 
			
		||||
    "legacy_lib_list": [],
 | 
			
		||||
    "meta": {
 | 
			
		||||
      "version": 1
 | 
			
		||||
    },
 | 
			
		||||
    "net_format_name": "Pcbnew",
 | 
			
		||||
    "ngspice": {
 | 
			
		||||
      "fix_include_paths": true,
 | 
			
		||||
      "fix_passive_vals": false,
 | 
			
		||||
      "meta": {
 | 
			
		||||
        "version": 0
 | 
			
		||||
      },
 | 
			
		||||
      "model_mode": 0,
 | 
			
		||||
      "workbook_filename": ""
 | 
			
		||||
    },
 | 
			
		||||
    "page_layout_descr_file": "",
 | 
			
		||||
    "plot_directory": "",
 | 
			
		||||
    "spice_adjust_passive_values": false,
 | 
			
		||||
    "spice_external_command": "spice \"%I\"",
 | 
			
		||||
    "subpart_first_id": 65,
 | 
			
		||||
    "subpart_id_separator": 0
 | 
			
		||||
  },
 | 
			
		||||
  "sheets": [
 | 
			
		||||
    [
 | 
			
		||||
      "b1ddb058-f7b2-429c-9489-f4e2242ad7e5",
 | 
			
		||||
      ""
 | 
			
		||||
    ]
 | 
			
		||||
  ],
 | 
			
		||||
  "text_variables": {}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										3585
									
								
								Hardware/oiler SMD.kicad_sch
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -3,5 +3,8 @@
 | 
			
		||||
    // for the documentation about the extensions.json format
 | 
			
		||||
    "recommendations": [
 | 
			
		||||
        "platformio.platformio-ide"
 | 
			
		||||
    ],
 | 
			
		||||
    "unwantedRecommendations": [
 | 
			
		||||
        "ms-vscode.cpptools-extension-pack"
 | 
			
		||||
    ]
 | 
			
		||||
}
 | 
			
		||||
@@ -1,44 +0,0 @@
 | 
			
		||||
#include <Arduino.h>
 | 
			
		||||
#include "config.h"
 | 
			
		||||
 | 
			
		||||
LubeConfig_t LubeConfig;
 | 
			
		||||
 | 
			
		||||
void StoreConfig_EEPROM()
 | 
			
		||||
{
 | 
			
		||||
  LubeConfig.checksum = 0;
 | 
			
		||||
  LubeConfig.checksum = Checksum_EEPROM((uint8_t *)&LubeConfig, sizeof(LubeConfig));
 | 
			
		||||
 | 
			
		||||
  EEPROM.begin(512);
 | 
			
		||||
  EEPROM.put(0, LubeConfig);
 | 
			
		||||
  EEPROM.commit();
 | 
			
		||||
  EEPROM.end();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void GetConfig_EEPROM()
 | 
			
		||||
{
 | 
			
		||||
  EEPROM.begin(512);
 | 
			
		||||
  EEPROM.get(0, LubeConfig);
 | 
			
		||||
  EEPROM.end();
 | 
			
		||||
 | 
			
		||||
  uint32_t checksum = LubeConfig.checksum;
 | 
			
		||||
  LubeConfig.checksum = 0;
 | 
			
		||||
 | 
			
		||||
  if (Checksum_EEPROM((uint8_t *)&LubeConfig, sizeof(LubeConfig)) == checksum)
 | 
			
		||||
    Serial.printf("Checksum OK");
 | 
			
		||||
  else
 | 
			
		||||
    Serial.printf("Checksum BAD");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint32_t Checksum_EEPROM(uint8_t const *data, size_t len)
 | 
			
		||||
{
 | 
			
		||||
  if (data == NULL)
 | 
			
		||||
    return 0;
 | 
			
		||||
  uint32_t crc = 0;
 | 
			
		||||
  while (len--)
 | 
			
		||||
  {
 | 
			
		||||
    crc ^= *data++;
 | 
			
		||||
    for (uint8_t k = 0; k < 8; k++)
 | 
			
		||||
      crc = crc & 1 ? (crc >> 1) ^ 0xb2 : crc >> 1;
 | 
			
		||||
  }
 | 
			
		||||
  return crc ^ 0xff;
 | 
			
		||||
}
 | 
			
		||||
@@ -1,29 +0,0 @@
 | 
			
		||||
#ifndef _CONFIG_H_
 | 
			
		||||
#define _CONFIG_H_
 | 
			
		||||
 | 
			
		||||
#include <Arduino.h>
 | 
			
		||||
#include <EEPROM.h>
 | 
			
		||||
 | 
			
		||||
typedef struct
 | 
			
		||||
{
 | 
			
		||||
  uint32_t DistancePerLube_Default = 0;
 | 
			
		||||
  uint32_t DistancePerLube_Rain = 0;
 | 
			
		||||
  uint32_t tankCapacity_ml = 320;
 | 
			
		||||
  uint32_t amountPerDose_µl = 0;
 | 
			
		||||
  uint32_t tankRemain_µl = 0;
 | 
			
		||||
  uint8_t TankRemindAtPercentage = 30;
 | 
			
		||||
  uint8_t PulsePerRevolution = 1;
 | 
			
		||||
  uint32_t TireWidth_mm = 150;
 | 
			
		||||
  uint32_t TireWidthHeight_Ratio = 70;
 | 
			
		||||
  uint32_t RimDiameter_Inch = 18;
 | 
			
		||||
  uint32_t DistancePerRevolution_mm = 2000;
 | 
			
		||||
  uint32_t checksum = 0;
 | 
			
		||||
} LubeConfig_t;
 | 
			
		||||
 | 
			
		||||
void StoreConfig_EEPROM();
 | 
			
		||||
void GetConfig_EEPROM();
 | 
			
		||||
uint32_t Checksum_EEPROM(uint8_t const *data, size_t len);
 | 
			
		||||
 | 
			
		||||
extern LubeConfig_t LubeConfig;
 | 
			
		||||
 | 
			
		||||
#endif // _CONFIG_H_
 | 
			
		||||
@@ -1,25 +0,0 @@
 | 
			
		||||
#ifndef _GLOBALS_H_
 | 
			
		||||
#define _GLOBALS_H_
 | 
			
		||||
 | 
			
		||||
#include <Arduino.h>
 | 
			
		||||
 | 
			
		||||
typedef enum eSystem_Status
 | 
			
		||||
{
 | 
			
		||||
  sysStat_NOP,
 | 
			
		||||
  sysStat_Startup,
 | 
			
		||||
  sysStat_Normal,
 | 
			
		||||
  sysStat_Rain,
 | 
			
		||||
  sysStat_Purge,
 | 
			
		||||
  sysStat_Error
 | 
			
		||||
} tSystem_Status;
 | 
			
		||||
 | 
			
		||||
typedef struct Globals_t {
 | 
			
		||||
  tSystem_Status systemStatus = sysStat_Startup;
 | 
			
		||||
  uint8_t purgePulses= 0;
 | 
			
		||||
  tSystem_Status resumeStatus = sysStat_Startup;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
extern Globals_t globals;
 | 
			
		||||
extern uint32_t TravelDistance_highRes;
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
@@ -1,65 +0,0 @@
 | 
			
		||||
#include "lubeapp.h"
 | 
			
		||||
 | 
			
		||||
extern void LED_Process(tSystem_Status newStatus = sysStat_NOP);
 | 
			
		||||
 | 
			
		||||
uint32_t lubePulseTimestamp = 0;
 | 
			
		||||
 | 
			
		||||
void RunLubeApp(volatile uint32_t *wheelPulseCounter)
 | 
			
		||||
{
 | 
			
		||||
    uint32_t LubeDistance = 0;
 | 
			
		||||
 | 
			
		||||
    // Calculate traveled Distance in mm
 | 
			
		||||
    TravelDistance_highRes += (*wheelPulseCounter * (LubeConfig.DistancePerRevolution_mm / LubeConfig.PulsePerRevolution));
 | 
			
		||||
    *wheelPulseCounter = 0;
 | 
			
		||||
 | 
			
		||||
    // check if we have to Lube!
 | 
			
		||||
    switch (globals.systemStatus)
 | 
			
		||||
    {
 | 
			
		||||
    case sysStat_Startup:
 | 
			
		||||
        globals.systemStatus = sysStat_Normal;
 | 
			
		||||
        globals.resumeStatus = sysStat_Normal;
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case sysStat_Normal:
 | 
			
		||||
        if (TravelDistance_highRes / 1000 > LubeConfig.DistancePerLube_Default)
 | 
			
		||||
        {
 | 
			
		||||
            LubePulse();
 | 
			
		||||
            TravelDistance_highRes = 0;
 | 
			
		||||
        }
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case sysStat_Rain:
 | 
			
		||||
        if (TravelDistance_highRes / 1000 > LubeConfig.DistancePerLube_Rain)
 | 
			
		||||
        {
 | 
			
		||||
            LubePulse();
 | 
			
		||||
            TravelDistance_highRes = 0;
 | 
			
		||||
        }
 | 
			
		||||
        break;
 | 
			
		||||
    case sysStat_Purge:
 | 
			
		||||
        if (globals.purgePulses > 0)
 | 
			
		||||
        {
 | 
			
		||||
            if (lubePulseTimestamp + LUBE_PULSE_LENGHT_MS + LUBE_PULSE_PAUSE_MS < millis())
 | 
			
		||||
            {
 | 
			
		||||
                LubePulse();
 | 
			
		||||
                globals.purgePulses--;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            globals.systemStatus = globals.resumeStatus;
 | 
			
		||||
        }
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // maintain Pin-State of Lube-Pump
 | 
			
		||||
    if (lubePulseTimestamp > millis())
 | 
			
		||||
        digitalWrite(GPIO_PUMP, HIGH);
 | 
			
		||||
    else
 | 
			
		||||
        digitalWrite(GPIO_PUMP, LOW);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void LubePulse()
 | 
			
		||||
{
 | 
			
		||||
    lubePulseTimestamp = millis() + LUBE_PULSE_LENGHT_MS;
 | 
			
		||||
    LubeConfig.tankRemain_µl = LubeConfig.tankRemain_µl - LubeConfig.amountPerDose_µl;
 | 
			
		||||
}
 | 
			
		||||
@@ -1,15 +0,0 @@
 | 
			
		||||
#ifndef _LUBEAPP_H_
 | 
			
		||||
#define _LUBEAPP_H_
 | 
			
		||||
 | 
			
		||||
#include <Arduino.h>
 | 
			
		||||
#include "config.h"
 | 
			
		||||
#include "common.h"
 | 
			
		||||
#include "globals.h"
 | 
			
		||||
 | 
			
		||||
#define LUBE_PULSE_LENGHT_MS 250
 | 
			
		||||
#define LUBE_PULSE_PAUSE_MS 250
 | 
			
		||||
 | 
			
		||||
void RunLubeApp(volatile uint32_t * wheelPulseCounter);
 | 
			
		||||
void LubePulse();
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
@@ -1,342 +0,0 @@
 | 
			
		||||
#include <Arduino.h>
 | 
			
		||||
#include <Wire.h>
 | 
			
		||||
#include <U8g2lib.h>
 | 
			
		||||
#include <ESP8266WiFi.h>
 | 
			
		||||
#include <ESP8266WiFiMulti.h>
 | 
			
		||||
#include <ESP8266mDNS.h>
 | 
			
		||||
#include <ArduinoOTA.h>
 | 
			
		||||
#include <RemoteDebug.h>
 | 
			
		||||
#include <FastLED.h>
 | 
			
		||||
#include <Ticker.h>
 | 
			
		||||
 | 
			
		||||
#include "common.h"
 | 
			
		||||
#include "rmtdbghelp.h"
 | 
			
		||||
#include "lubeapp.h"
 | 
			
		||||
#include "webui.h"
 | 
			
		||||
#include "config.h"
 | 
			
		||||
#include "globals.h"
 | 
			
		||||
 | 
			
		||||
const char *ssid = QUOTE(WIFI_SSID);
 | 
			
		||||
const char *password = QUOTE(WIFI_PASSWORD);
 | 
			
		||||
 | 
			
		||||
const uint32_t connectTimeoutMs = 5000;
 | 
			
		||||
 | 
			
		||||
#ifdef DEBUG
 | 
			
		||||
const bool debug_flag = true;
 | 
			
		||||
#else
 | 
			
		||||
const bool debug_flag = false;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
bool startSetupMode = false;
 | 
			
		||||
char DeviceName[33];
 | 
			
		||||
 | 
			
		||||
Globals_t globals;
 | 
			
		||||
uint32_t TravelDistance_highRes;
 | 
			
		||||
volatile uint32_t wheel_pulse = 0;
 | 
			
		||||
 | 
			
		||||
U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(-1);
 | 
			
		||||
RemoteDebug Debug;
 | 
			
		||||
ESP8266WiFiMulti wifiMulti;
 | 
			
		||||
CRGB leds[1];
 | 
			
		||||
 | 
			
		||||
// Function-Prototypes
 | 
			
		||||
String IpAddress2String(const IPAddress &ipAddress);
 | 
			
		||||
void processCmdRemoteDebug();
 | 
			
		||||
void RemotDebug_printSystemInfo();
 | 
			
		||||
void RemoteDebug_printWifiInfo();
 | 
			
		||||
void wifiMaintainConnectionTicker_callback();
 | 
			
		||||
void IRAM_ATTR trigger_ISR();
 | 
			
		||||
void LED_Process(tSystem_Status newStatus = sysStat_NOP);
 | 
			
		||||
void DisplayProcess();
 | 
			
		||||
 | 
			
		||||
Ticker WiFiMaintainConnectionTicker(wifiMaintainConnectionTicker_callback, 1000, 0, MILLIS);
 | 
			
		||||
 | 
			
		||||
void setup()
 | 
			
		||||
{
 | 
			
		||||
  system_update_cpu_freq(SYS_CPU_80MHZ);
 | 
			
		||||
 | 
			
		||||
  snprintf(DeviceName, 32, HOST_NAME, ESP.getChipId());
 | 
			
		||||
 | 
			
		||||
  WiFi.mode(WIFI_OFF);
 | 
			
		||||
  WiFi.persistent(false);
 | 
			
		||||
 | 
			
		||||
  Serial.begin(115200);
 | 
			
		||||
  Serial.setDebugOutput(true);
 | 
			
		||||
 | 
			
		||||
  Serial.println("Souko's ChainLube Mk1");
 | 
			
		||||
  Serial.println(DeviceName);
 | 
			
		||||
 | 
			
		||||
  GetConfig_EEPROM();
 | 
			
		||||
 | 
			
		||||
  u8x8.begin();
 | 
			
		||||
  u8x8.setFont(u8x8_font_chroma48medium8_r);
 | 
			
		||||
 | 
			
		||||
  FastLED.addLeds<WS2811, GPIO_LED, GRB>(leds, 1); // GRB ordering is assumed
 | 
			
		||||
 | 
			
		||||
  pinMode(GPIO_TRIGGER, INPUT_PULLUP);
 | 
			
		||||
  pinMode(GPIO_BUTTON, INPUT_PULLUP);
 | 
			
		||||
  pinMode(GPIO_PUMP, OUTPUT);
 | 
			
		||||
 | 
			
		||||
  attachInterrupt(digitalPinToInterrupt(GPIO_TRIGGER), trigger_ISR, FALLING);
 | 
			
		||||
 | 
			
		||||
  WiFi.mode(WIFI_STA);
 | 
			
		||||
  WiFi.setHostname(DeviceName);
 | 
			
		||||
  wifiMulti.addAP(QUOTE(WIFI_SSID), QUOTE(WIFI_PASSWORD));
 | 
			
		||||
 | 
			
		||||
  WiFiMaintainConnectionTicker.start();
 | 
			
		||||
 | 
			
		||||
  if (MDNS.begin(DeviceName))
 | 
			
		||||
    MDNS.addService("telnet", "tcp", 23);
 | 
			
		||||
 | 
			
		||||
  Debug.begin(DeviceName);        // Initialize the WiFi server
 | 
			
		||||
  Debug.setResetCmdEnabled(true); // Enable the reset command
 | 
			
		||||
  Debug.showProfiler(true);       // Profiler (Good to measure times, to optimize codes)
 | 
			
		||||
  Debug.showColors(true);         // Colors
 | 
			
		||||
  Debug.setPassword(QUOTE(ADMIN_PASSWORD));
 | 
			
		||||
 | 
			
		||||
  Debug.setHelpProjectsCmds(helpCmd);
 | 
			
		||||
  Debug.setCallBackProjectCmds(&processCmdRemoteDebug);
 | 
			
		||||
 | 
			
		||||
  ArduinoOTA.setPort(8266);
 | 
			
		||||
  ArduinoOTA.setHostname(DeviceName);
 | 
			
		||||
  ArduinoOTA.setPassword(QUOTE(ADMIN_PASSWORD));
 | 
			
		||||
 | 
			
		||||
  ArduinoOTA.onStart([]()
 | 
			
		||||
                     {
 | 
			
		||||
                       u8x8.clearDisplay();
 | 
			
		||||
                       u8x8.drawString(0, 0, "OTA-Update");
 | 
			
		||||
                       u8x8.refreshDisplay(); });
 | 
			
		||||
 | 
			
		||||
  ArduinoOTA.onProgress([](unsigned int progress, unsigned int total)
 | 
			
		||||
                        {
 | 
			
		||||
                          static bool refreshed = false;
 | 
			
		||||
                          if (!refreshed)
 | 
			
		||||
                          {
 | 
			
		||||
                            u8x8.clearDisplay();
 | 
			
		||||
                            refreshed = true;
 | 
			
		||||
                            u8x8.drawString(0, 0, "OTA Upload");
 | 
			
		||||
                          }
 | 
			
		||||
                          uint32_t percent = progress / (total / 100);
 | 
			
		||||
                          u8x8.setCursor(0, 1);
 | 
			
		||||
                          u8x8.printf("%d %%", percent);
 | 
			
		||||
                          u8x8.refreshDisplay(); });
 | 
			
		||||
 | 
			
		||||
  ArduinoOTA.onEnd([]()
 | 
			
		||||
                   {
 | 
			
		||||
                     u8x8.clearDisplay();
 | 
			
		||||
                     u8x8.drawString(0, 0, "OTA-Restart");
 | 
			
		||||
                     u8x8.refreshDisplay(); });
 | 
			
		||||
 | 
			
		||||
  ArduinoOTA.begin();
 | 
			
		||||
 | 
			
		||||
  u8x8.clearDisplay();
 | 
			
		||||
  u8x8.drawString(4, 0, "Souko's");
 | 
			
		||||
  u8x8.drawString(1, 1, "ChainLube Mk1");
 | 
			
		||||
  u8x8.refreshDisplay();
 | 
			
		||||
 | 
			
		||||
  initWebUI();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void loop()
 | 
			
		||||
{
 | 
			
		||||
  LED_Process(globals.systemStatus);
 | 
			
		||||
  RunLubeApp(&wheel_pulse);
 | 
			
		||||
 | 
			
		||||
  WiFiMaintainConnectionTicker.update();
 | 
			
		||||
 | 
			
		||||
  DisplayProcess();
 | 
			
		||||
 | 
			
		||||
  ArduinoOTA.handle();
 | 
			
		||||
  Debug.handle();
 | 
			
		||||
  yield();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
String IpAddress2String(const IPAddress &ipAddress)
 | 
			
		||||
{
 | 
			
		||||
  return String(ipAddress[0]) + String(".") +
 | 
			
		||||
         String(ipAddress[1]) + String(".") +
 | 
			
		||||
         String(ipAddress[2]) + String(".") +
 | 
			
		||||
         String(ipAddress[3]);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void processCmdRemoteDebug()
 | 
			
		||||
{
 | 
			
		||||
  String lastCmd = Debug.getLastCommand();
 | 
			
		||||
 | 
			
		||||
  if (lastCmd == "sysinfo")
 | 
			
		||||
    RemotDebug_printSystemInfo();
 | 
			
		||||
  else if (lastCmd == "netinfo")
 | 
			
		||||
    RemoteDebug_printWifiInfo();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void RemotDebug_printSystemInfo()
 | 
			
		||||
{
 | 
			
		||||
  debugA("Souko's ChainOiler Mk1");
 | 
			
		||||
  debugA("Hostname: %s", DeviceName);
 | 
			
		||||
 | 
			
		||||
  FlashMode_t ideMode = ESP.getFlashChipMode();
 | 
			
		||||
  debugA("Sdk version: %s", ESP.getSdkVersion());
 | 
			
		||||
  debugA("Core Version: %s", ESP.getCoreVersion().c_str());
 | 
			
		||||
  debugA("Boot Version: %u", ESP.getBootVersion());
 | 
			
		||||
  debugA("Boot Mode: %u", ESP.getBootMode());
 | 
			
		||||
  debugA("CPU Frequency: %u MHz", ESP.getCpuFreqMHz());
 | 
			
		||||
  debugA("Reset reason: %s", ESP.getResetReason().c_str());
 | 
			
		||||
  debugA("Flash Size: %d", ESP.getFlashChipRealSize());
 | 
			
		||||
  debugA("Flash Size IDE: %d", ESP.getFlashChipSize());
 | 
			
		||||
  debugA("Flash ide mode:  %s", (ideMode == FM_QIO ? "QIO" : ideMode == FM_QOUT ? "QOUT"
 | 
			
		||||
                                                         : ideMode == FM_DIO    ? "DIO"
 | 
			
		||||
                                                         : ideMode == FM_DOUT   ? "DOUT"
 | 
			
		||||
                                                                                : "UNKNOWN"));
 | 
			
		||||
  debugA("OTA-Pass: %s", QUOTE(ADMIN_PASSWORD));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void RemoteDebug_printWifiInfo()
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void wifiMaintainConnectionTicker_callback()
 | 
			
		||||
{
 | 
			
		||||
  static uint32_t WiFiFailCount = 0;
 | 
			
		||||
  const uint32_t WiFiFailMax = 20;
 | 
			
		||||
 | 
			
		||||
  if (wifiMulti.run(connectTimeoutMs) == WL_CONNECTED)
 | 
			
		||||
  {
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    if (WiFiFailCount < WiFiFailMax)
 | 
			
		||||
    {
 | 
			
		||||
      WiFiFailCount++;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
      Serial.println("WiFi not connected! - Start AP");
 | 
			
		||||
      WiFi.mode(WIFI_OFF);
 | 
			
		||||
      WiFi.softAP(DeviceName, QUOTE(WIFI_AP_PASSWORD));
 | 
			
		||||
      WiFiMaintainConnectionTicker.stop();
 | 
			
		||||
      Serial.println("WiFi AP started, stopped Maintain-Timer");
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void trigger_ISR()
 | 
			
		||||
{
 | 
			
		||||
  wheel_pulse++;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void LED_Process(tSystem_Status newSysStatus)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
  typedef enum
 | 
			
		||||
  {
 | 
			
		||||
    LED_Startup,
 | 
			
		||||
    LED_Normal,
 | 
			
		||||
    LED_Confirm_Normal,
 | 
			
		||||
    LED_Rain,
 | 
			
		||||
    LED_Confirm_Rain,
 | 
			
		||||
    LED_Purge,
 | 
			
		||||
    LED_Error
 | 
			
		||||
  } tLED_Status;
 | 
			
		||||
 | 
			
		||||
  static tSystem_Status oldSysStatus = sysStat_NOP;
 | 
			
		||||
  static tLED_Status LED_Status = LED_Startup;
 | 
			
		||||
 | 
			
		||||
  uint8_t color = 0;
 | 
			
		||||
  uint32_t timer = 0;
 | 
			
		||||
  uint32_t timestamp = 0;
 | 
			
		||||
 | 
			
		||||
  if (oldSysStatus != newSysStatus)
 | 
			
		||||
  {
 | 
			
		||||
    switch (newSysStatus)
 | 
			
		||||
    {
 | 
			
		||||
    case sysStat_Startup:
 | 
			
		||||
      LED_Status = LED_Startup;
 | 
			
		||||
      break;
 | 
			
		||||
    case sysStat_Normal:
 | 
			
		||||
      timestamp = millis() + 1500;
 | 
			
		||||
      LED_Status = LED_Confirm_Normal;
 | 
			
		||||
      break;
 | 
			
		||||
    case sysStat_Rain:
 | 
			
		||||
      timestamp = millis() + 1500;
 | 
			
		||||
      LED_Status = LED_Confirm_Rain;
 | 
			
		||||
      break;
 | 
			
		||||
    case sysStat_Purge:
 | 
			
		||||
      LED_Status = LED_Purge;
 | 
			
		||||
      break;
 | 
			
		||||
    case sysStat_Error:
 | 
			
		||||
      LED_Status = LED_Error;
 | 
			
		||||
      break;
 | 
			
		||||
    }
 | 
			
		||||
    oldSysStatus = newSysStatus;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  timer = millis();
 | 
			
		||||
 | 
			
		||||
  switch (LED_Status)
 | 
			
		||||
  {
 | 
			
		||||
  case LED_Startup:
 | 
			
		||||
    FastLED.setBrightness(255);
 | 
			
		||||
    timer = timer % 2000;
 | 
			
		||||
    color = timer > 500 ? 0 : (uint8_t)(timer / 2);
 | 
			
		||||
    leds[0] = CRGB(color, color, color);
 | 
			
		||||
    break;
 | 
			
		||||
 | 
			
		||||
  case LED_Confirm_Normal:
 | 
			
		||||
    FastLED.setBrightness(255);
 | 
			
		||||
    leds[0] = timer % 500 > 250 ? CRGB(0, 255, 0) : CRGB(0, 4, 0);
 | 
			
		||||
    if (timestamp < timer)
 | 
			
		||||
    {
 | 
			
		||||
      LED_Status = LED_Normal;
 | 
			
		||||
      FastLED.setBrightness(64);
 | 
			
		||||
    }
 | 
			
		||||
    break;
 | 
			
		||||
 | 
			
		||||
  case LED_Normal:
 | 
			
		||||
    leds[0] = timer % 2000 > 1950 ? CRGB(0, 255, 0) : CRGB(0, 4, 0);
 | 
			
		||||
    break;
 | 
			
		||||
 | 
			
		||||
  case LED_Confirm_Rain:
 | 
			
		||||
    FastLED.setBrightness(255);
 | 
			
		||||
    leds[0] = timer % 500 > 250 ? CRGB(0, 0, 255) : CRGB(0, 0, 4);
 | 
			
		||||
    if (timestamp < timer)
 | 
			
		||||
    {
 | 
			
		||||
      LED_Status = LED_Rain;
 | 
			
		||||
      FastLED.setBrightness(64);
 | 
			
		||||
    }
 | 
			
		||||
    break;
 | 
			
		||||
 | 
			
		||||
  case LED_Rain:
 | 
			
		||||
    leds[0] = timer % 2000 > 1950 ? CRGB(0, 0, 255) : CRGB(0, 0, 4);
 | 
			
		||||
    break;
 | 
			
		||||
 | 
			
		||||
  case LED_Purge:
 | 
			
		||||
    timer = timer % 500;
 | 
			
		||||
    color = timer / 2;
 | 
			
		||||
    leds[0] = CRGB::DeepPink;
 | 
			
		||||
    if (timer < 250)
 | 
			
		||||
      FastLED.setBrightness(color);
 | 
			
		||||
    else
 | 
			
		||||
      FastLED.setBrightness(250 - color);
 | 
			
		||||
    break;
 | 
			
		||||
 | 
			
		||||
  case LED_Error:
 | 
			
		||||
    leds[0] = timer % 500 > 250 ? CRGB::Red : CRGB::Black;
 | 
			
		||||
    break;
 | 
			
		||||
 | 
			
		||||
  default:
 | 
			
		||||
    break;
 | 
			
		||||
  }
 | 
			
		||||
  FastLED.show();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void DisplayProcess()
 | 
			
		||||
{
 | 
			
		||||
  u8x8.setCursor(0, 3);
 | 
			
		||||
  uint32_t DistRemain = globals.systemStatus == sysStat_Normal ? LubeConfig.DistancePerLube_Default : LubeConfig.DistancePerLube_Rain;
 | 
			
		||||
  DistRemain -= TravelDistance_highRes / 1000;
 | 
			
		||||
  u8x8.printf("next Lube: %4dm\n", DistRemain);
 | 
			
		||||
  u8x8.printf("Tank: %8dml\n", LubeConfig.tankRemain_µl / 1000);
 | 
			
		||||
  u8x8.printf("Purges: %8d\n", globals.purgePulses);
 | 
			
		||||
  u8x8.refreshDisplay();
 | 
			
		||||
}
 | 
			
		||||
@@ -1,2 +0,0 @@
 | 
			
		||||
const char helpCmd[] = "sysinfo    - System Info\r\n"
 | 
			
		||||
                       "netinfo    - WiFi Info\r\n";
 | 
			
		||||
@@ -1,131 +0,0 @@
 | 
			
		||||
#include "webui.h"
 | 
			
		||||
 | 
			
		||||
uint16_t tab_lube;
 | 
			
		||||
uint16_t tab_wheel;
 | 
			
		||||
uint16_t tab_tank;
 | 
			
		||||
uint16_t tab_maintenance;
 | 
			
		||||
uint16_t tab_store;
 | 
			
		||||
 | 
			
		||||
uint16_t num_lubedist_normal;
 | 
			
		||||
uint16_t num_lubedist_rain;
 | 
			
		||||
uint16_t button_lubedist;
 | 
			
		||||
 | 
			
		||||
uint16_t num_wheel_width;
 | 
			
		||||
uint16_t num_wheel_ratio;
 | 
			
		||||
uint16_t num_wheel_rim;
 | 
			
		||||
uint16_t button_wheelcalc;
 | 
			
		||||
uint16_t num_wheel_ppr;
 | 
			
		||||
uint16_t num_wheel_dist;
 | 
			
		||||
 | 
			
		||||
uint16_t num_tank_capacity;
 | 
			
		||||
uint16_t num_tank_notify;
 | 
			
		||||
uint16_t num_dose_per_pulse;
 | 
			
		||||
 | 
			
		||||
uint16_t label_tankRemain;
 | 
			
		||||
uint16_t button_reset_tank;
 | 
			
		||||
uint16_t num_purge_pulses;
 | 
			
		||||
uint16_t button_purge;
 | 
			
		||||
 | 
			
		||||
uint16_t button_store;
 | 
			
		||||
uint16_t button_reload;
 | 
			
		||||
uint16_t label_storeStatus;
 | 
			
		||||
 | 
			
		||||
void SettingChanged_Callback(Control *sender, int type)
 | 
			
		||||
{
 | 
			
		||||
  if (sender->id == num_lubedist_normal)
 | 
			
		||||
    LubeConfig.DistancePerLube_Default = ESPUI.getControl(num_lubedist_normal)->value.toInt();
 | 
			
		||||
  else if (sender->id == num_lubedist_rain)
 | 
			
		||||
    LubeConfig.DistancePerLube_Rain = ESPUI.getControl(num_lubedist_rain)->value.toInt();
 | 
			
		||||
  else if (sender->id == num_wheel_width)
 | 
			
		||||
    LubeConfig.TireWidth_mm = ESPUI.getControl(num_wheel_width)->value.toInt();
 | 
			
		||||
  else if (sender->id == num_wheel_ratio)
 | 
			
		||||
    LubeConfig.TireWidthHeight_Ratio = ESPUI.getControl(num_wheel_ratio)->value.toInt();
 | 
			
		||||
  else if (sender->id == num_wheel_rim)
 | 
			
		||||
    LubeConfig.RimDiameter_Inch = ESPUI.getControl(num_wheel_rim)->value.toInt();
 | 
			
		||||
  else if (sender->id == num_wheel_ppr)
 | 
			
		||||
    LubeConfig.PulsePerRevolution = ESPUI.getControl(num_wheel_ppr)->value.toInt();
 | 
			
		||||
  else if (sender->id == num_wheel_dist)
 | 
			
		||||
    LubeConfig.DistancePerRevolution_mm = ESPUI.getControl(num_wheel_dist)->value.toInt();
 | 
			
		||||
  else if (sender->id == num_tank_capacity)
 | 
			
		||||
    LubeConfig.tankCapacity_ml = ESPUI.getControl(num_tank_capacity)->value.toInt();
 | 
			
		||||
  else if (sender->id == num_tank_notify)
 | 
			
		||||
    LubeConfig.TankRemindAtPercentage = ESPUI.getControl(num_tank_notify)->value.toInt();
 | 
			
		||||
  else if (sender->id == num_dose_per_pulse)
 | 
			
		||||
    LubeConfig.amountPerDose_µl = ESPUI.getControl(num_dose_per_pulse)->value.toInt();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void buttons_Callback(Control *sender, int type)
 | 
			
		||||
{
 | 
			
		||||
  if (type != B_UP)
 | 
			
		||||
    return;
 | 
			
		||||
 | 
			
		||||
  if (sender->id == button_wheelcalc)
 | 
			
		||||
  {
 | 
			
		||||
    LubeConfig.TireWidth_mm = ESPUI.getControl(num_wheel_width)->value.toInt();
 | 
			
		||||
    LubeConfig.RimDiameter_Inch = ESPUI.getControl(num_wheel_rim)->value.toInt();
 | 
			
		||||
    LubeConfig.TireWidthHeight_Ratio = ESPUI.getControl(num_wheel_ratio)->value.toInt();
 | 
			
		||||
    LubeConfig.DistancePerRevolution_mm = (uint32_t)((((((float)LubeConfig.TireWidthHeight_Ratio / 100.0) * (float)LubeConfig.TireWidth_mm) * 2.0) + ((float)LubeConfig.RimDiameter_Inch * 25.4)) * 3.1416);
 | 
			
		||||
    ESPUI.updateControlValue(num_wheel_dist, String(LubeConfig.DistancePerRevolution_mm));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (sender->id == button_reset_tank)
 | 
			
		||||
  {
 | 
			
		||||
    LubeConfig.tankRemain_µl = LubeConfig.tankCapacity_ml * 1000;
 | 
			
		||||
    ESPUI.print(label_tankRemain, String(LubeConfig.tankRemain_µl / 1000));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (sender->id == button_purge)
 | 
			
		||||
  {
 | 
			
		||||
    int pulses = ESPUI.getControl(num_purge_pulses)->value.toInt();
 | 
			
		||||
    Serial.printf("Starting to Purge with %d pulses", pulses);
 | 
			
		||||
    globals.purgePulses = pulses;
 | 
			
		||||
    globals.resumeStatus = globals.systemStatus;
 | 
			
		||||
    globals.systemStatus = sysStat_Purge;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (sender->id == button_store)
 | 
			
		||||
  {
 | 
			
		||||
    StoreConfig_EEPROM();
 | 
			
		||||
    ESPUI.print(label_storeStatus, "Successfully Stored Settings");
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (sender->id == button_reload)
 | 
			
		||||
  {
 | 
			
		||||
    GetConfig_EEPROM();
 | 
			
		||||
    ESPUI.print(label_storeStatus, "Successfully Reloaded Settings");
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void initWebUI()
 | 
			
		||||
{
 | 
			
		||||
  tab_lube = ESPUI.addControl(ControlType::Tab, "Dosierung", "Dosierung");
 | 
			
		||||
  tab_wheel = ESPUI.addControl(ControlType::Tab, "Erfassung", "Erfassung");
 | 
			
		||||
  tab_tank = ESPUI.addControl(ControlType::Tab, "Tank", "Tank");
 | 
			
		||||
  tab_maintenance = ESPUI.addControl(ControlType::Tab, "Wartung", "Wartung");
 | 
			
		||||
  tab_store = ESPUI.addControl(ControlType::Tab, "Speichern", "Speichern");
 | 
			
		||||
 | 
			
		||||
  num_lubedist_normal = ESPUI.addControl(ControlType::Number, "Öl-Impuls alle x Meter (Normal)", String(LubeConfig.DistancePerLube_Default), ControlColor::Emerald, tab_lube, &SettingChanged_Callback);
 | 
			
		||||
  num_lubedist_rain = ESPUI.addControl(ControlType::Number, "Öl-Impuls alle x Meter (Regen)", String(LubeConfig.DistancePerLube_Rain), ControlColor::Emerald, tab_lube, &SettingChanged_Callback);
 | 
			
		||||
 | 
			
		||||
  num_wheel_width = ESPUI.addControl(ControlType::Number, "Reifenbreite (mm)", String(LubeConfig.TireWidth_mm), ControlColor::Peterriver, tab_wheel, &SettingChanged_Callback);
 | 
			
		||||
  num_wheel_ratio = ESPUI.addControl(ControlType::Number, "Höhe/Breite-Verhältniss", String(LubeConfig.TireWidthHeight_Ratio), ControlColor::Peterriver, tab_wheel, &SettingChanged_Callback);
 | 
			
		||||
  num_wheel_rim = ESPUI.addControl(ControlType::Number, "Felgendurchmesser (Zoll)", String(LubeConfig.RimDiameter_Inch), ControlColor::Peterriver, tab_wheel, &SettingChanged_Callback);
 | 
			
		||||
  button_wheelcalc = ESPUI.addControl(ControlType::Button, "Abrollumfang aus Reifendaten berechnen", "Berechnen", ControlColor::Peterriver, tab_wheel, &buttons_Callback);
 | 
			
		||||
  num_wheel_dist = ESPUI.addControl(ControlType::Number, "Wegstrecke pro Radumdrehung (mm)", String(LubeConfig.DistancePerRevolution_mm), ControlColor::Wetasphalt, tab_wheel, &SettingChanged_Callback);
 | 
			
		||||
  num_wheel_ppr = ESPUI.addControl(ControlType::Number, "Sensorimpulse pro Umdrehung", String(LubeConfig.PulsePerRevolution), ControlColor::Wetasphalt, tab_wheel, &SettingChanged_Callback);
 | 
			
		||||
 | 
			
		||||
  num_tank_capacity = ESPUI.addControl(ControlType::Number, "Tankinhalt maximal (ml)", String(LubeConfig.tankCapacity_ml), ControlColor::Carrot, tab_tank, &SettingChanged_Callback);
 | 
			
		||||
  num_tank_notify = ESPUI.addControl(ControlType::Number, "Tankinhalt Warnung (%)", String(LubeConfig.TankRemindAtPercentage), ControlColor::Carrot, tab_tank, &SettingChanged_Callback);
 | 
			
		||||
  num_dose_per_pulse = ESPUI.addControl(ControlType::Number, "Menge pro Pumpenimpuls (µl)", String(LubeConfig.amountPerDose_µl), ControlColor::Carrot, tab_tank, &SettingChanged_Callback);
 | 
			
		||||
 | 
			
		||||
  label_tankRemain = ESPUI.addControl(ControlType::Label, "Tankinhalt verbleibend (ml, geschätzt)", String(LubeConfig.tankRemain_µl / 1000), ControlColor::Alizarin, tab_maintenance);
 | 
			
		||||
  button_reset_tank = ESPUI.addControl(ControlType::Button, "Tankinhalt zurücksetzen", "Reset", ControlColor::Alizarin, tab_maintenance, &buttons_Callback);
 | 
			
		||||
  num_purge_pulses = ESPUI.addControl(ControlType::Number, "Entlüftung Impulse", "10", ControlColor::Alizarin, tab_maintenance);
 | 
			
		||||
  button_purge = ESPUI.addControl(ControlType::Button, "Leitung Entlüften", "Start", ControlColor::Alizarin, tab_maintenance, &buttons_Callback);
 | 
			
		||||
 | 
			
		||||
  button_store = ESPUI.addControl(ControlType::Button, "Einstellungen permanent speichern", "Speichern", ControlColor::Turquoise, tab_store, &buttons_Callback);
 | 
			
		||||
  button_reload = ESPUI.addControl(ControlType::Button, "Einstellungen neu laden", "Laden", ControlColor::Turquoise, tab_store, &buttons_Callback);
 | 
			
		||||
  label_storeStatus = ESPUI.addControl(ControlType::Label, "Status", "", ControlColor::Turquoise, tab_store);
 | 
			
		||||
 | 
			
		||||
  ESPUI.begin("Souko's ChainLube Mk1");
 | 
			
		||||
}
 | 
			
		||||
@@ -1,12 +0,0 @@
 | 
			
		||||
#ifndef _WEBUI_H_
 | 
			
		||||
#define _WEBUI_H_
 | 
			
		||||
 | 
			
		||||
#include <Arduino.h>
 | 
			
		||||
#include <ESPUI.h>
 | 
			
		||||
#include "config.h"
 | 
			
		||||
#include "globals.h"
 | 
			
		||||
 | 
			
		||||
void initWebUI();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
							
								
								
									
										77
									
								
								Software/assets/Logo.svg
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 10 KiB  | 
							
								
								
									
										510
									
								
								Software/data/index.htm
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,510 @@
 | 
			
		||||
<!DOCTYPE html>
 | 
			
		||||
<html>
 | 
			
		||||
 | 
			
		||||
<head>
 | 
			
		||||
  <meta charset="utf-8" />
 | 
			
		||||
  <title>KTM CAN Chain Oiler</title>
 | 
			
		||||
  <meta http-equiv="content-type" content="text/html;charset=UTF-8">
 | 
			
		||||
  <meta name="viewport" content="width=device-width, initial-scale=1">
 | 
			
		||||
  <link rel="stylesheet" href="static/css/bootstrap.min.css">
 | 
			
		||||
  <link rel="stylesheet" href="static/css/custom.css">
 | 
			
		||||
  <script src="static/js/jquery.min.js"></script>
 | 
			
		||||
  <script src="static/js/bootstrap.min.js"></script>
 | 
			
		||||
  <link rel="apple-touch-icon" sizes="180x180" href="static/img/apple-touch-icon.png">
 | 
			
		||||
  <link rel="icon" type="image/png" sizes="32x32" href="static/img/favicon-32x32.png">
 | 
			
		||||
  <link rel="icon" type="image/png" sizes="16x16" href="static/img/favicon-16x16.png">
 | 
			
		||||
  <link rel="manifest" href="static/img/site.webmanifest">
 | 
			
		||||
</head>
 | 
			
		||||
 | 
			
		||||
<body>
 | 
			
		||||
 | 
			
		||||
  <nav class="navbar navbar-expand-md navbar-default fixed-top">
 | 
			
		||||
    <div class="navbar-header">
 | 
			
		||||
      <a class="navbar-brand" href="#">
 | 
			
		||||
        <img src="static/img/logo.png" width="30" height="30" class="d-inline-block align-top" alt="">
 | 
			
		||||
        KTM CAN ChainLube
 | 
			
		||||
      </a>
 | 
			
		||||
      <button type="button" data-target="#navbarCollapse" data-toggle="collapse" class="navbar-toggle">
 | 
			
		||||
        <span class="sr-only">Toggle navigation</span>
 | 
			
		||||
        <span class="icon-bar"></span>
 | 
			
		||||
        <span class="icon-bar"></span>
 | 
			
		||||
        <span class="icon-bar"></span>
 | 
			
		||||
      </button>
 | 
			
		||||
    </div>
 | 
			
		||||
 | 
			
		||||
    <!-- Collection of nav links, forms, and other content for toggling -->
 | 
			
		||||
    <div id="navbarCollapse" class="collapse navbar-collapse">
 | 
			
		||||
      <ul class="nav navbar-nav">
 | 
			
		||||
        <li class="active"><a data-toggle="tab" href="#tab_home">Home</a></li>
 | 
			
		||||
        <li><a data-toggle="tab" href="#tab_source">Wegstrecke</a></li>
 | 
			
		||||
        <li><a data-toggle="tab" href="#tab_lube">Schmierung</a></li>
 | 
			
		||||
        <li><a data-toggle="tab" href="#tab_tank">Öltank</a></li>
 | 
			
		||||
        <li><a data-toggle="tab" href="#tab_maintenance">Wartung</a></li>
 | 
			
		||||
        <li><a data-toggle="tab" href="#tab_sysinfo">Systeminfo</a></li>
 | 
			
		||||
        <li><a data-toggle="tab" href="#tab_fwupdate">Update</a></li>
 | 
			
		||||
      </ul>
 | 
			
		||||
 | 
			
		||||
    </div>
 | 
			
		||||
  </nav>
 | 
			
		||||
 | 
			
		||||
  <main role="main" class="container">
 | 
			
		||||
 | 
			
		||||
    <!-- Tabs Content -->
 | 
			
		||||
    <div class="tab-content">
 | 
			
		||||
      <!-- Div Tab Home-->
 | 
			
		||||
      <div id="tab_home" class="tab-pane fade in active">
 | 
			
		||||
        <div class="col text-center">
 | 
			
		||||
          <div class="jumbotron">
 | 
			
		||||
 | 
			
		||||
            <img src="static/img/logo.png" width="120" height="120" class="img-fluid" alt="">
 | 
			
		||||
            <h3>KTM CAN Chain Lube</h3>
 | 
			
		||||
          </div>
 | 
			
		||||
 | 
			
		||||
        </div>
 | 
			
		||||
        <p>
 | 
			
		||||
        <h4>Tankinhalt verbleibend</h4>
 | 
			
		||||
        <div class="progress">
 | 
			
		||||
          <div class="progress-bar" role="progressbar" aria-valuenow="%TANK_REMAIN_CAPACITY%" aria-valuemin="0"
 | 
			
		||||
            aria-valuemax="100" style="width: %TANK_REMAIN_CAPACITY%%">
 | 
			
		||||
            %TANK_REMAIN_CAPACITY%%
 | 
			
		||||
          </div>
 | 
			
		||||
        </div>
 | 
			
		||||
        <h4>aktueller Modus</h4>
 | 
			
		||||
        <input class="form-control" type="text" placeholder="%SYSTEM_STATUS%" readonly>
 | 
			
		||||
        <div %SHOW_DTC_TABLE%>
 | 
			
		||||
          <h4>Fehlercodes</h4>
 | 
			
		||||
          <table class="table">
 | 
			
		||||
            <tbody>
 | 
			
		||||
              <tr>
 | 
			
		||||
                <th class="col-md-4" scope="col">Timestamp</td>
 | 
			
		||||
                <th class="col-md-4" scope="col">DTC</td>
 | 
			
		||||
                <th class="col-md-4" scope="col">active</td>
 | 
			
		||||
              </tr>
 | 
			
		||||
              %DTC_TABLE%
 | 
			
		||||
            </tbody>
 | 
			
		||||
          </table>
 | 
			
		||||
        </div>
 | 
			
		||||
        </p>
 | 
			
		||||
      </div>
 | 
			
		||||
      <!-- Div Tab Home-->
 | 
			
		||||
      <!-- Div Tab Source Settings-->
 | 
			
		||||
      <div id="tab_source" class="tab-pane fade">
 | 
			
		||||
        <h3>Erfassung Wegstrecke</h3>
 | 
			
		||||
        <hr>
 | 
			
		||||
        <p>
 | 
			
		||||
        <form action="\post.htm" method="POST" class="form-horizontal">
 | 
			
		||||
          <div class="form-group">
 | 
			
		||||
            <label for="sourceselect" class="control-label col-xs-5">Wegstrecke Quelle</label>
 | 
			
		||||
            <div class="col-xs-7">
 | 
			
		||||
              <select id="sourceselect" name="sourceselect" class="select form-control">
 | 
			
		||||
                %SOURCE_SELECT_OPTIONS%
 | 
			
		||||
              </select>
 | 
			
		||||
            </div>
 | 
			
		||||
          </div>
 | 
			
		||||
          <div class="form-group row">
 | 
			
		||||
            <div class="col-xs-offset-5 col-xs-7">
 | 
			
		||||
              <button name="sourcesave" type="submit" class="btn btn-primary">Übernehmen</button>
 | 
			
		||||
            </div>
 | 
			
		||||
          </div>
 | 
			
		||||
        </form>
 | 
			
		||||
        </p>
 | 
			
		||||
        <div class="alert alert-warning">
 | 
			
		||||
          <strong>Achtung!</strong><br>
 | 
			
		||||
          Bei Änderung der Wegstrecken-Quelle wird der CAN-Oiler neu gestartet.
 | 
			
		||||
          Dadurch wird die WiFi-Verbindung getrennt und muss neu aufgebaut werden.
 | 
			
		||||
        </div>
 | 
			
		||||
        <!-- Div Source:Impulse Settings-->
 | 
			
		||||
        <div %SHOW_IMPULSE_SETTINGS%>
 | 
			
		||||
          <h4>Einstellungen Impuls</h4>
 | 
			
		||||
          <p>
 | 
			
		||||
          <form action="\post.htm" method="POST" class="form-horizontal">
 | 
			
		||||
            <div class="form-group">
 | 
			
		||||
              <label for="tirewidth" class="control-label col-xs-5">Reifenbreite</label>
 | 
			
		||||
              <div class="col-xs-7">
 | 
			
		||||
                <div class="input-group">
 | 
			
		||||
                  <input id="tirewidth" name="tirewidth" type="text" required="required" class="form-control"
 | 
			
		||||
                    value="%TIRE_WIDTH_MM%">
 | 
			
		||||
                  <div class="input-group-addon">mm</div>
 | 
			
		||||
                </div>
 | 
			
		||||
              </div>
 | 
			
		||||
            </div>
 | 
			
		||||
            <div class="form-group">
 | 
			
		||||
              <label for="tireratio" class="control-label col-xs-5">Höhe/Breite-Verhältniss</label>
 | 
			
		||||
              <div class="col-xs-7">
 | 
			
		||||
                <div class="input-group">
 | 
			
		||||
                  <input id="tireratio" name="tireratio" type="text" required="required" class="form-control"
 | 
			
		||||
                    value="%TIRE_RATIO%">
 | 
			
		||||
                  <div class="input-group-addon"></div>
 | 
			
		||||
                </div>
 | 
			
		||||
              </div>
 | 
			
		||||
            </div>
 | 
			
		||||
            <div class="form-group">
 | 
			
		||||
              <label for="tiredia" class="control-label col-xs-5">Felgendurchmesser</label>
 | 
			
		||||
              <div class="col-xs-7">
 | 
			
		||||
                <div class="input-group">
 | 
			
		||||
                  <input id="tiredia" name="tiredia" type="text" required="required" class="form-control"
 | 
			
		||||
                    value="%RIM_DIAMETER%">
 | 
			
		||||
                  <div class="input-group-addon">"</div>
 | 
			
		||||
                </div>
 | 
			
		||||
              </div>
 | 
			
		||||
            </div>
 | 
			
		||||
            <div class="form-group">
 | 
			
		||||
              <label for="pulserev" class="control-label col-xs-5">Pulse pro Umdrehung</label>
 | 
			
		||||
              <div class="col-xs-7">
 | 
			
		||||
                <div class="input-group">
 | 
			
		||||
                  <input id="pulserev" name="pulserev" type="text" required="required" class="form-control"
 | 
			
		||||
                    value="%PULSE_PER_REV%">
 | 
			
		||||
                  <div class="input-group-addon"></div>
 | 
			
		||||
                </div>
 | 
			
		||||
              </div>
 | 
			
		||||
            </div>
 | 
			
		||||
            <div class="form-group row">
 | 
			
		||||
              <div class="col-xs-offset-5 col-xs-7">
 | 
			
		||||
                <button name="pulsesave" type="submit" class="btn btn-primary">Speichern</button>
 | 
			
		||||
              </div>
 | 
			
		||||
            </div>
 | 
			
		||||
          </form>
 | 
			
		||||
          </p>
 | 
			
		||||
        </div>
 | 
			
		||||
        <!-- Div Source:Impulse Settings-->
 | 
			
		||||
        <!-- Div Source:CAN Settings-->
 | 
			
		||||
        <div %SHOW_CAN_SETTINGS%>
 | 
			
		||||
          <h4>Einstellungen CAN-Bus</h4>
 | 
			
		||||
          <p>
 | 
			
		||||
          <form action="\post.htm" method="POST" class="form-horizontal">
 | 
			
		||||
            <div class="form-group">
 | 
			
		||||
              <label for="cansource" class="control-label col-xs-5">Model</label>
 | 
			
		||||
              <div class="col-xs-7">
 | 
			
		||||
                <select id="cansource" name="cansource" class="select form-control">
 | 
			
		||||
                  %CANSOURCE_SELECT_OPTIONS%
 | 
			
		||||
                </select>
 | 
			
		||||
              </div>
 | 
			
		||||
            </div>
 | 
			
		||||
            <div class="form-group row">
 | 
			
		||||
              <div class="col-xs-offset-5 col-xs-7">
 | 
			
		||||
                <button name="cansave" type="submit" class="btn btn-primary">Speichern</button>
 | 
			
		||||
              </div>
 | 
			
		||||
            </div>
 | 
			
		||||
          </form>
 | 
			
		||||
          </p>
 | 
			
		||||
        </div>
 | 
			
		||||
        <!-- Div Source:CAN Settings-->
 | 
			
		||||
        <!-- Div Source:GPS Settings-->
 | 
			
		||||
        <div %SHOW_GPS_SETTINGS%>
 | 
			
		||||
          <h4>Einstellungen GPS</h4>
 | 
			
		||||
          <p>
 | 
			
		||||
          <form action="\post.htm" method="POST" class="form-horizontal">
 | 
			
		||||
            <div class="form-group">
 | 
			
		||||
              <label for="gpsbaud" class="control-label col-xs-5">Baudrate</label>
 | 
			
		||||
              <div class="col-xs-7">
 | 
			
		||||
                <select id="gpsbaud" name="gpsbaud" class="select form-control">
 | 
			
		||||
                  %GPSBAUD_SELECT_OPTIONS%
 | 
			
		||||
                </select>
 | 
			
		||||
              </div>
 | 
			
		||||
            </div>
 | 
			
		||||
            <div class="form-group row">
 | 
			
		||||
              <div class="col-xs-offset-5 col-xs-7">
 | 
			
		||||
                <button name="gpssave" type="submit" class="btn btn-primary">Speichern</button>
 | 
			
		||||
              </div>
 | 
			
		||||
            </div>
 | 
			
		||||
          </form>
 | 
			
		||||
          </p>
 | 
			
		||||
        </div>
 | 
			
		||||
        <!-- Div Source:GPS Settings-->
 | 
			
		||||
      </div>
 | 
			
		||||
      <!-- Div Tab Source Settings-->
 | 
			
		||||
      <!-- Div Tab Lube -->
 | 
			
		||||
      <div id="tab_lube" class="tab-pane fade">
 | 
			
		||||
        <h3>Schmierung</h3>
 | 
			
		||||
        <hr>
 | 
			
		||||
        <p>
 | 
			
		||||
        <form action="\post.htm" method="POST" class="form-horizontal">
 | 
			
		||||
          <div class="form-group">
 | 
			
		||||
            <label for="lubedistancenormal" class="control-label col-xs-5">Modus:normal</label>
 | 
			
		||||
            <div class="col-xs-7">
 | 
			
		||||
              <div class="input-group">
 | 
			
		||||
                <input id="lubedistancenormal" name="lubedistancenormal" value="%LUBE_DISTANCE_NORMAL%" type="text"
 | 
			
		||||
                  class="form-control" required="required">
 | 
			
		||||
                <div class="input-group-addon">m</div>
 | 
			
		||||
              </div>
 | 
			
		||||
            </div>
 | 
			
		||||
          </div>
 | 
			
		||||
          <div class="form-group">
 | 
			
		||||
            <label for="lubedistancerain" class="control-label col-xs-5">Modus:rain</label>
 | 
			
		||||
            <div class="col-xs-7">
 | 
			
		||||
              <div class="input-group">
 | 
			
		||||
                <input id="lubedistancerain" name="lubedistancerain" value="%LUBE_DISTANCE_RAIN%" type="text"
 | 
			
		||||
                  class="form-control" required="required">
 | 
			
		||||
                <div class="input-group-addon">m</div>
 | 
			
		||||
              </div>
 | 
			
		||||
            </div>
 | 
			
		||||
          </div>
 | 
			
		||||
          <div class="form-group row">
 | 
			
		||||
            <div class="col-xs-offset-5 col-xs-7">
 | 
			
		||||
              <button name="oilsave" type="submit" class="btn btn-primary">Speichern</button>
 | 
			
		||||
            </div>
 | 
			
		||||
          </div>
 | 
			
		||||
        </form>
 | 
			
		||||
        </p>
 | 
			
		||||
      </div>
 | 
			
		||||
      <!-- Div Tab Lube -->
 | 
			
		||||
      <!-- Div Tab Maintenance -->
 | 
			
		||||
      <div id="tab_maintenance" class="tab-pane fade">
 | 
			
		||||
        <h3>Wartung</h3>
 | 
			
		||||
        <hr>
 | 
			
		||||
        <p>
 | 
			
		||||
        <form action="\post.htm" method="POST" class="form-horizontal">
 | 
			
		||||
          <div class="form-group">
 | 
			
		||||
            <label for="purgepulse" class="control-label col-xs-5">Entlüftung Impulse</label>
 | 
			
		||||
            <div class="col-xs-7">
 | 
			
		||||
              <div class="input-group">
 | 
			
		||||
                <input id="purgepulse" name="purgepulse" value="%BLEEDING_PULSES%" type="text" class="form-control">
 | 
			
		||||
                <div class="input-group-addon"></div>
 | 
			
		||||
              </div>
 | 
			
		||||
            </div>
 | 
			
		||||
          </div>
 | 
			
		||||
          <div class="form-group row">
 | 
			
		||||
            <div class="col-xs-offset-5 col-xs-7">
 | 
			
		||||
              <button name="maintsave" type="submit" class="btn btn-primary">Speichern</button>
 | 
			
		||||
            </div>
 | 
			
		||||
          </div>
 | 
			
		||||
        </form>
 | 
			
		||||
        </p>
 | 
			
		||||
        <p>
 | 
			
		||||
        <form action="\post.htm" method="POST" class="form-horizontal">
 | 
			
		||||
          <div class="form-group">
 | 
			
		||||
            <label for="tankremain_maint" class="control-label col-xs-5">Tankinhalt verbleibend</label>
 | 
			
		||||
            <div class="col-xs-7">
 | 
			
		||||
              <div class="progress">
 | 
			
		||||
                <div id="tankremain_maint" class="progress-bar" role="progressbar"
 | 
			
		||||
                  aria-valuenow="%TANK_REMAIN_CAPACITY%" aria-valuemin="0" aria-valuemax="100"
 | 
			
		||||
                  style="width: %TANK_REMAIN_CAPACITY%%">
 | 
			
		||||
                  %TANK_REMAIN_CAPACITY%%
 | 
			
		||||
                </div>
 | 
			
		||||
              </div>
 | 
			
		||||
            </div>
 | 
			
		||||
          </div>
 | 
			
		||||
          <div class="form-group row">
 | 
			
		||||
            <div class="col-xs-offset-5 col-xs-7">
 | 
			
		||||
              <button name="resettank" type="submit" class="btn btn-primary">Tank zurücksetzen</button>
 | 
			
		||||
            </div>
 | 
			
		||||
          </div>
 | 
			
		||||
        </form>
 | 
			
		||||
        </p>
 | 
			
		||||
      </div>
 | 
			
		||||
      <!-- Div Tab Maintenance -->
 | 
			
		||||
      <!-- Div Tank Settings-->
 | 
			
		||||
      <div id="tab_tank" class="tab-pane fade">
 | 
			
		||||
        <h3>Öltank</h3>
 | 
			
		||||
        <hr>
 | 
			
		||||
        <p>
 | 
			
		||||
        <form action="\post.htm" method="POST" class="form-horizontal">
 | 
			
		||||
          <div class="form-group">
 | 
			
		||||
            <label for="tankcap" class="control-label col-xs-5">Tankkapazität</label>
 | 
			
		||||
            <div class="col-xs-7">
 | 
			
		||||
              <div class="input-group">
 | 
			
		||||
                <input id="tankcap" name="tankcap" value="%TANK_CAPACITY%" type="text" class="form-control"
 | 
			
		||||
                  required="required">
 | 
			
		||||
                <div class="input-group-addon">ml</div>
 | 
			
		||||
              </div>
 | 
			
		||||
            </div>
 | 
			
		||||
          </div>
 | 
			
		||||
          <div class="form-group">
 | 
			
		||||
            <label for="tankwarn" class="control-label col-xs-5">Leer-Warnung</label>
 | 
			
		||||
            <div class="col-xs-7">
 | 
			
		||||
              <div class="input-group">
 | 
			
		||||
                <input id="tankwarn" name="tankwarn" value="%TANK_REMIND%" type="text" class="form-control"
 | 
			
		||||
                  required="required">
 | 
			
		||||
                <div class="input-group-addon">%</div>
 | 
			
		||||
              </div>
 | 
			
		||||
            </div>
 | 
			
		||||
          </div>
 | 
			
		||||
          <div class="form-group">
 | 
			
		||||
            <label for="pumppulse" class="control-label col-xs-5">Menge pro Puls</label>
 | 
			
		||||
            <div class="col-xs-7">
 | 
			
		||||
              <div class="input-group">
 | 
			
		||||
                <input id="pumppulse" name="pumppulse" value="%AMOUNT_PER_DOSE%" type="text" class="form-control"
 | 
			
		||||
                  required="required">
 | 
			
		||||
                <div class="input-group-addon">µl</div>
 | 
			
		||||
              </div>
 | 
			
		||||
            </div>
 | 
			
		||||
          </div>
 | 
			
		||||
          <div class="form-group row">
 | 
			
		||||
            <div class="col-xs-offset-5 col-xs-7">
 | 
			
		||||
              <button name="oilsave" type="submit" class="btn btn-primary">Speichern</button>
 | 
			
		||||
            </div>
 | 
			
		||||
          </div>
 | 
			
		||||
        </form>
 | 
			
		||||
        </p>
 | 
			
		||||
      </div>
 | 
			
		||||
      <!-- Div Tank Settings-->
 | 
			
		||||
      <!-- Div Tab SystemInfo -->
 | 
			
		||||
      <div id="tab_sysinfo" class="tab-pane fade">
 | 
			
		||||
        <h3>Systeminfo</h3>
 | 
			
		||||
        <hr>
 | 
			
		||||
        <h4>Einstellungen</h4>
 | 
			
		||||
        <p>
 | 
			
		||||
        <table class="table">
 | 
			
		||||
          <tbody>
 | 
			
		||||
            <tr>
 | 
			
		||||
              <th class="col-md-8" scope="col">Parameter</td>
 | 
			
		||||
              <th class="col-md-4" scope="col">Value</td>
 | 
			
		||||
            </tr>
 | 
			
		||||
            <tr>
 | 
			
		||||
              <td>DistancePerLube_Default</td>
 | 
			
		||||
              <td>%LUBE_DISTANCE_NORMAL%</td>
 | 
			
		||||
            </tr>
 | 
			
		||||
            <tr>
 | 
			
		||||
              <td>DistancePerLube_Rain</td>
 | 
			
		||||
              <td>%LUBE_DISTANCE_RAIN%</td>
 | 
			
		||||
            </tr>
 | 
			
		||||
            <tr>
 | 
			
		||||
              <td>tankCapacity_ml</td>
 | 
			
		||||
              <td>%TANK_CAPACITY%</td>
 | 
			
		||||
            </tr>
 | 
			
		||||
            <tr>
 | 
			
		||||
              <td>amountPerDose_µl</td>
 | 
			
		||||
              <td>%AMOUNT_PER_DOSE%</td>
 | 
			
		||||
            </tr>
 | 
			
		||||
            <tr>
 | 
			
		||||
              <td>TankRemindAtPercentage</td>
 | 
			
		||||
              <td>%TANK_REMIND%</td>
 | 
			
		||||
            </tr>
 | 
			
		||||
            <tr>
 | 
			
		||||
              <td>PulsePerRevolution</td>
 | 
			
		||||
              <td>%PULSE_PER_REV%</td>
 | 
			
		||||
            </tr>
 | 
			
		||||
            <tr>
 | 
			
		||||
              <td>TireWidth_mm</td>
 | 
			
		||||
              <td>%TIRE_WIDTH_MM%</td>
 | 
			
		||||
            </tr>
 | 
			
		||||
            <tr>
 | 
			
		||||
              <td>TireWidthHeight_Ratio</td>
 | 
			
		||||
              <td>%TIRE_RATIO%</td>
 | 
			
		||||
            </tr>
 | 
			
		||||
            <tr>
 | 
			
		||||
              <td>RimDiameter_Inch</td>
 | 
			
		||||
              <td>%RIM_DIAMETER%</td>
 | 
			
		||||
            </tr>
 | 
			
		||||
            <tr>
 | 
			
		||||
              <td>DistancePerRevolution_mm</td>
 | 
			
		||||
              <td>%DISTANCE_PER_REV%</td>
 | 
			
		||||
            </tr>
 | 
			
		||||
            <tr>
 | 
			
		||||
              <td>BleedingPulses</td>
 | 
			
		||||
              <td>%BLEEDING_PULSES%</td>
 | 
			
		||||
            </tr>
 | 
			
		||||
            <tr>
 | 
			
		||||
              <td>SpeedSource</td>
 | 
			
		||||
              <td>%SPEED_SOURCE%</td>
 | 
			
		||||
            </tr>
 | 
			
		||||
            <tr>
 | 
			
		||||
              <td>GPSBaudRate</td>
 | 
			
		||||
              <td>%GPS_BAUD%</td>
 | 
			
		||||
            </tr>
 | 
			
		||||
            <tr>
 | 
			
		||||
              <td>CANSource</td>
 | 
			
		||||
              <td>%CAN_SOURCE%</td>
 | 
			
		||||
            </tr>
 | 
			
		||||
            <tr>
 | 
			
		||||
              <td>Checksum</td>
 | 
			
		||||
              <td>%CONFIG_CHECKSUM%</td>
 | 
			
		||||
            </tr>
 | 
			
		||||
          </tbody>
 | 
			
		||||
        </table>
 | 
			
		||||
        </p>
 | 
			
		||||
        <h4>Betriebsdaten</h4>
 | 
			
		||||
        <p>
 | 
			
		||||
        <table class="table">
 | 
			
		||||
          <tbody>
 | 
			
		||||
            <tr>
 | 
			
		||||
              <th class="col-md-8" scope="col">Parameter</td>
 | 
			
		||||
              <th class="col-md-4" scope="col">Value</td>
 | 
			
		||||
            </tr>
 | 
			
		||||
            <tr>
 | 
			
		||||
              <td>writeCycleCounter</td>
 | 
			
		||||
              <td>%WRITE_CYCLE_COUNT%</td>
 | 
			
		||||
            </tr>
 | 
			
		||||
            <tr>
 | 
			
		||||
              <td>PersistenceMarker</td>
 | 
			
		||||
              <td>%PERSISTENCE_MARKER%</td>
 | 
			
		||||
            </tr>
 | 
			
		||||
            <tr>
 | 
			
		||||
              <td>tankRemain_µl</td>
 | 
			
		||||
              <td>%TANK_REMAIN_UL%</td>
 | 
			
		||||
            </tr>
 | 
			
		||||
            <tr>
 | 
			
		||||
              <td>TravelDistance_highRes</td>
 | 
			
		||||
              <td>%TRAVEL_DISTANCE_HIGHRES%</td>
 | 
			
		||||
            </tr>
 | 
			
		||||
            <tr>
 | 
			
		||||
              <td>Odometer</td>
 | 
			
		||||
              <td>%ODOMETER%,%ODOMETER_M%</td>
 | 
			
		||||
            </tr>
 | 
			
		||||
            <tr>
 | 
			
		||||
              <td>checksum</td>
 | 
			
		||||
              <td>%PERSISTANCE_CHECKSUM%</td>
 | 
			
		||||
            </tr>
 | 
			
		||||
        </table>
 | 
			
		||||
        </p>
 | 
			
		||||
      </div>
 | 
			
		||||
      <!-- Div Tab SystemInfo -->
 | 
			
		||||
      <!-- Div Tab Firmware Update-->
 | 
			
		||||
      <div id="tab_fwupdate" class="tab-pane fade">
 | 
			
		||||
        <h3>Firmware Update</h3>
 | 
			
		||||
        <hr>
 | 
			
		||||
        <h4>Version-Info</h4>
 | 
			
		||||
        <p>
 | 
			
		||||
        <table class="table">
 | 
			
		||||
          <tbody>
 | 
			
		||||
            <tr>
 | 
			
		||||
              <td>Firmware Version</td>
 | 
			
		||||
              <td>%SW_VERSION%</td>
 | 
			
		||||
            </tr>
 | 
			
		||||
            <tr>
 | 
			
		||||
              <td>Flash Version</td>
 | 
			
		||||
              <td>%FS_VERSION%</td>
 | 
			
		||||
            </tr>
 | 
			
		||||
        </table>
 | 
			
		||||
        </p>
 | 
			
		||||
        <hr>
 | 
			
		||||
        <h4>Firmware-Update</h4>
 | 
			
		||||
        <p>
 | 
			
		||||
        <form method='POST' action='/doUpdate' enctype='multipart/form-data'>
 | 
			
		||||
          <div class="form-group">
 | 
			
		||||
            <label for="fw-update-file" class="col-sm-2 col-form-label">Firmware-File</label>
 | 
			
		||||
            <div class="col-xs-7">
 | 
			
		||||
              <div class="input-group">
 | 
			
		||||
                <input id="fw-update-file" name="fw-update-file" type="file" class="form-control-file"
 | 
			
		||||
                  required="required">
 | 
			
		||||
              </div>
 | 
			
		||||
              <div class="form-group row">
 | 
			
		||||
                <div class="col-xs-offset-5 col-xs-7">
 | 
			
		||||
                  <button name="fw-update" type="submit" class="btn btn-primary">Aktualisieren</button>
 | 
			
		||||
                </div>
 | 
			
		||||
              </div>
 | 
			
		||||
            </div>
 | 
			
		||||
        </form>
 | 
			
		||||
        </p>
 | 
			
		||||
      </div>
 | 
			
		||||
      <!-- Div Tab Firmware Update-->
 | 
			
		||||
    </div>
 | 
			
		||||
    <!-- Tabs Content -->
 | 
			
		||||
  </main>
 | 
			
		||||
 | 
			
		||||
  <!-- Footer -->
 | 
			
		||||
  <footer class="navbar-default navbar-fixed-bottom">
 | 
			
		||||
    <div class="container-fluid">
 | 
			
		||||
      <!-- Copyright -->
 | 
			
		||||
      <div class="col text-center">
 | 
			
		||||
        © 2022 Copyright:
 | 
			
		||||
        <a class="text-reset fw-bold" href="https://eventronics.de/">Marcel Peterkau</a>
 | 
			
		||||
      </div>
 | 
			
		||||
      <!-- Copyright -->
 | 
			
		||||
    </div>
 | 
			
		||||
  </footer>
 | 
			
		||||
  <!-- Footer -->
 | 
			
		||||
 | 
			
		||||
</body>
 | 
			
		||||
 | 
			
		||||
</html>
 | 
			
		||||
							
								
								
									
										28
									
								
								Software/data/post.htm
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,28 @@
 | 
			
		||||
<!DOCTYPE html>
 | 
			
		||||
<html>
 | 
			
		||||
 | 
			
		||||
<head>
 | 
			
		||||
  <meta charset="utf-8" />
 | 
			
		||||
  <title>KTM CAN Chain Oiler</title>
 | 
			
		||||
  <meta http-equiv="content-type" content="text/html;charset=UTF-8">
 | 
			
		||||
  <meta name="viewport" content="width=device-width, initial-scale=1">
 | 
			
		||||
  <link rel="stylesheet" href="static/css/bootstrap.min.css">
 | 
			
		||||
  <link rel="stylesheet" href="static/css/custom.css">
 | 
			
		||||
  <script src="static/js/jquery.min.js"></script>
 | 
			
		||||
  <script src="static/js/bootstrap.min.js"></script>
 | 
			
		||||
  <link rel="apple-touch-icon" sizes="180x180" href="static/img/apple-touch-icon.png">
 | 
			
		||||
  <link rel="icon" type="image/png" sizes="32x32" href="static/img/favicon-32x32.png">
 | 
			
		||||
  <link rel="icon" type="image/png" sizes="16x16" href="static/img/favicon-16x16.png">
 | 
			
		||||
  <link rel="manifest" href="static/img/site.webmanifest">
 | 
			
		||||
  <meta http-equiv="refresh" content="3; url='/index.htm'" />
 | 
			
		||||
</head>
 | 
			
		||||
 | 
			
		||||
<body>
 | 
			
		||||
  <div class="container" style="display: flex; justify-content: center; align-items: center; height: 100vh">
 | 
			
		||||
    <div class="alert alert-success">
 | 
			
		||||
      <strong>Bitte warten!</strong> Änderungen werden übernommen.
 | 
			
		||||
    </div>
 | 
			
		||||
  </div>
 | 
			
		||||
</body>
 | 
			
		||||
 | 
			
		||||
</html>
 | 
			
		||||
							
								
								
									
										1
									
								
								Software/data/static/css/bootstrap.min.css
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										1
									
								
								Software/data/static/css/custom.css
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1 @@
 | 
			
		||||
kbd{border:1px solid #333}.btn-default:focus,.btn-default:active,.btn-default.active,.open .dropdown-toggle.btn-default{background-color:#6a6a6a;border-color:#636363}.btn-default:hover{background-color:#6a6a6a}.btn-primary:hover{background-color:#404040}.btn-success:hover{background-color:#3d8b3d}.btn-info:hover{background-color:#28a1c5}.btn-danger:hover{background-color:#b52b27}.btn-warning:hover{background-color:#df8a13}.navbar-default .navbar-nav>li.active>a:hover{background-color:#222}.navbar-inverse .navbar-nav>li.active>a:hover{background-color:#444}.table{color:#fff}.table .primary,.table .info,.table .success,.table .warning,.table .danger{color:#fff}.table-hover tr:hover{cursor:pointer}.input-group-addon{color:#fff}.nav>li>a:hover{color:#fff}.pager>li>a:hover{color:#fff}a:focus{outline:0}a.list-group-item.active:hover{background-color:#4d4d4d}a.list-group-item-success,a.list-group-item-info,a.list-group-item-warning,a.list-group-item-danger,a.list-group-item-success:hover,a.list-group-item-info:hover,a.list-group-item-warning:hover,a.list-group-item-danger:hover{color:#fff}a.active.list-group-item-success,a.active.list-group-item-info,a.active.list-group-item-warning,a.active.list-group-item-danger,a.active.list-group-item-success:hover,a.active.list-group-item-info:hover,a.active.list-group-item-warning:hover,a.active.list-group-item-danger:hover{border-color:#666}a.active.list-group-item-success:hover{background-color:#3d8b3d}a.active.list-group-item-info:hover{background-color:#28a1c5}a.active.list-group-item-warning:hover{background-color:#df8a13}a.active.list-group-item-danger:hover{background-color:#b52b27}.list-group-item-success,.list-group-item-info,.list-group-item-warning,.list-group-item-danger{color:#fff}.alert-info,.alert-primary,.alert-warning,.alert-danger,.alert-success{color:#fff}.alert-info .alert-link,.alert-primary .alert-link,.alert-warning .alert-link,.alert-danger .alert-link,.alert-success .alert-link{color:#fff}
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								Software/data/static/img/android-chrome-192x192.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 14 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								Software/data/static/img/android-chrome-512x512.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 39 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								Software/data/static/img/apple-touch-icon.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 13 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								Software/data/static/img/favicon-16x16.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 545 B  | 
							
								
								
									
										
											BIN
										
									
								
								Software/data/static/img/favicon-32x32.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 1.3 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								Software/data/static/img/favicon.ico
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 15 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								Software/data/static/img/logo.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 5.6 KiB  | 
							
								
								
									
										1
									
								
								Software/data/static/img/site.webmanifest
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1 @@
 | 
			
		||||
{"name":"","short_name":"","icons":[{"src":"/android-chrome-192x192.png","sizes":"192x192","type":"image/png"},{"src":"/android-chrome-512x512.png","sizes":"512x512","type":"image/png"}],"theme_color":"#ffffff","background_color":"#ffffff","display":"standalone"}
 | 
			
		||||
							
								
								
									
										7
									
								
								Software/data/static/js/bootstrap.min.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										2
									
								
								Software/data/static/js/jquery.min.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										1
									
								
								Software/data/version
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1 @@
 | 
			
		||||
1
 | 
			
		||||
@@ -30,17 +30,25 @@ build_flags =
 | 
			
		||||
  -DWIFI_PASSWORD=${wifi_cred.wifi_password}
 | 
			
		||||
  -DADMIN_PASSWORD=${wifi_cred.admin_password}
 | 
			
		||||
  -DWIFI_AP_PASSWORD=${wifi_cred.wifi_ap_password}
 | 
			
		||||
  -DWIFI_AP_IP_GW=10,0,0,1
 | 
			
		||||
  -DFEATURE_ENABLE_WIFI_CLIENT
 | 
			
		||||
  -DFEATURE_ENABLE_REMOTE_DEBUG
 | 
			
		||||
  ;-DFEATURE_ENABLE_CAN
 | 
			
		||||
  ;-DFEATURE_ENABLE_GPS
 | 
			
		||||
 | 
			
		||||
board_build.filesystem = littlefs
 | 
			
		||||
 | 
			
		||||
monitor_filters = esp8266_exception_decoder
 | 
			
		||||
monitor_speed = 115200
 | 
			
		||||
 | 
			
		||||
board_build.ldscript = eagle.flash.4m.ld
 | 
			
		||||
board_build.ldscript = eagle.flash.4m1m.ld
 | 
			
		||||
lib_ldf_mode = deep
 | 
			
		||||
lib_deps = 
 | 
			
		||||
    olikraus/U8g2 @ ^2.28.8
 | 
			
		||||
    joaolopesf/RemoteDebug @ ^2.1.2
 | 
			
		||||
    fastled/FastLED @ ^3.5.0
 | 
			
		||||
    sstaub/Ticker @ ^4.2.0
 | 
			
		||||
    s00500/ESPUI @ ^2.0.0
 | 
			
		||||
    coryjfowler/mcp_can @ ^1.5.0
 | 
			
		||||
    robtillaart/I2C_EEPROM @ ^1.5.2
 | 
			
		||||
    mikalhart/TinyGPSPlus @ ^1.0.3
 | 
			
		||||
    me-no-dev/ESP Async WebServer @ ^1.2.3
 | 
			
		||||
							
								
								
									
										46
									
								
								Software/src/can.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,46 @@
 | 
			
		||||
#ifdef FEATURE_ENABLE_CAN
 | 
			
		||||
#include "can.h"
 | 
			
		||||
 | 
			
		||||
MCP_CAN CAN0(GPIO_CS_CAN);
 | 
			
		||||
 | 
			
		||||
void Init_CAN()
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    if (CAN0.begin(MCP_STDEXT, CAN_500KBPS, MCP_16MHZ) != CAN_OK)
 | 
			
		||||
        MaintainDTC(DTC_CAN_TRANSCEIVER_FAILED, true);
 | 
			
		||||
 | 
			
		||||
    CAN0.init_Mask(0, 0, 0x07FF0000); // Init first mask...
 | 
			
		||||
    CAN0.init_Mask(1, 0, 0x07FF0000); // Init second mask...
 | 
			
		||||
    CAN0.init_Filt(0, 0, 0x012D0000); // Init first filter...
 | 
			
		||||
 | 
			
		||||
    CAN0.setMode(MCP_NORMAL);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint32_t Process_CAN_WheelSpeed()
 | 
			
		||||
{
 | 
			
		||||
#define FACTOR_RWP_KMH_890ADV 18 // Divider to convert Raw Data to km/h
 | 
			
		||||
 | 
			
		||||
    can_frame canMsg;
 | 
			
		||||
    static uint32_t lastRecTimestamp = 0;
 | 
			
		||||
    uint16_t RearWheelSpeed_raw;
 | 
			
		||||
 | 
			
		||||
    if (CAN0.readMsgBuf(&canMsg.can_id, &canMsg.can_dlc, canMsg.data) == CAN_OK)
 | 
			
		||||
    {
 | 
			
		||||
        RearWheelSpeed_raw = (uint16_t)canMsg.data[5] << 8 | canMsg.data[6];
 | 
			
		||||
        // raw / FACTOR_RWP_KMH_890ADV -> km/h * 100000 -> cm/h / 3600 -> cm/s
 | 
			
		||||
        // raw * 500 -> cm/s
 | 
			
		||||
        uint32_t RWP_millimeter_per_second = (((uint32_t)RearWheelSpeed_raw * 1000000) / FACTOR_RWP_KMH_890ADV) / 3600;
 | 
			
		||||
 | 
			
		||||
        uint32_t timesincelast = millis() - lastRecTimestamp;
 | 
			
		||||
        lastRecTimestamp = millis();
 | 
			
		||||
 | 
			
		||||
        uint32_t milimeters_to_add = (RWP_millimeter_per_second * timesincelast) / 1000;
 | 
			
		||||
 | 
			
		||||
        return milimeters_to_add;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    MaintainDTC(DTC_NO_CAN_SIGNAL, (millis() > lastRecTimestamp + 10000 ? true : false));
 | 
			
		||||
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
							
								
								
									
										21
									
								
								Software/src/can.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,21 @@
 | 
			
		||||
#ifndef _CAN_H_
 | 
			
		||||
#define _CAN_H_
 | 
			
		||||
 | 
			
		||||
#include <Arduino.h>
 | 
			
		||||
#include <mcp_can.h>
 | 
			
		||||
#include <SPI.h>
 | 
			
		||||
#include "common.h"
 | 
			
		||||
#include "globals.h"
 | 
			
		||||
#include "dtc.h"
 | 
			
		||||
 | 
			
		||||
struct can_frame
 | 
			
		||||
{
 | 
			
		||||
    unsigned long can_id;
 | 
			
		||||
    uint8_t can_dlc;
 | 
			
		||||
    uint8_t data[8] __attribute__((aligned(8)));
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
void Init_CAN();
 | 
			
		||||
uint32_t Process_CAN_WheelSpeed();
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
@@ -4,19 +4,25 @@
 | 
			
		||||
#define Q(x) #x
 | 
			
		||||
#define QUOTE(x) Q(x)
 | 
			
		||||
 | 
			
		||||
#define GPIO_BUTTON D5
 | 
			
		||||
#define GPIO_LED D6
 | 
			
		||||
#define GPIO_TRIGGER D4
 | 
			
		||||
#define GPIO_PUMP D3
 | 
			
		||||
#define GPIO_BUTTON D4
 | 
			
		||||
#define GPIO_LED D3
 | 
			
		||||
#define GPIO_TRIGGER D6
 | 
			
		||||
#define GPIO_PUMP D0
 | 
			
		||||
#define GPIO_CS_CAN D8
 | 
			
		||||
 | 
			
		||||
#ifndef HOST_NAME
 | 
			
		||||
#define HOST_NAME "ChainLube_%06X" // Use printf-Formatting - Chip-ID (uin32_t) will be added
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#define SW_VERSION_MAJOR 1
 | 
			
		||||
#define SW_VERSION_MINOR 0
 | 
			
		||||
 | 
			
		||||
#ifndef OTA_DELAY
 | 
			
		||||
#define OTA_DELAY 50 // ticks -> 10ms / tick
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#define ATOMIC_FS_UPDATE 
 | 
			
		||||
 | 
			
		||||
#ifndef ADMIN_PASSWORD
 | 
			
		||||
#error "You need to define ADMIN_PASSWORD for OTA-Update"
 | 
			
		||||
#endif
 | 
			
		||||
							
								
								
									
										226
									
								
								Software/src/config.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,226 @@
 | 
			
		||||
#include "config.h"
 | 
			
		||||
 | 
			
		||||
I2C_eeprom ee(0x50, EEPROM_SIZE_BYTES);
 | 
			
		||||
 | 
			
		||||
LubeConfig_t LubeConfig;
 | 
			
		||||
persistenceData_t PersistenceData;
 | 
			
		||||
uint16_t eePersistenceMarker = 0;
 | 
			
		||||
const uint16_t eeVersion = 1; // inc
 | 
			
		||||
boolean eeAvailable = false;
 | 
			
		||||
 | 
			
		||||
const uint16_t startofLubeConfig = 16;
 | 
			
		||||
const uint16_t startofPersistence = 16 + sizeof(LubeConfig) + (sizeof(LubeConfig) % 16);
 | 
			
		||||
 | 
			
		||||
boolean checkEEPROMavailable();
 | 
			
		||||
 | 
			
		||||
void InitEEPROM()
 | 
			
		||||
{
 | 
			
		||||
  ee.begin();
 | 
			
		||||
  if (!checkEEPROMavailable())
 | 
			
		||||
  {
 | 
			
		||||
    globals.systemStatus = sysStat_Error;
 | 
			
		||||
    MaintainDTC(DTC_NO_EEPROM_FOUND, true);
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
  GetConfig_EEPROM();
 | 
			
		||||
 | 
			
		||||
  if (LubeConfig.EEPROM_Version != eeVersion)
 | 
			
		||||
  {
 | 
			
		||||
    FormatConfig_EEPROM();
 | 
			
		||||
    globals.systemStatus = sysStat_Error;
 | 
			
		||||
    MaintainDTC(DTC_EEPROM_VERSION_BAD, true);
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void EEPROM_Process()
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
  switch (globals.requestEEAction)
 | 
			
		||||
  {
 | 
			
		||||
  case EE_CFG_SAVE:
 | 
			
		||||
    StoreConfig_EEPROM();
 | 
			
		||||
    globals.requestEEAction = EE_IDLE;
 | 
			
		||||
    break;
 | 
			
		||||
  case EE_CFG_LOAD:
 | 
			
		||||
    GetConfig_EEPROM();
 | 
			
		||||
    globals.requestEEAction = EE_IDLE;
 | 
			
		||||
    break;
 | 
			
		||||
  case EE_PDS_SAVE:
 | 
			
		||||
    StorePersistence_EEPROM();
 | 
			
		||||
    globals.requestEEAction = EE_IDLE;
 | 
			
		||||
    break;
 | 
			
		||||
  case EE_PDS_LOAD:
 | 
			
		||||
    GetPersistence_EEPROM();
 | 
			
		||||
    globals.requestEEAction = EE_IDLE;
 | 
			
		||||
    break;
 | 
			
		||||
  case EE_IDLE:
 | 
			
		||||
  default:
 | 
			
		||||
    globals.requestEEAction = EE_IDLE;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void StoreConfig_EEPROM()
 | 
			
		||||
{
 | 
			
		||||
  LubeConfig.checksum = 0;
 | 
			
		||||
  LubeConfig.checksum = Checksum_EEPROM((uint8_t *)&LubeConfig, sizeof(LubeConfig));
 | 
			
		||||
  if (!checkEEPROMavailable())
 | 
			
		||||
    return;
 | 
			
		||||
 | 
			
		||||
  ee.updateBlock(startofLubeConfig, (uint8_t *)&LubeConfig, sizeof(LubeConfig));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void GetConfig_EEPROM()
 | 
			
		||||
{
 | 
			
		||||
  if (!checkEEPROMavailable())
 | 
			
		||||
    return;
 | 
			
		||||
 | 
			
		||||
  ee.readBlock(startofLubeConfig, (uint8_t *)&LubeConfig, sizeof(LubeConfig));
 | 
			
		||||
 | 
			
		||||
  uint32_t checksum = LubeConfig.checksum;
 | 
			
		||||
  LubeConfig.checksum = 0;
 | 
			
		||||
 | 
			
		||||
  if (Checksum_EEPROM((uint8_t *)&LubeConfig, sizeof(LubeConfig)) != checksum)
 | 
			
		||||
  {
 | 
			
		||||
    MaintainDTC(DTC_EEPROM_CFG_BAD, true);
 | 
			
		||||
    FormatConfig_EEPROM();
 | 
			
		||||
  }
 | 
			
		||||
  LubeConfig.checksum = checksum;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint16_t getPersistanceAddress()
 | 
			
		||||
{
 | 
			
		||||
  return startofPersistence + eePersistenceMarker;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void StorePersistence_EEPROM()
 | 
			
		||||
{
 | 
			
		||||
  if (PersistenceData.writeCycleCounter >= 0xFFF0)
 | 
			
		||||
    MovePersistencePage_EEPROM(false);
 | 
			
		||||
  else
 | 
			
		||||
    PersistenceData.writeCycleCounter++;
 | 
			
		||||
 | 
			
		||||
  PersistenceData.checksum = 0;
 | 
			
		||||
  PersistenceData.checksum = Checksum_EEPROM((uint8_t *)&PersistenceData, sizeof(PersistenceData));
 | 
			
		||||
 | 
			
		||||
  if (!checkEEPROMavailable())
 | 
			
		||||
    return;
 | 
			
		||||
 | 
			
		||||
  ee.updateBlock(getPersistanceAddress(), (uint8_t *)&PersistenceData, sizeof(PersistenceData));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void GetPersistence_EEPROM()
 | 
			
		||||
{
 | 
			
		||||
  if (!checkEEPROMavailable())
 | 
			
		||||
    return;
 | 
			
		||||
 | 
			
		||||
  eePersistenceMarker = (ee.readByte(0) << 8) | ee.readByte(1);
 | 
			
		||||
  ee.readBlock(getPersistanceAddress(), (uint8_t *)&PersistenceData, sizeof(PersistenceData));
 | 
			
		||||
 | 
			
		||||
  uint32_t checksum = PersistenceData.checksum;
 | 
			
		||||
  PersistenceData.checksum = 0;
 | 
			
		||||
 | 
			
		||||
  if (Checksum_EEPROM((uint8_t *)&PersistenceData, sizeof(PersistenceData)) != checksum)
 | 
			
		||||
  {
 | 
			
		||||
    MaintainDTC(DTC_EEPROM_PDS_BAD, true);
 | 
			
		||||
    FormatPersistence_EEPROM();
 | 
			
		||||
  }
 | 
			
		||||
  PersistenceData.checksum = checksum;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void FormatConfig_EEPROM()
 | 
			
		||||
{
 | 
			
		||||
  LubeConfig_t defaults;
 | 
			
		||||
  LubeConfig = defaults;
 | 
			
		||||
  LubeConfig.EEPROM_Version = eeVersion;
 | 
			
		||||
  StoreConfig_EEPROM();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void FormatPersistence_EEPROM()
 | 
			
		||||
{
 | 
			
		||||
  persistenceData_t defaults;
 | 
			
		||||
  PersistenceData = defaults;
 | 
			
		||||
  eePersistenceMarker = 0;
 | 
			
		||||
  StorePersistence_EEPROM();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void MovePersistencePage_EEPROM(boolean reset)
 | 
			
		||||
{
 | 
			
		||||
  if (!checkEEPROMavailable())
 | 
			
		||||
    return;
 | 
			
		||||
 | 
			
		||||
  eePersistenceMarker = eePersistenceMarker + sizeof(PersistenceData);
 | 
			
		||||
  PersistenceData.writeCycleCounter = 0;
 | 
			
		||||
 | 
			
		||||
  // check if we reached the End of the EEPROM and Startover at the beginning
 | 
			
		||||
  // if ((startofPersistence + eePersistenceMarker + sizeof(PersistenceData)) > ee.getDeviceSize() || reset)
 | 
			
		||||
  // {
 | 
			
		||||
  //   eePersistenceMarker = 0;
 | 
			
		||||
  // }
 | 
			
		||||
 | 
			
		||||
  ee.updateByte(0, (uint8_t)(eePersistenceMarker >> 8));
 | 
			
		||||
  ee.updateByte(1, (uint8_t)(eePersistenceMarker & 0xFF));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint32_t Checksum_EEPROM(uint8_t const *data, size_t len)
 | 
			
		||||
{
 | 
			
		||||
  if (data == NULL)
 | 
			
		||||
    return 0;
 | 
			
		||||
  uint32_t crc, mask;
 | 
			
		||||
  crc = 0xFFFFFFFF;
 | 
			
		||||
 | 
			
		||||
  while (len--)
 | 
			
		||||
  {
 | 
			
		||||
    crc ^= *data++;
 | 
			
		||||
    for (uint8_t k = 0; k < 8; k++)
 | 
			
		||||
    {
 | 
			
		||||
      mask = -(crc & 1);
 | 
			
		||||
      crc = (crc >> 1) ^ (0xEDB88320 & mask);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  return ~crc;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void dumpEEPROM(uint16_t memoryAddress, uint16_t length)
 | 
			
		||||
{
 | 
			
		||||
#define BLOCK_TO_LENGTH 16
 | 
			
		||||
 | 
			
		||||
  if (!checkEEPROMavailable())
 | 
			
		||||
    return;
 | 
			
		||||
 | 
			
		||||
  char ascii_buf[BLOCK_TO_LENGTH + 1];
 | 
			
		||||
  sprintf(ascii_buf, "%*s", BLOCK_TO_LENGTH, "ASCII");
 | 
			
		||||
  Serial.print(PSTR("\nAddress "));
 | 
			
		||||
  for (int x = 0; x < BLOCK_TO_LENGTH; x++)
 | 
			
		||||
    Serial.printf("%3d", x);
 | 
			
		||||
 | 
			
		||||
  memoryAddress = memoryAddress / BLOCK_TO_LENGTH * BLOCK_TO_LENGTH;
 | 
			
		||||
  length = (length + BLOCK_TO_LENGTH - 1) / BLOCK_TO_LENGTH * BLOCK_TO_LENGTH;
 | 
			
		||||
 | 
			
		||||
  for (unsigned int i = 0; i < length; i++)
 | 
			
		||||
  {
 | 
			
		||||
    int blockpoint = memoryAddress % BLOCK_TO_LENGTH;
 | 
			
		||||
    if (blockpoint == 0)
 | 
			
		||||
    {
 | 
			
		||||
      ascii_buf[BLOCK_TO_LENGTH] = 0;
 | 
			
		||||
      Serial.printf("  %s", ascii_buf);
 | 
			
		||||
      Serial.printf("\n0x%05X:", memoryAddress);
 | 
			
		||||
    }
 | 
			
		||||
    ascii_buf[blockpoint] = ee.readByte(memoryAddress);
 | 
			
		||||
    Serial.printf(" %02X", ascii_buf[blockpoint]);
 | 
			
		||||
    if (ascii_buf[blockpoint] < 0x20 || ascii_buf[blockpoint] > 0x7E)
 | 
			
		||||
      ascii_buf[blockpoint] = '.';
 | 
			
		||||
    memoryAddress++;
 | 
			
		||||
  }
 | 
			
		||||
  Serial.println();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
boolean checkEEPROMavailable()
 | 
			
		||||
{
 | 
			
		||||
  if (!ee.isConnected())
 | 
			
		||||
  {
 | 
			
		||||
    MaintainDTC(DTC_NO_EEPROM_FOUND, true);
 | 
			
		||||
    return false;
 | 
			
		||||
  }
 | 
			
		||||
  return true;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										113
									
								
								Software/src/config.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,113 @@
 | 
			
		||||
#ifndef _CONFIG_H_
 | 
			
		||||
#define _CONFIG_H_
 | 
			
		||||
 | 
			
		||||
#include <Arduino.h>
 | 
			
		||||
#include <Wire.h>
 | 
			
		||||
#include <I2C_eeprom.h>
 | 
			
		||||
#include "globals.h"
 | 
			
		||||
#include "dtc.h"
 | 
			
		||||
 | 
			
		||||
#define EEPROM_SIZE_BYTES I2C_DEVICESIZE_24LC256
 | 
			
		||||
 | 
			
		||||
typedef enum SpeedSource_e
 | 
			
		||||
{
 | 
			
		||||
  SOURCE_TIME,
 | 
			
		||||
  SOURCE_IMPULSE,
 | 
			
		||||
#ifdef FEATURE_ENABLE_GPS
 | 
			
		||||
  SOURCE_GPS,
 | 
			
		||||
#endif
 | 
			
		||||
#if FEATURE_ENABLE_CAN
 | 
			
		||||
  SOURCE_CAN
 | 
			
		||||
#endif
 | 
			
		||||
} SpeedSource_t;
 | 
			
		||||
 | 
			
		||||
const char SpeedSourceString[][8] = {
 | 
			
		||||
    "Timer",
 | 
			
		||||
    "Impuls",
 | 
			
		||||
#ifdef FEATURE_ENABLE_GPS
 | 
			
		||||
    "GPS",
 | 
			
		||||
#endif
 | 
			
		||||
#if FEATURE_ENABLE_CAN
 | 
			
		||||
    "CAN-Bus"
 | 
			
		||||
#endif
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#ifdef FEATURE_ENABLE_GPS
 | 
			
		||||
typedef enum GPSBaudRate_e
 | 
			
		||||
{
 | 
			
		||||
  BAUD_9600,
 | 
			
		||||
  BAUD_115200
 | 
			
		||||
} GPSBaudRate_t;
 | 
			
		||||
 | 
			
		||||
const char GPSBaudRateString[][7] = {
 | 
			
		||||
    "9600",
 | 
			
		||||
    "115200"};
 | 
			
		||||
 | 
			
		||||
const size_t GPSBaudRateString_Elements = sizeof(GPSBaudRateString) / sizeof(GPSBaudRateString[0]);
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifdef FEATURE_ENABLE_CAN
 | 
			
		||||
typedef enum CANSource_e
 | 
			
		||||
{
 | 
			
		||||
  KTM_890_ADV_R_2021
 | 
			
		||||
} CANSource_t;
 | 
			
		||||
 | 
			
		||||
const char CANSourceString[][28] = {
 | 
			
		||||
    "KTM 890 Adventure R (2021)"};
 | 
			
		||||
 | 
			
		||||
const char CANSourceString_Elements = sizeof(CANSourceString) / sizeof(CANSourceString[0]);
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
const size_t SpeedSourceString_Elements = sizeof(SpeedSourceString) / sizeof(SpeedSourceString[0]);
 | 
			
		||||
 | 
			
		||||
typedef struct
 | 
			
		||||
{
 | 
			
		||||
  uint16_t writeCycleCounter = 0;
 | 
			
		||||
  uint32_t tankRemain_µl = 0;
 | 
			
		||||
  uint32_t TravelDistance_highRes_mm = 0;
 | 
			
		||||
  uint32_t odometer_mm = 0;
 | 
			
		||||
  uint32_t odometer = 0;
 | 
			
		||||
  uint32_t checksum = 0;
 | 
			
		||||
} persistenceData_t;
 | 
			
		||||
 | 
			
		||||
typedef struct
 | 
			
		||||
{
 | 
			
		||||
  uint8_t EEPROM_Version = 0;
 | 
			
		||||
  uint32_t DistancePerLube_Default = 8000;
 | 
			
		||||
  uint32_t DistancePerLube_Rain = 4000;
 | 
			
		||||
  uint32_t tankCapacity_ml = 320;
 | 
			
		||||
  uint32_t amountPerDose_µl = 72;
 | 
			
		||||
  uint8_t TankRemindAtPercentage = 30;
 | 
			
		||||
  uint8_t PulsePerRevolution = 1;
 | 
			
		||||
  uint32_t TireWidth_mm = 150;
 | 
			
		||||
  uint32_t TireWidthHeight_Ratio = 70;
 | 
			
		||||
  uint32_t RimDiameter_Inch = 18;
 | 
			
		||||
  uint32_t DistancePerRevolution_mm = 2000;
 | 
			
		||||
  uint8_t BleedingPulses = 25;
 | 
			
		||||
  SpeedSource_t SpeedSource = SOURCE_IMPULSE;
 | 
			
		||||
#ifdef FEATURE_ENABLE_GPS
 | 
			
		||||
  GPSBaudRate_t GPSBaudRate = BAUD_115200;
 | 
			
		||||
#endif
 | 
			
		||||
#ifdef FEATURE_ENABLE_CAN
 | 
			
		||||
  CANSource_t CANSource = KTM_890_ADV_R_2021;
 | 
			
		||||
#endif
 | 
			
		||||
  uint32_t checksum = 0;
 | 
			
		||||
} LubeConfig_t;
 | 
			
		||||
 | 
			
		||||
void InitEEPROM();
 | 
			
		||||
void EEPROM_Process();
 | 
			
		||||
void StoreConfig_EEPROM();
 | 
			
		||||
void GetConfig_EEPROM();
 | 
			
		||||
void StorePersistence_EEPROM();
 | 
			
		||||
void GetPersistence_EEPROM();
 | 
			
		||||
void FormatConfig_EEPROM();
 | 
			
		||||
void FormatPersistence_EEPROM();
 | 
			
		||||
uint32_t Checksum_EEPROM(uint8_t const *data, size_t len);
 | 
			
		||||
void dumpEEPROM(uint16_t memoryAddress, uint16_t length);
 | 
			
		||||
void MovePersistencePage_EEPROM(boolean reset);
 | 
			
		||||
uint16_t getPersistanceAddress();
 | 
			
		||||
 | 
			
		||||
extern LubeConfig_t LubeConfig;
 | 
			
		||||
extern persistenceData_t PersistenceData;
 | 
			
		||||
extern uint16_t eePersistenceMarker;
 | 
			
		||||
#endif // _CONFIG_H_
 | 
			
		||||
							
								
								
									
										85
									
								
								Software/src/dtc.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,85 @@
 | 
			
		||||
#include "dtc.h"
 | 
			
		||||
 | 
			
		||||
DTCEntry_s DTCStorage[MAX_DTC_STORAGE];
 | 
			
		||||
 | 
			
		||||
void MaintainDTC(DTCNums_t DTC_no, boolean active)
 | 
			
		||||
{
 | 
			
		||||
    for (int i = 0; i < MAX_DTC_STORAGE; i++)
 | 
			
		||||
    {
 | 
			
		||||
        if (DTCStorage[i].Number == DTC_no)
 | 
			
		||||
        {
 | 
			
		||||
            if (active && DTCStorage[i].active != DTC_ACTIVE)
 | 
			
		||||
            {
 | 
			
		||||
                Serial.printf("DTC gone active: %d\n", DTC_no);
 | 
			
		||||
                DTCStorage[i].timestamp = millis();
 | 
			
		||||
                DTCStorage[i].active = DTC_ACTIVE;
 | 
			
		||||
            }
 | 
			
		||||
            if (!active && DTCStorage[i].active == DTC_ACTIVE)
 | 
			
		||||
            {
 | 
			
		||||
                Serial.printf("DTC gone previous: %d\n", DTC_no);
 | 
			
		||||
                DTCStorage[i].active = DTC_PREVIOUS;
 | 
			
		||||
            }
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // DTC was not found with upper iteration, but is active
 | 
			
		||||
    // so we need to look for free space to store DTC
 | 
			
		||||
    if (active == true)
 | 
			
		||||
    {
 | 
			
		||||
        for (int i = 0; i < MAX_DTC_STORAGE; i++)
 | 
			
		||||
        {
 | 
			
		||||
            if (DTCStorage[i].Number == DTC_LAST_DTC)
 | 
			
		||||
            {
 | 
			
		||||
                Serial.printf("new DTC registered: %d\n", DTC_no);
 | 
			
		||||
                DTCStorage[i].Number = DTC_no;
 | 
			
		||||
                DTCStorage[i].timestamp = millis();
 | 
			
		||||
                DTCStorage[i].active = DTC_ACTIVE;
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ClearDTC(DTCNums_t DTC_no)
 | 
			
		||||
{
 | 
			
		||||
    for (int i = 0; i < MAX_DTC_STORAGE; i++)
 | 
			
		||||
    {
 | 
			
		||||
        if (DTCStorage[i].Number == DTC_no)
 | 
			
		||||
        {
 | 
			
		||||
            DTCStorage[i].Number = DTC_LAST_DTC;
 | 
			
		||||
            DTCStorage[i].active = DTC_NONE;
 | 
			
		||||
            DTCStorage[i].timestamp = 0;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ClearAllDTC()
 | 
			
		||||
{
 | 
			
		||||
    for (int i = 0; i < MAX_DTC_STORAGE; i++)
 | 
			
		||||
    {
 | 
			
		||||
        DTCStorage[i].Number = DTC_LAST_DTC;
 | 
			
		||||
        DTCStorage[i].active = DTC_NONE;
 | 
			
		||||
        DTCStorage[i].timestamp = 0;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
DTCNums_t getlastDTC(boolean only_active)
 | 
			
		||||
{
 | 
			
		||||
    int8_t pointer = -1;
 | 
			
		||||
    uint32_t lasttimestamp = 0;
 | 
			
		||||
 | 
			
		||||
    for (int i = 0; i < MAX_DTC_STORAGE; i++)
 | 
			
		||||
    {
 | 
			
		||||
        if (DTCStorage[i].Number > 0 && DTCStorage[i].timestamp > lasttimestamp)
 | 
			
		||||
        {
 | 
			
		||||
            if (only_active == false || DTCStorage[i].active == DTC_ACTIVE)
 | 
			
		||||
            {
 | 
			
		||||
                pointer = i;
 | 
			
		||||
                lasttimestamp = DTCStorage[i].timestamp;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return pointer >= 0 ? DTCStorage[pointer].Number : DTC_LAST_DTC;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										46
									
								
								Software/src/dtc.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,46 @@
 | 
			
		||||
#ifndef _DTC_H_
 | 
			
		||||
#define _DTC_H_
 | 
			
		||||
 | 
			
		||||
#include <Arduino.h>
 | 
			
		||||
 | 
			
		||||
#define MAX_DTC_STORAGE 6
 | 
			
		||||
 | 
			
		||||
typedef enum DTCNums_e
 | 
			
		||||
{
 | 
			
		||||
  DTC_TANK_EMPTY = 1,
 | 
			
		||||
  DTC_NO_EEPROM_FOUND,
 | 
			
		||||
  DTC_EEPROM_CFG_BAD,
 | 
			
		||||
  DTC_EEPROM_PDS_BAD,
 | 
			
		||||
  DTC_EEPROM_VERSION_BAD,
 | 
			
		||||
  DTC_FLASHFS_ERROR,
 | 
			
		||||
#ifdef FEATURE_ENABLE_GPS
 | 
			
		||||
  DTC_NO_GPS_SERIAL,
 | 
			
		||||
#endif
 | 
			
		||||
#ifdef FEATURE_ENABLE_CAN
 | 
			
		||||
  DTC_CAN_TRANSCEIVER_FAILED,
 | 
			
		||||
  DTC_NO_CAN_SIGNAL,
 | 
			
		||||
#endif
 | 
			
		||||
  DTC_LAST_DTC
 | 
			
		||||
} DTCNums_t;
 | 
			
		||||
 | 
			
		||||
typedef enum DTCActive_e
 | 
			
		||||
{
 | 
			
		||||
  DTC_NONE,
 | 
			
		||||
  DTC_ACTIVE,
 | 
			
		||||
  DTC_PREVIOUS
 | 
			
		||||
} DTCActive_t;
 | 
			
		||||
 | 
			
		||||
typedef struct DTCEntry_s
 | 
			
		||||
{
 | 
			
		||||
  DTCNums_t Number;
 | 
			
		||||
  uint32_t timestamp;
 | 
			
		||||
  DTCActive_t active;
 | 
			
		||||
} DTCEntry_t;
 | 
			
		||||
 | 
			
		||||
void MaintainDTC(DTCNums_t DTC_no, boolean active);
 | 
			
		||||
void ClearDTC(DTCNums_t DTC_no);
 | 
			
		||||
void ClearAllDTC();
 | 
			
		||||
DTCNums_t getlastDTC(boolean only_active);
 | 
			
		||||
 | 
			
		||||
extern DTCEntry_s DTCStorage[MAX_DTC_STORAGE];
 | 
			
		||||
#endif
 | 
			
		||||
							
								
								
									
										37
									
								
								Software/src/globals.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,37 @@
 | 
			
		||||
#ifndef _GLOBALS_H_
 | 
			
		||||
#define _GLOBALS_H_
 | 
			
		||||
 | 
			
		||||
#include <Arduino.h>
 | 
			
		||||
 | 
			
		||||
typedef enum eSystem_Status
 | 
			
		||||
{
 | 
			
		||||
  sysStat_Startup,
 | 
			
		||||
  sysStat_Normal,
 | 
			
		||||
  sysStat_Rain,
 | 
			
		||||
  sysStat_Purge,
 | 
			
		||||
  sysStat_Error,
 | 
			
		||||
  sysStat_Shutdown
 | 
			
		||||
} tSystem_Status;
 | 
			
		||||
 | 
			
		||||
typedef enum eEERequest
 | 
			
		||||
{
 | 
			
		||||
  EE_IDLE,
 | 
			
		||||
  EE_CFG_SAVE,
 | 
			
		||||
  EE_CFG_LOAD,
 | 
			
		||||
  EE_PDS_SAVE,
 | 
			
		||||
  EE_PDS_LOAD
 | 
			
		||||
} tEERequest;
 | 
			
		||||
 | 
			
		||||
typedef struct Globals_s
 | 
			
		||||
{
 | 
			
		||||
  tSystem_Status systemStatus = sysStat_Startup;
 | 
			
		||||
  tSystem_Status resumeStatus = sysStat_Startup;
 | 
			
		||||
  char systemStatustxt[16] = "";
 | 
			
		||||
  uint8_t purgePulses = 0;
 | 
			
		||||
  eEERequest requestEEAction = EE_IDLE;
 | 
			
		||||
  char DeviceName[33];
 | 
			
		||||
} Globals_t;
 | 
			
		||||
 | 
			
		||||
extern Globals_t globals;
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
							
								
								
									
										59
									
								
								Software/src/gps.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,59 @@
 | 
			
		||||
#ifdef FEATURE_ENABLE_GPS
 | 
			
		||||
#include "gps.h"
 | 
			
		||||
 | 
			
		||||
TinyGPSPlus gps;
 | 
			
		||||
 | 
			
		||||
void Init_GPS()
 | 
			
		||||
{
 | 
			
		||||
    uint32_t baudrate;
 | 
			
		||||
    switch (LubeConfig.GPSBaudRate)
 | 
			
		||||
    {
 | 
			
		||||
    case BAUD_9600:
 | 
			
		||||
        baudrate = 9600;
 | 
			
		||||
        break;
 | 
			
		||||
    case BAUD_115200:
 | 
			
		||||
        baudrate = 115200;
 | 
			
		||||
        break;
 | 
			
		||||
    default:
 | 
			
		||||
        baudrate = 4800;
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    Serial.printf(PSTR("Init GPS with Baud %d\n"), baudrate);
 | 
			
		||||
    Serial.begin(baudrate);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint32_t Process_GPS_WheelSpeed()
 | 
			
		||||
{
 | 
			
		||||
    static uint32_t lastRecTimestamp;
 | 
			
		||||
    static uint32_t lastValidSpeedTimestamp;
 | 
			
		||||
    uint16_t RearWheelSpeed_kmh;
 | 
			
		||||
 | 
			
		||||
    while (Serial.available() > 0)
 | 
			
		||||
    {
 | 
			
		||||
        uint8_t incoming = Serial.read();
 | 
			
		||||
        if (gps.encode(incoming))
 | 
			
		||||
        {
 | 
			
		||||
            RearWheelSpeed_kmh = gps.speed.isValid() ? gps.speed.kmph() : 0;
 | 
			
		||||
 | 
			
		||||
            if (RearWheelSpeed_kmh > 0)
 | 
			
		||||
            {
 | 
			
		||||
                uint32_t RWP_millimeter_per_second = ((uint32_t)RearWheelSpeed_kmh * 1000000) / 3600;
 | 
			
		||||
 | 
			
		||||
                uint32_t timesincelast = millis() - lastValidSpeedTimestamp;
 | 
			
		||||
                lastValidSpeedTimestamp = millis();
 | 
			
		||||
 | 
			
		||||
                uint32_t milimeters_to_add = (RWP_millimeter_per_second * timesincelast) / 1000;
 | 
			
		||||
 | 
			
		||||
                return milimeters_to_add;
 | 
			
		||||
            }
 | 
			
		||||
            lastRecTimestamp = millis();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    MaintainDTC(DTC_NO_GPS_SERIAL, (millis() > lastRecTimestamp + 10000));
 | 
			
		||||
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
							
								
								
									
										12
									
								
								Software/src/gps.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,12 @@
 | 
			
		||||
#ifndef _GPS_H_
 | 
			
		||||
#define _GPS_H_
 | 
			
		||||
 | 
			
		||||
#include <TinyGPSPlus.h>
 | 
			
		||||
#include "config.h"
 | 
			
		||||
#include "common.h"
 | 
			
		||||
#include "dtc.h"
 | 
			
		||||
 | 
			
		||||
void Init_GPS();
 | 
			
		||||
uint32_t Process_GPS_WheelSpeed();
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
							
								
								
									
										117
									
								
								Software/src/lubeapp.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,117 @@
 | 
			
		||||
#include "lubeapp.h"
 | 
			
		||||
 | 
			
		||||
uint32_t lubePulseTimestamp = 0;
 | 
			
		||||
 | 
			
		||||
void RunLubeApp(uint32_t add_milimeters)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    MaintainDTC(DTC_TANK_EMPTY, (PersistenceData.tankRemain_µl < LubeConfig.amountPerDose_µl));
 | 
			
		||||
 | 
			
		||||
    static tSystem_Status preserverSysStatusError;
 | 
			
		||||
 | 
			
		||||
    if (globals.systemStatus != sysStat_Error)
 | 
			
		||||
        preserverSysStatusError = globals.systemStatus;
 | 
			
		||||
 | 
			
		||||
    if (getlastDTC(true) < DTC_LAST_DTC)
 | 
			
		||||
    {
 | 
			
		||||
        globals.systemStatus = sysStat_Error;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        if (globals.systemStatus == sysStat_Error)
 | 
			
		||||
        {
 | 
			
		||||
            globals.systemStatus = preserverSysStatusError;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Add traveled Distance in mm
 | 
			
		||||
    PersistenceData.TravelDistance_highRes_mm += add_milimeters;
 | 
			
		||||
    PersistenceData.odometer_mm += add_milimeters;
 | 
			
		||||
    if (PersistenceData.odometer_mm >= 1000000)
 | 
			
		||||
    {
 | 
			
		||||
        PersistenceData.odometer++;
 | 
			
		||||
        PersistenceData.odometer_mm = 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    switch (globals.systemStatus)
 | 
			
		||||
    {
 | 
			
		||||
    case sysStat_Startup:
 | 
			
		||||
        if (millis() > STARTUP_DELAY)
 | 
			
		||||
        {
 | 
			
		||||
            globals.systemStatus = sysStat_Normal;
 | 
			
		||||
            globals.resumeStatus = sysStat_Normal;
 | 
			
		||||
        }
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case sysStat_Normal:
 | 
			
		||||
        if (PersistenceData.TravelDistance_highRes_mm / 1000 > LubeConfig.DistancePerLube_Default)
 | 
			
		||||
        {
 | 
			
		||||
            LubePulse();
 | 
			
		||||
            PersistenceData.TravelDistance_highRes_mm = 0;
 | 
			
		||||
        }
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case sysStat_Rain:
 | 
			
		||||
        if (PersistenceData.TravelDistance_highRes_mm / 1000 > LubeConfig.DistancePerLube_Rain)
 | 
			
		||||
        {
 | 
			
		||||
            LubePulse();
 | 
			
		||||
            PersistenceData.TravelDistance_highRes_mm = 0;
 | 
			
		||||
        }
 | 
			
		||||
        break;
 | 
			
		||||
    case sysStat_Purge:
 | 
			
		||||
        if (globals.purgePulses > 0)
 | 
			
		||||
        {
 | 
			
		||||
            if (lubePulseTimestamp + LUBE_PULSE_PAUSE_MS < millis())
 | 
			
		||||
            {
 | 
			
		||||
                LubePulse();
 | 
			
		||||
                globals.purgePulses--;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            globals.systemStatus = globals.resumeStatus;
 | 
			
		||||
        }
 | 
			
		||||
        break;
 | 
			
		||||
    case sysStat_Error:
 | 
			
		||||
    case sysStat_Shutdown:
 | 
			
		||||
    default:
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    switch (globals.systemStatus)
 | 
			
		||||
    {
 | 
			
		||||
    case sysStat_Normal:
 | 
			
		||||
        strcpy(globals.systemStatustxt, PSTR("Normal"));
 | 
			
		||||
        break;
 | 
			
		||||
    case sysStat_Purge:
 | 
			
		||||
        strcpy(globals.systemStatustxt, PSTR("Purge"));
 | 
			
		||||
        break;
 | 
			
		||||
    case sysStat_Rain:
 | 
			
		||||
        strcpy(globals.systemStatustxt, PSTR("Rain"));
 | 
			
		||||
        break;
 | 
			
		||||
    case sysStat_Startup:
 | 
			
		||||
        strcpy(globals.systemStatustxt, PSTR("Startup"));
 | 
			
		||||
        break;
 | 
			
		||||
    case sysStat_Error:
 | 
			
		||||
        strcpy(globals.systemStatustxt, PSTR("Error"));
 | 
			
		||||
        break;
 | 
			
		||||
    case sysStat_Shutdown:
 | 
			
		||||
        strcpy(globals.systemStatustxt, PSTR("Shutdown"));
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // maintain Pin-State of Lube-Pump
 | 
			
		||||
    if (lubePulseTimestamp > millis())
 | 
			
		||||
        digitalWrite(GPIO_PUMP, HIGH);
 | 
			
		||||
    else
 | 
			
		||||
        digitalWrite(GPIO_PUMP, LOW);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void LubePulse()
 | 
			
		||||
{
 | 
			
		||||
    lubePulseTimestamp = millis() + LUBE_PULSE_LENGHT_MS;
 | 
			
		||||
    if (PersistenceData.tankRemain_µl < LubeConfig.amountPerDose_µl)
 | 
			
		||||
        PersistenceData.tankRemain_µl = 0;
 | 
			
		||||
    else
 | 
			
		||||
        PersistenceData.tankRemain_µl = PersistenceData.tankRemain_µl - LubeConfig.amountPerDose_µl;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										18
									
								
								Software/src/lubeapp.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,18 @@
 | 
			
		||||
#ifndef _LUBEAPP_H_
 | 
			
		||||
#define _LUBEAPP_H_
 | 
			
		||||
 | 
			
		||||
#include <Arduino.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include "config.h"
 | 
			
		||||
#include "common.h"
 | 
			
		||||
#include "globals.h"
 | 
			
		||||
#include "dtc.h"
 | 
			
		||||
 | 
			
		||||
#define LUBE_PULSE_LENGHT_MS 160
 | 
			
		||||
#define LUBE_PULSE_PAUSE_MS 100
 | 
			
		||||
#define STARTUP_DELAY 5000
 | 
			
		||||
 | 
			
		||||
void RunLubeApp(uint32_t add_milimeters);
 | 
			
		||||
void LubePulse();
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
							
								
								
									
										769
									
								
								Software/src/main.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,769 @@
 | 
			
		||||
#include <Arduino.h>
 | 
			
		||||
#include <Wire.h>
 | 
			
		||||
#include <U8g2lib.h>
 | 
			
		||||
#include <ESP8266WiFi.h>
 | 
			
		||||
#include <ArduinoOTA.h>
 | 
			
		||||
 | 
			
		||||
#include <FastLED.h>
 | 
			
		||||
#include <Ticker.h>
 | 
			
		||||
 | 
			
		||||
#include "common.h"
 | 
			
		||||
 | 
			
		||||
#include "lubeapp.h"
 | 
			
		||||
#include "webui.h"
 | 
			
		||||
#include "config.h"
 | 
			
		||||
#include "globals.h"
 | 
			
		||||
#ifdef FEATURE_ENABLE_CAN
 | 
			
		||||
#include "can.h"
 | 
			
		||||
#endif
 | 
			
		||||
#ifdef FEATURE_ENABLE_GPS
 | 
			
		||||
#include "gps.h"
 | 
			
		||||
#endif
 | 
			
		||||
#include "dtc.h"
 | 
			
		||||
 | 
			
		||||
#ifdef FEATURE_ENABLE_REMOTE_DEBUG
 | 
			
		||||
#include <RemoteDebug.h>
 | 
			
		||||
#include "rmtdbghelp.h"
 | 
			
		||||
#else
 | 
			
		||||
#define debugV Serial.println
 | 
			
		||||
#define debugE Serial.println
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifdef FEATURE_ENABLE_WIFI_CLIENT
 | 
			
		||||
#include <ESP8266WiFiMulti.h>
 | 
			
		||||
 | 
			
		||||
const char *ssid = QUOTE(WIFI_SSID);
 | 
			
		||||
const char *password = QUOTE(WIFI_PASSWORD);
 | 
			
		||||
const uint32_t connectTimeoutMs = 5000;
 | 
			
		||||
 | 
			
		||||
ESP8266WiFiMulti wifiMulti;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
bool startSetupMode = false;
 | 
			
		||||
 | 
			
		||||
Globals_t globals;
 | 
			
		||||
uint32_t TravelDistance_highRes;
 | 
			
		||||
volatile uint32_t wheel_pulse = 0;
 | 
			
		||||
 | 
			
		||||
U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(-1);
 | 
			
		||||
CRGB leds[1];
 | 
			
		||||
 | 
			
		||||
// Function-Prototypes
 | 
			
		||||
void IRAM_ATTR trigger_ISR();
 | 
			
		||||
void LED_Process(uint8_t override = false, CRGB setColor = CRGB::White);
 | 
			
		||||
void Display_Process();
 | 
			
		||||
void Button_Process();
 | 
			
		||||
void toggleWiFiAP(boolean shutdown = false);
 | 
			
		||||
void SystemShutdown();
 | 
			
		||||
uint32_t Process_Impulse_WheelSpeed();
 | 
			
		||||
void EEPROMCyclicPDS_callback();
 | 
			
		||||
void initGlobals();
 | 
			
		||||
 | 
			
		||||
#ifdef FEATURE_ENABLE_REMOTE_DEBUG
 | 
			
		||||
RemoteDebug Debug;
 | 
			
		||||
String IpAddress2String(const IPAddress &ipAddress);
 | 
			
		||||
void processCmdRemoteDebug();
 | 
			
		||||
void RemoteDebug_formatCFG();
 | 
			
		||||
void RemoteDebug_formatPersistence();
 | 
			
		||||
void RemotDebug_printSystemInfo();
 | 
			
		||||
void RemoteDebug_printWifiInfo();
 | 
			
		||||
void RemoteDebug_CheckEEPOM();
 | 
			
		||||
void RemoteDebug_dumpConfig();
 | 
			
		||||
void RemoteDebug_dumpPersistance();
 | 
			
		||||
void RemoteDebug_ShowDTCs();
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifdef FEATURE_ENABLE_WIFI_CLIENT
 | 
			
		||||
void wifiMaintainConnectionTicker_callback();
 | 
			
		||||
Ticker WiFiMaintainConnectionTicker(wifiMaintainConnectionTicker_callback, 1000, 0, MILLIS);
 | 
			
		||||
#endif
 | 
			
		||||
Ticker EEPROMCyclicPDSTicker(EEPROMCyclicPDS_callback, 60000, 0, MILLIS);
 | 
			
		||||
 | 
			
		||||
void setup()
 | 
			
		||||
{
 | 
			
		||||
  system_update_cpu_freq(SYS_CPU_80MHZ);
 | 
			
		||||
  snprintf(globals.DeviceName, 32, HOST_NAME, ESP.getChipId());
 | 
			
		||||
  WiFi.persistent(false);
 | 
			
		||||
 | 
			
		||||
  ClearAllDTC(); // Init DTC-Storage
 | 
			
		||||
 | 
			
		||||
#ifdef FEATURE_ENABLE_WIFI_CLIENT
 | 
			
		||||
  WiFi.mode(WIFI_STA);
 | 
			
		||||
  WiFi.setHostname(globals.DeviceName);
 | 
			
		||||
  wifiMulti.addAP(QUOTE(WIFI_SSID), QUOTE(WIFI_PASSWORD));
 | 
			
		||||
  WiFiMaintainConnectionTicker.start();
 | 
			
		||||
#else
 | 
			
		||||
  WiFi.mode(WIFI_OFF);
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
  Serial.begin(115200);
 | 
			
		||||
  Serial.setDebugOutput(true);
 | 
			
		||||
 | 
			
		||||
  Serial.println("Souko's ChainLube Mk1");
 | 
			
		||||
  Serial.println(globals.DeviceName);
 | 
			
		||||
 | 
			
		||||
  InitEEPROM();
 | 
			
		||||
  GetConfig_EEPROM();
 | 
			
		||||
  GetPersistence_EEPROM();
 | 
			
		||||
 | 
			
		||||
  u8x8.begin();
 | 
			
		||||
  u8x8.setFont(u8x8_font_chroma48medium8_r);
 | 
			
		||||
 | 
			
		||||
  FastLED.addLeds<WS2811, GPIO_LED, GRB>(leds, 1); // GRB ordering is assumed
 | 
			
		||||
 | 
			
		||||
  switch (LubeConfig.SpeedSource)
 | 
			
		||||
  {
 | 
			
		||||
  case SOURCE_IMPULSE:
 | 
			
		||||
    pinMode(GPIO_TRIGGER, INPUT_PULLUP);
 | 
			
		||||
    attachInterrupt(digitalPinToInterrupt(GPIO_TRIGGER), trigger_ISR, FALLING);
 | 
			
		||||
    break;
 | 
			
		||||
#ifdef FEATURE_ENABLE_GPS
 | 
			
		||||
  case SOURCE_GPS:
 | 
			
		||||
    Init_GPS();
 | 
			
		||||
    break;
 | 
			
		||||
#endif
 | 
			
		||||
  case SOURCE_TIME:
 | 
			
		||||
 | 
			
		||||
    break;
 | 
			
		||||
#ifdef FEATURE_ENABLE_CAN
 | 
			
		||||
  case SOURCE_CAN:
 | 
			
		||||
    Init_CAN();
 | 
			
		||||
    break;
 | 
			
		||||
#endif
 | 
			
		||||
  default:
 | 
			
		||||
    debugE("Source Setting N/A");
 | 
			
		||||
    break;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  pinMode(GPIO_BUTTON, INPUT_PULLUP);
 | 
			
		||||
  pinMode(GPIO_PUMP, OUTPUT);
 | 
			
		||||
 | 
			
		||||
#ifdef FEATURE_ENABLE_REMOTE_DEBUG
 | 
			
		||||
  Debug.begin(globals.DeviceName);
 | 
			
		||||
  Debug.setResetCmdEnabled(true);
 | 
			
		||||
  Debug.showProfiler(false);
 | 
			
		||||
  Debug.showColors(true);
 | 
			
		||||
  Debug.setPassword(QUOTE(ADMIN_PASSWORD));
 | 
			
		||||
  Debug.setSerialEnabled(true);
 | 
			
		||||
  Debug.showDebugLevel(true);
 | 
			
		||||
 | 
			
		||||
  Debug.setHelpProjectsCmds(helpCmd);
 | 
			
		||||
  Debug.setCallBackProjectCmds(&processCmdRemoteDebug);
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
  ArduinoOTA.setPort(8266);
 | 
			
		||||
  ArduinoOTA.setHostname(globals.DeviceName);
 | 
			
		||||
  ArduinoOTA.setPassword(QUOTE(ADMIN_PASSWORD));
 | 
			
		||||
 | 
			
		||||
  ArduinoOTA.onStart([]()
 | 
			
		||||
                     {
 | 
			
		||||
                       u8x8.clearDisplay();
 | 
			
		||||
                       u8x8.drawString(0, 0, "OTA-Update");
 | 
			
		||||
                       u8x8.refreshDisplay(); });
 | 
			
		||||
 | 
			
		||||
  ArduinoOTA.onProgress([](unsigned int progress, unsigned int total)
 | 
			
		||||
                        {
 | 
			
		||||
                          static bool refreshed = false;
 | 
			
		||||
                          if (!refreshed)
 | 
			
		||||
                          {
 | 
			
		||||
                            u8x8.clearDisplay();
 | 
			
		||||
                            refreshed = true;
 | 
			
		||||
                            u8x8.drawString(0, 0, "OTA Upload");
 | 
			
		||||
                          }
 | 
			
		||||
                          uint32_t percent = progress / (total / 100);
 | 
			
		||||
                          u8x8.setCursor(0, 1);
 | 
			
		||||
                          u8x8.printf("%d %%", percent);
 | 
			
		||||
                          u8x8.refreshDisplay(); });
 | 
			
		||||
 | 
			
		||||
  ArduinoOTA.onEnd([]()
 | 
			
		||||
                   {
 | 
			
		||||
                     u8x8.clearDisplay();
 | 
			
		||||
                     u8x8.drawString(0, 0, "OTA-Restart");
 | 
			
		||||
                     u8x8.refreshDisplay(); });
 | 
			
		||||
 | 
			
		||||
  ArduinoOTA.begin();
 | 
			
		||||
 | 
			
		||||
  u8x8.clearDisplay();
 | 
			
		||||
  u8x8.drawString(0, 0, "KTM ChainLube V1");
 | 
			
		||||
  u8x8.refreshDisplay();
 | 
			
		||||
 | 
			
		||||
  initWebUI();
 | 
			
		||||
  initGlobals();
 | 
			
		||||
  EEPROMCyclicPDSTicker.start();
 | 
			
		||||
  Serial.println("Setup Done");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void loop()
 | 
			
		||||
{
 | 
			
		||||
  uint32_t wheelDistance = 0;
 | 
			
		||||
 | 
			
		||||
  switch (LubeConfig.SpeedSource)
 | 
			
		||||
  {
 | 
			
		||||
  case SOURCE_IMPULSE:
 | 
			
		||||
    wheelDistance = Process_Impulse_WheelSpeed();
 | 
			
		||||
    break;
 | 
			
		||||
#ifdef FEATURE_ENABLE_CAN
 | 
			
		||||
  case SOURCE_CAN:
 | 
			
		||||
    wheelDistance = Process_CAN_WheelSpeed();
 | 
			
		||||
    break;
 | 
			
		||||
#endif
 | 
			
		||||
  case SOURCE_TIME:
 | 
			
		||||
    break;
 | 
			
		||||
#ifdef FEATURE_ENABLE_GPS
 | 
			
		||||
  case SOURCE_GPS:
 | 
			
		||||
    wheelDistance = Process_GPS_WheelSpeed();
 | 
			
		||||
    break;
 | 
			
		||||
#endif
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  RunLubeApp(wheelDistance);
 | 
			
		||||
  EEPROMCyclicPDSTicker.update();
 | 
			
		||||
  Display_Process();
 | 
			
		||||
  Button_Process();
 | 
			
		||||
  LED_Process();
 | 
			
		||||
  EEPROM_Process();
 | 
			
		||||
 | 
			
		||||
  ArduinoOTA.handle();
 | 
			
		||||
#ifdef FEATURE_ENABLE_REMOTE_DEBUG
 | 
			
		||||
  Debug.handle();
 | 
			
		||||
#endif
 | 
			
		||||
#ifdef FEATURE_ENABLE_WIFI_CLIENT
 | 
			
		||||
  WiFiMaintainConnectionTicker.update();
 | 
			
		||||
#endif
 | 
			
		||||
  if (globals.systemStatus == sysStat_Shutdown)
 | 
			
		||||
    SystemShutdown();
 | 
			
		||||
  yield();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
String IpAddress2String(const IPAddress &ipAddress)
 | 
			
		||||
{
 | 
			
		||||
  return String(ipAddress[0]) + String(".") +
 | 
			
		||||
         String(ipAddress[1]) + String(".") +
 | 
			
		||||
         String(ipAddress[2]) + String(".") +
 | 
			
		||||
         String(ipAddress[3]);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void initGlobals()
 | 
			
		||||
{
 | 
			
		||||
  globals.purgePulses = 0;
 | 
			
		||||
  globals.requestEEAction = EE_IDLE;
 | 
			
		||||
  globals.resumeStatus = sysStat_Normal;
 | 
			
		||||
  globals.systemStatus = sysStat_Startup;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#ifdef FEATURE_ENABLE_REMOTE_DEBUG
 | 
			
		||||
void processCmdRemoteDebug()
 | 
			
		||||
{
 | 
			
		||||
  String lastCmd = Debug.getLastCommand();
 | 
			
		||||
 | 
			
		||||
  if (lastCmd == "sysinfo")
 | 
			
		||||
    RemotDebug_printSystemInfo();
 | 
			
		||||
  else if (lastCmd == "netinfo")
 | 
			
		||||
    RemoteDebug_printWifiInfo();
 | 
			
		||||
  else if (lastCmd == "formatCFG")
 | 
			
		||||
    RemoteDebug_formatCFG();
 | 
			
		||||
  else if (lastCmd == "formatPDS")
 | 
			
		||||
    RemoteDebug_formatPersistence();
 | 
			
		||||
  else if (lastCmd == "checkEE")
 | 
			
		||||
    RemoteDebug_CheckEEPOM();
 | 
			
		||||
  else if (lastCmd == "dumpEE1k")
 | 
			
		||||
    dumpEEPROM(0, 1024);
 | 
			
		||||
  else if (lastCmd == "dumpEE")
 | 
			
		||||
    dumpEEPROM(0, EEPROM_SIZE_BYTES);
 | 
			
		||||
  else if (lastCmd == "resetPageEE")
 | 
			
		||||
    MovePersistencePage_EEPROM(true);
 | 
			
		||||
  else if (lastCmd == "dumpCFG")
 | 
			
		||||
    RemoteDebug_dumpConfig();
 | 
			
		||||
  else if (lastCmd == "dumpPDS")
 | 
			
		||||
    RemoteDebug_dumpPersistance();
 | 
			
		||||
  else if (lastCmd == "saveEE")
 | 
			
		||||
    StoreConfig_EEPROM();
 | 
			
		||||
  else if (lastCmd == "showdtc")
 | 
			
		||||
    RemoteDebug_ShowDTCs();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void RemoteDebug_formatCFG()
 | 
			
		||||
{
 | 
			
		||||
  debugA("Formatting Config-EEPROM and reseting to default");
 | 
			
		||||
  FormatConfig_EEPROM();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void RemoteDebug_formatPersistence()
 | 
			
		||||
{
 | 
			
		||||
  debugA("Formatting Persistence-EEPROM and reseting to default");
 | 
			
		||||
  FormatPersistence_EEPROM();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void RemotDebug_printSystemInfo()
 | 
			
		||||
{
 | 
			
		||||
  debugA("Souko's ChainOiler Mk1");
 | 
			
		||||
  debugA("Hostname: %s", globals.DeviceName);
 | 
			
		||||
 | 
			
		||||
  FlashMode_t ideMode = ESP.getFlashChipMode();
 | 
			
		||||
  debugA("Sdk version: %s", ESP.getSdkVersion());
 | 
			
		||||
  debugA("Core Version: %s", ESP.getCoreVersion().c_str());
 | 
			
		||||
  debugA("Boot Version: %u", ESP.getBootVersion());
 | 
			
		||||
  debugA("Boot Mode: %u", ESP.getBootMode());
 | 
			
		||||
  debugA("CPU Frequency: %u MHz", ESP.getCpuFreqMHz());
 | 
			
		||||
  debugA("Reset reason: %s", ESP.getResetReason().c_str());
 | 
			
		||||
  debugA("Flash Size: %d", ESP.getFlashChipRealSize());
 | 
			
		||||
  debugA("Flash Size IDE: %d", ESP.getFlashChipSize());
 | 
			
		||||
  debugA("Flash ide mode:  %s", (ideMode == FM_QIO ? "QIO" : ideMode == FM_QOUT ? "QOUT"
 | 
			
		||||
                                                         : ideMode == FM_DIO    ? "DIO"
 | 
			
		||||
                                                         : ideMode == FM_DOUT   ? "DOUT"
 | 
			
		||||
                                                                                : "UNKNOWN"));
 | 
			
		||||
  debugA("OTA-Pass: %s", QUOTE(ADMIN_PASSWORD));
 | 
			
		||||
  debugA("Git-Revison: %s", GIT_REV);
 | 
			
		||||
  debugA("Sw-Version: %d.%02d", SW_VERSION_MAJOR, SW_VERSION_MINOR);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void RemoteDebug_dumpConfig()
 | 
			
		||||
{
 | 
			
		||||
  debugA("DistancePerLube_Default: %d", LubeConfig.DistancePerLube_Default);
 | 
			
		||||
  debugA("DistancePerLube_Rain: %d", LubeConfig.DistancePerLube_Rain);
 | 
			
		||||
  debugA("tankCapacity_ml: %d", LubeConfig.tankCapacity_ml);
 | 
			
		||||
  debugA("amountPerDose_µl: %d", LubeConfig.amountPerDose_µl);
 | 
			
		||||
  debugA("TankRemindAtPercentage: %d", LubeConfig.TankRemindAtPercentage);
 | 
			
		||||
  debugA("PulsePerRevolution: %d", LubeConfig.PulsePerRevolution);
 | 
			
		||||
  debugA("TireWidth_mm: %d", LubeConfig.TireWidth_mm);
 | 
			
		||||
  debugA("TireWidthHeight_Ratio: %d", LubeConfig.TireWidth_mm);
 | 
			
		||||
  debugA("RimDiameter_Inch: %d", LubeConfig.RimDiameter_Inch);
 | 
			
		||||
  debugA("DistancePerRevolution_mm: %d", LubeConfig.DistancePerRevolution_mm);
 | 
			
		||||
  debugA("BleedingPulses: %d", LubeConfig.BleedingPulses);
 | 
			
		||||
  debugA("SpeedSource: %d", LubeConfig.SpeedSource);
 | 
			
		||||
#ifdef FEATURE_ENABLE_GPS
 | 
			
		||||
  debugA("GPSBaudRate: %d", LubeConfig.GPSBaudRate);
 | 
			
		||||
#endif
 | 
			
		||||
#ifdef FEATURE_ENABLE_CAN
 | 
			
		||||
  debugA("CANSource: %d", LubeConfig.CANSource);
 | 
			
		||||
#endif
 | 
			
		||||
  debugA("checksum: 0x%08X", LubeConfig.checksum);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void RemoteDebug_dumpPersistance()
 | 
			
		||||
{
 | 
			
		||||
  debugA("writeCycleCounter: %d", PersistenceData.writeCycleCounter);
 | 
			
		||||
  debugA("tankRemain_µl: %d", PersistenceData.tankRemain_µl);
 | 
			
		||||
  debugA("TravelDistance_highRes_mm: %d", PersistenceData.TravelDistance_highRes_mm);
 | 
			
		||||
  debugA("checksum: %d", PersistenceData.checksum);
 | 
			
		||||
  debugA("PSD Adress: 0x%04X", getPersistanceAddress());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void RemoteDebug_printWifiInfo()
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void RemoteDebug_CheckEEPOM()
 | 
			
		||||
{
 | 
			
		||||
  uint32_t checksum = PersistenceData.checksum;
 | 
			
		||||
  PersistenceData.checksum = 0;
 | 
			
		||||
 | 
			
		||||
  if (Checksum_EEPROM((uint8_t *)&PersistenceData, sizeof(PersistenceData)) == checksum)
 | 
			
		||||
  {
 | 
			
		||||
    debugA("PersistenceData EEPROM Checksum OK\n");
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    debugA("PersistenceData EEPROM Checksum BAD\n");
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  PersistenceData.checksum = checksum;
 | 
			
		||||
 | 
			
		||||
  checksum = LubeConfig.checksum;
 | 
			
		||||
  LubeConfig.checksum = 0;
 | 
			
		||||
 | 
			
		||||
  if (Checksum_EEPROM((uint8_t *)&LubeConfig, sizeof(LubeConfig)) == checksum)
 | 
			
		||||
  {
 | 
			
		||||
    debugA("LubeConfig EEPROM Checksum OK\n");
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    debugA("LubeConfig EEPROM Checksum BAD\n");
 | 
			
		||||
  }
 | 
			
		||||
  LubeConfig.checksum = checksum;
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifdef FEATURE_ENABLE_WIFI_CLIENT
 | 
			
		||||
void wifiMaintainConnectionTicker_callback()
 | 
			
		||||
{
 | 
			
		||||
  static uint32_t WiFiFailCount = 0;
 | 
			
		||||
  const uint32_t WiFiFailMax = 20;
 | 
			
		||||
 | 
			
		||||
  if (wifiMulti.run(connectTimeoutMs) == WL_CONNECTED)
 | 
			
		||||
  {
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    if (WiFiFailCount < WiFiFailMax)
 | 
			
		||||
    {
 | 
			
		||||
      WiFiFailCount++;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
      debugV("WiFi not connected! - Start AP");
 | 
			
		||||
      toggleWiFiAP();
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
void EEPROMCyclicPDS_callback()
 | 
			
		||||
{
 | 
			
		||||
  StorePersistence_EEPROM();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void trigger_ISR()
 | 
			
		||||
{
 | 
			
		||||
  wheel_pulse++;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void LED_Process(uint8_t override, CRGB SetColor)
 | 
			
		||||
{
 | 
			
		||||
  typedef enum
 | 
			
		||||
  {
 | 
			
		||||
    LED_Startup,
 | 
			
		||||
    LED_Normal,
 | 
			
		||||
    LED_Confirm_Normal,
 | 
			
		||||
    LED_Rain,
 | 
			
		||||
    LED_Confirm_Rain,
 | 
			
		||||
    LED_Purge,
 | 
			
		||||
    LED_Error,
 | 
			
		||||
    LED_Override
 | 
			
		||||
  } tLED_Status;
 | 
			
		||||
 | 
			
		||||
  static tSystem_Status oldSysStatus = sysStat_Startup;
 | 
			
		||||
  static tLED_Status LED_Status = LED_Startup;
 | 
			
		||||
  static CRGB LED_override_color = 0;
 | 
			
		||||
  static tLED_Status LED_ResumeOverrideStatus = LED_Startup;
 | 
			
		||||
 | 
			
		||||
  uint8_t color = 0;
 | 
			
		||||
  uint32_t timer = 0;
 | 
			
		||||
  static uint32_t timestamp = 0;
 | 
			
		||||
  timer = millis();
 | 
			
		||||
 | 
			
		||||
  if (override == 1)
 | 
			
		||||
  {
 | 
			
		||||
    if (LED_Status != LED_Override)
 | 
			
		||||
    {
 | 
			
		||||
      LED_ResumeOverrideStatus = LED_Status;
 | 
			
		||||
      debugV("Override LED_Status");
 | 
			
		||||
    }
 | 
			
		||||
    LED_Status = LED_Override;
 | 
			
		||||
    LED_override_color = SetColor;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (override == 2)
 | 
			
		||||
  {
 | 
			
		||||
    if (LED_Status == LED_Override)
 | 
			
		||||
    {
 | 
			
		||||
      LED_Status = LED_ResumeOverrideStatus;
 | 
			
		||||
      debugV("Resume LED_Status");
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (oldSysStatus != globals.systemStatus)
 | 
			
		||||
  {
 | 
			
		||||
    switch (globals.systemStatus)
 | 
			
		||||
    {
 | 
			
		||||
    case sysStat_Startup:
 | 
			
		||||
      LED_Status = LED_Startup;
 | 
			
		||||
      debugV("sysStat: Startup");
 | 
			
		||||
      break;
 | 
			
		||||
    case sysStat_Normal:
 | 
			
		||||
      timestamp = timer + 3500;
 | 
			
		||||
      LED_Status = LED_Confirm_Normal;
 | 
			
		||||
      debugV("sysStat: Normal");
 | 
			
		||||
      break;
 | 
			
		||||
    case sysStat_Rain:
 | 
			
		||||
      timestamp = timer + 3500;
 | 
			
		||||
      LED_Status = LED_Confirm_Rain;
 | 
			
		||||
      debugV("sysStat: Rain");
 | 
			
		||||
      break;
 | 
			
		||||
    case sysStat_Purge:
 | 
			
		||||
      LED_Status = LED_Purge;
 | 
			
		||||
      debugV("sysStat: Purge");
 | 
			
		||||
      break;
 | 
			
		||||
    case sysStat_Error:
 | 
			
		||||
      LED_Status = LED_Error;
 | 
			
		||||
      debugV("sysStat: Error");
 | 
			
		||||
      break;
 | 
			
		||||
    case sysStat_Shutdown:
 | 
			
		||||
    default:
 | 
			
		||||
      break;
 | 
			
		||||
    }
 | 
			
		||||
    oldSysStatus = globals.systemStatus;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  uint32_t percentage = PersistenceData.tankRemain_µl / (LubeConfig.tankCapacity_ml * 10);
 | 
			
		||||
 | 
			
		||||
  switch (LED_Status)
 | 
			
		||||
  {
 | 
			
		||||
  case LED_Startup:
 | 
			
		||||
    FastLED.setBrightness(255);
 | 
			
		||||
 | 
			
		||||
    if (percentage < LubeConfig.TankRemindAtPercentage)
 | 
			
		||||
      leds[0] = CRGB::OrangeRed;
 | 
			
		||||
    else
 | 
			
		||||
      leds[0] = CRGB::White;
 | 
			
		||||
    break;
 | 
			
		||||
 | 
			
		||||
  case LED_Confirm_Normal:
 | 
			
		||||
    FastLED.setBrightness(255);
 | 
			
		||||
    leds[0] = timer % 250 > 125 ? CRGB(0, 255, 0) : CRGB(0, 4, 0);
 | 
			
		||||
    if (timestamp < timer)
 | 
			
		||||
    {
 | 
			
		||||
      LED_Status = LED_Normal;
 | 
			
		||||
      FastLED.setBrightness(64);
 | 
			
		||||
      debugV("LED_Status: Confirm -> Normal");
 | 
			
		||||
    }
 | 
			
		||||
    break;
 | 
			
		||||
 | 
			
		||||
  case LED_Normal:
 | 
			
		||||
    if (timer % 2000 > 1950)
 | 
			
		||||
      leds[0] = CRGB(0, 255, 0);
 | 
			
		||||
    else if (WiFi.getMode() != WIFI_OFF && timer % 2000 > 1800 && timer % 2000 < 1850)
 | 
			
		||||
      leds[0] = CRGB(255, 128, 0);
 | 
			
		||||
    else
 | 
			
		||||
      leds[0] = CRGB(0, 4, 0);
 | 
			
		||||
    break;
 | 
			
		||||
 | 
			
		||||
  case LED_Confirm_Rain:
 | 
			
		||||
    FastLED.setBrightness(255);
 | 
			
		||||
    leds[0] = timer % 250 > 125 ? CRGB(0, 0, 255) : CRGB(0, 0, 4);
 | 
			
		||||
    if (timestamp < timer)
 | 
			
		||||
    {
 | 
			
		||||
      LED_Status = LED_Rain;
 | 
			
		||||
      FastLED.setBrightness(64);
 | 
			
		||||
      debugV("LED_Status: Confirm -> Rain");
 | 
			
		||||
    }
 | 
			
		||||
    break;
 | 
			
		||||
 | 
			
		||||
  case LED_Rain:
 | 
			
		||||
    if (timer % 2000 > 1950)
 | 
			
		||||
      leds[0] = CRGB(0, 0, 255);
 | 
			
		||||
    else if (WiFi.getMode() != WIFI_OFF && timer % 2000 > 1800 && timer % 2000 < 1850)
 | 
			
		||||
      leds[0] = CRGB(255, 128, 0);
 | 
			
		||||
    else
 | 
			
		||||
      leds[0] = CRGB(0, 0, 4);
 | 
			
		||||
    break;
 | 
			
		||||
 | 
			
		||||
  case LED_Purge:
 | 
			
		||||
    timer = timer % 500;
 | 
			
		||||
    color = timer / 2;
 | 
			
		||||
    leds[0] = CRGB::DeepPink;
 | 
			
		||||
    if (timer < 250)
 | 
			
		||||
      FastLED.setBrightness(color);
 | 
			
		||||
    else
 | 
			
		||||
      FastLED.setBrightness(250 - color);
 | 
			
		||||
    break;
 | 
			
		||||
 | 
			
		||||
  case LED_Error:
 | 
			
		||||
    leds[0] = timer % 500 > 250 ? CRGB::Red : CRGB::Black;
 | 
			
		||||
    break;
 | 
			
		||||
 | 
			
		||||
  case LED_Override:
 | 
			
		||||
    leds[0] = LED_override_color;
 | 
			
		||||
    break;
 | 
			
		||||
 | 
			
		||||
  default:
 | 
			
		||||
    break;
 | 
			
		||||
  }
 | 
			
		||||
  FastLED.show();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Display_Process()
 | 
			
		||||
{
 | 
			
		||||
  static tSystem_Status oldSysStatus = sysStat_Startup;
 | 
			
		||||
 | 
			
		||||
  if (oldSysStatus != globals.systemStatus)
 | 
			
		||||
  {
 | 
			
		||||
    u8x8.clearDisplay();
 | 
			
		||||
    u8x8.drawString(0, 0, "KTM ChainLube V1");
 | 
			
		||||
    oldSysStatus = globals.systemStatus;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  u8x8.setCursor(0, 1);
 | 
			
		||||
  uint32_t DistRemain = globals.systemStatus == sysStat_Normal ? LubeConfig.DistancePerLube_Default : LubeConfig.DistancePerLube_Rain;
 | 
			
		||||
  DistRemain -= TravelDistance_highRes / 1000;
 | 
			
		||||
  u8x8.printf(PSTR("Mode: %10s\n"), globals.systemStatustxt);
 | 
			
		||||
  if (globals.systemStatus == sysStat_Error)
 | 
			
		||||
  {
 | 
			
		||||
    u8x8.printf(PSTR("last DTC: %6d\n"), getlastDTC(false));
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    u8x8.printf(PSTR("next Lube: %4dm\n"), DistRemain);
 | 
			
		||||
    u8x8.printf(PSTR("Tank: %8dml\n"), PersistenceData.tankRemain_µl / 1000);
 | 
			
		||||
    u8x8.printf(PSTR("WiFi: %10s\n"), (WiFi.getMode() == WIFI_AP ? "AP" : WiFi.getMode() == WIFI_OFF ? "OFF"
 | 
			
		||||
                                                                      : WiFi.getMode() == WIFI_STA   ? "CLIENT"
 | 
			
		||||
                                                                                                     : "UNKNOWN"));
 | 
			
		||||
    u8x8.printf(PSTR("Source: %8s\n"), SpeedSourceString[LubeConfig.SpeedSource]);
 | 
			
		||||
    u8x8.printf("%s\n", WiFi.localIP().toString().c_str());
 | 
			
		||||
  }
 | 
			
		||||
  u8x8.refreshDisplay();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Button_Process()
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
#define BUTTON_ACTION_DELAY_TOGGLEMODE 500
 | 
			
		||||
#define BUTTON_ACTION_DELAY_PURGE 3500
 | 
			
		||||
#define BUTTON_ACTION_DELAY_WIFI 6500
 | 
			
		||||
#define BUTTON_ACTION_DELAY_NOTHING 9500
 | 
			
		||||
 | 
			
		||||
  typedef enum buttonAction_e
 | 
			
		||||
  {
 | 
			
		||||
    BTN_INACTIVE,
 | 
			
		||||
    BTN_NOTHING,
 | 
			
		||||
    BTN_TOGGLEMODE,
 | 
			
		||||
    BTN_TOGGLEWIFI,
 | 
			
		||||
    BTN_STARTPURGE
 | 
			
		||||
  } buttonAction_t;
 | 
			
		||||
 | 
			
		||||
  static uint32_t buttonTimestamp = 0;
 | 
			
		||||
  static buttonAction_t buttonAction = BTN_INACTIVE;
 | 
			
		||||
 | 
			
		||||
  if (digitalRead(GPIO_BUTTON) == LOW)
 | 
			
		||||
  {
 | 
			
		||||
 | 
			
		||||
    if (buttonTimestamp == 0)
 | 
			
		||||
      buttonTimestamp = millis();
 | 
			
		||||
 | 
			
		||||
    if (buttonTimestamp + BUTTON_ACTION_DELAY_NOTHING < millis())
 | 
			
		||||
    {
 | 
			
		||||
      LED_Process(1, CRGB::White);
 | 
			
		||||
      buttonAction = BTN_NOTHING;
 | 
			
		||||
    }
 | 
			
		||||
    else if (buttonTimestamp + BUTTON_ACTION_DELAY_WIFI < millis())
 | 
			
		||||
    {
 | 
			
		||||
      LED_Process(1, CRGB::Yellow);
 | 
			
		||||
      buttonAction = BTN_TOGGLEWIFI;
 | 
			
		||||
    }
 | 
			
		||||
    else if (buttonTimestamp + BUTTON_ACTION_DELAY_PURGE < millis())
 | 
			
		||||
    {
 | 
			
		||||
      LED_Process(1, CRGB::DeepPink);
 | 
			
		||||
      buttonAction = BTN_STARTPURGE;
 | 
			
		||||
    }
 | 
			
		||||
    else if (buttonTimestamp + BUTTON_ACTION_DELAY_TOGGLEMODE < millis())
 | 
			
		||||
    {
 | 
			
		||||
      CRGB color = globals.systemStatus == sysStat_Normal ? CRGB::Blue : CRGB::Green;
 | 
			
		||||
      LED_Process(1, color);
 | 
			
		||||
      buttonAction = BTN_TOGGLEMODE;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    if (buttonAction != BTN_INACTIVE)
 | 
			
		||||
    {
 | 
			
		||||
      switch (buttonAction)
 | 
			
		||||
      {
 | 
			
		||||
      case BTN_TOGGLEWIFI:
 | 
			
		||||
        toggleWiFiAP();
 | 
			
		||||
        debugV("Starting WiFi AP");
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
      case BTN_STARTPURGE:
 | 
			
		||||
        globals.systemStatus = sysStat_Purge;
 | 
			
		||||
        globals.purgePulses = LubeConfig.BleedingPulses;
 | 
			
		||||
        debugV("Starting Purge");
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
      case BTN_TOGGLEMODE:
 | 
			
		||||
        switch (globals.systemStatus)
 | 
			
		||||
        {
 | 
			
		||||
        case sysStat_Normal:
 | 
			
		||||
          globals.systemStatus = sysStat_Rain;
 | 
			
		||||
          globals.resumeStatus = sysStat_Rain;
 | 
			
		||||
          break;
 | 
			
		||||
 | 
			
		||||
        case sysStat_Rain:
 | 
			
		||||
          globals.systemStatus = sysStat_Normal;
 | 
			
		||||
          globals.resumeStatus = sysStat_Normal;
 | 
			
		||||
          break;
 | 
			
		||||
        default:
 | 
			
		||||
          break;
 | 
			
		||||
        }
 | 
			
		||||
        debugV("Toggling Mode");
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
      case BTN_NOTHING:
 | 
			
		||||
      default:
 | 
			
		||||
        debugV("Nothing or invalid");
 | 
			
		||||
        break;
 | 
			
		||||
      }
 | 
			
		||||
      LED_Process(2);
 | 
			
		||||
    }
 | 
			
		||||
    buttonAction = BTN_INACTIVE;
 | 
			
		||||
    buttonTimestamp = 0;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void toggleWiFiAP(boolean shutdown)
 | 
			
		||||
{
 | 
			
		||||
  if (WiFi.getMode() != WIFI_OFF)
 | 
			
		||||
  {
 | 
			
		||||
    WiFi.mode(WIFI_OFF);
 | 
			
		||||
    debugV("WiFi turned off");
 | 
			
		||||
#ifdef FEATURE_ENABLE_WIFI_CLIENT
 | 
			
		||||
    WiFiMaintainConnectionTicker.stop();
 | 
			
		||||
#endif
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    WiFi.mode(WIFI_AP);
 | 
			
		||||
    WiFi.softAPConfig(IPAddress(WIFI_AP_IP_GW), IPAddress(WIFI_AP_IP_GW), IPAddress(255, 255, 255, 0));
 | 
			
		||||
    WiFi.softAP(globals.DeviceName, QUOTE(WIFI_AP_PASSWORD));
 | 
			
		||||
#ifdef FEATURE_ENABLE_WIFI_CLIENT
 | 
			
		||||
    WiFiMaintainConnectionTicker.stop();
 | 
			
		||||
    debugV("WiFi AP started, stopped Maintain-Timer");
 | 
			
		||||
#else
 | 
			
		||||
    debugV("WiFi AP started");
 | 
			
		||||
#endif
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void SystemShutdown()
 | 
			
		||||
{
 | 
			
		||||
  StoreConfig_EEPROM();
 | 
			
		||||
  ESP.restart();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint32_t Process_Impulse_WheelSpeed()
 | 
			
		||||
{
 | 
			
		||||
  uint32_t add_milimeters;
 | 
			
		||||
  // Calculate traveled Distance in mm
 | 
			
		||||
  add_milimeters = (wheel_pulse * (LubeConfig.DistancePerRevolution_mm / LubeConfig.PulsePerRevolution));
 | 
			
		||||
  wheel_pulse = 0;
 | 
			
		||||
 | 
			
		||||
  return add_milimeters;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void RemoteDebug_ShowDTCs()
 | 
			
		||||
{
 | 
			
		||||
  char buff_timestamp[16]; // Format: DD-hh:mm:ss:xxx
 | 
			
		||||
  char buff_active[9];
 | 
			
		||||
 | 
			
		||||
  for (uint32_t i = 0; i < MAX_DTC_STORAGE; i++)
 | 
			
		||||
  {
 | 
			
		||||
    if (DTCStorage[i].Number < DTC_LAST_DTC)
 | 
			
		||||
    {
 | 
			
		||||
      sprintf(buff_timestamp, "%02d-%02d:%02d:%02d:%03d",
 | 
			
		||||
              DTCStorage[i].timestamp / 86400000,    // Days
 | 
			
		||||
              DTCStorage[i].timestamp / 360000 % 24, // Hours
 | 
			
		||||
              DTCStorage[i].timestamp / 60000 % 60,  // Minutes
 | 
			
		||||
              DTCStorage[i].timestamp / 1000 % 60,   // Seconds
 | 
			
		||||
              DTCStorage[i].timestamp % 1000);       // milliseconds
 | 
			
		||||
 | 
			
		||||
      if (DTCStorage[i].active == DTC_ACTIVE)
 | 
			
		||||
        strcpy(buff_active, "active");
 | 
			
		||||
      else if (DTCStorage[i].active == DTC_PREVIOUS)
 | 
			
		||||
        strcpy(buff_active, "previous");
 | 
			
		||||
      else
 | 
			
		||||
        strcpy(buff_active, "none");
 | 
			
		||||
 | 
			
		||||
      debugA("%s \t %6d \t %s", buff_timestamp, DTCStorage[i].Number, buff_active);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										12
									
								
								Software/src/rmtdbghelp.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,12 @@
 | 
			
		||||
const char helpCmd[] = "sysinfo     - System Info\r\n"
 | 
			
		||||
                       "netinfo     - WiFi Info\r\n"
 | 
			
		||||
                       "formatPDS   - Format Persistence EEPROM Data\r\n"
 | 
			
		||||
                       "formatCFG   - Format Configuration EEPROM Data\r\n"
 | 
			
		||||
                       "checkEE     - Check EEPROM with checksum\r\n"
 | 
			
		||||
                       "dumpEE1k    - dump the first 1kb of EEPROM to Serial\r\n"
 | 
			
		||||
                       "dumpEE      - dump the whole EPPROM to Serial\r\n"
 | 
			
		||||
                       "resetPageEE - Reset the PersistenceData Page\r\n"
 | 
			
		||||
                       "dumpCFG     - print Config struct\r\n"
 | 
			
		||||
                       "dumpPDS     - print PersistanceStruct\r\n"
 | 
			
		||||
                       "saveEE      - save EE-Data\r\n"
 | 
			
		||||
                       "showdtc     - Show all DTCs\r\n";
 | 
			
		||||
							
								
								
									
										350
									
								
								Software/src/webui.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,350 @@
 | 
			
		||||
#include "webui.h"
 | 
			
		||||
 | 
			
		||||
AsyncWebServer webServer(80);
 | 
			
		||||
 | 
			
		||||
const char *PARAM_MESSAGE = "message";
 | 
			
		||||
 | 
			
		||||
String processor(const String &var);
 | 
			
		||||
void WebserverPOST_Callback(AsyncWebServerRequest *request);
 | 
			
		||||
void WebserverNotFound_Callback(AsyncWebServerRequest *request);
 | 
			
		||||
void Webserver_Callback(AsyncWebServerRequest *request);
 | 
			
		||||
void WebserverFirmwareUpdate_Callback(AsyncWebServerRequest *request, const String &filename, size_t index, uint8_t *data, size_t len, bool final);
 | 
			
		||||
uint32_t GetFlashVersion();
 | 
			
		||||
 | 
			
		||||
void initWebUI()
 | 
			
		||||
{
 | 
			
		||||
  if (!LittleFS.begin())
 | 
			
		||||
  {
 | 
			
		||||
    Serial.println("An Error has occurred while mounting LittleFS");
 | 
			
		||||
    MaintainDTC(DTC_FLASHFS_ERROR, true);
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  MDNS.begin(globals.DeviceName);
 | 
			
		||||
  MDNS.addService("telnet", "tcp", 23);
 | 
			
		||||
  MDNS.addService("http", "tcp", 80);
 | 
			
		||||
 | 
			
		||||
  webServer.serveStatic("/static/", LittleFS, "/static/").setCacheControl("max-age=360000");
 | 
			
		||||
  webServer.on("/", HTTP_GET, [](AsyncWebServerRequest *request)
 | 
			
		||||
               { request->redirect("/index.htm"); });
 | 
			
		||||
  webServer.onNotFound(WebserverNotFound_Callback);
 | 
			
		||||
  webServer.on("/index.htm", HTTP_GET, Webserver_Callback);
 | 
			
		||||
  webServer.on("/post.htm", HTTP_POST, WebserverPOST_Callback);
 | 
			
		||||
  webServer.on(
 | 
			
		||||
      "/doUpdate", HTTP_POST, [](AsyncWebServerRequest *request) {}, WebserverFirmwareUpdate_Callback);
 | 
			
		||||
 | 
			
		||||
  webServer.begin();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
String processor(const String &var)
 | 
			
		||||
{
 | 
			
		||||
  if (var == "TANK_REMAIN_CAPACITY")
 | 
			
		||||
    return String((PersistenceData.tankRemain_µl / 10) / LubeConfig.tankCapacity_ml);
 | 
			
		||||
  if (var == "LUBE_DISTANCE_NORMAL")
 | 
			
		||||
    return String(LubeConfig.DistancePerLube_Default);
 | 
			
		||||
  if (var == "LUBE_DISTANCE_RAIN")
 | 
			
		||||
    return String(LubeConfig.DistancePerLube_Rain);
 | 
			
		||||
  if (var == "TANK_CAPACITY")
 | 
			
		||||
    return String(LubeConfig.tankCapacity_ml);
 | 
			
		||||
  if (var == "AMOUNT_PER_DOSE")
 | 
			
		||||
    return String(LubeConfig.amountPerDose_µl);
 | 
			
		||||
  if (var == "TANK_REMIND")
 | 
			
		||||
    return String(LubeConfig.TankRemindAtPercentage);
 | 
			
		||||
  if (var == "PULSE_PER_REV")
 | 
			
		||||
    return String(LubeConfig.PulsePerRevolution);
 | 
			
		||||
  if (var == "TIRE_WIDTH_MM")
 | 
			
		||||
    return String(LubeConfig.TireWidth_mm);
 | 
			
		||||
  if (var == "TIRE_RATIO")
 | 
			
		||||
    return String(LubeConfig.TireWidthHeight_Ratio);
 | 
			
		||||
  if (var == "RIM_DIAMETER")
 | 
			
		||||
    return String(LubeConfig.RimDiameter_Inch);
 | 
			
		||||
  if (var == "DISTANCE_PER_REV")
 | 
			
		||||
    return String(LubeConfig.DistancePerRevolution_mm);
 | 
			
		||||
  if (var == "BLEEDING_PULSES")
 | 
			
		||||
    return String(LubeConfig.BleedingPulses);
 | 
			
		||||
  if (var == "SPEED_SOURCE")
 | 
			
		||||
    return String(SpeedSourceString[LubeConfig.SpeedSource]);
 | 
			
		||||
#ifdef FEATURE_ENABLE_GPS
 | 
			
		||||
  if (var == "GPS_BAUD")
 | 
			
		||||
    return String(GPSBaudRateString[LubeConfig.GPSBaudRate]);
 | 
			
		||||
#endif
 | 
			
		||||
#ifdef FEATURE_ENABLE_CAN
 | 
			
		||||
  if (var == "CAN_SOURCE")
 | 
			
		||||
    return String(CANSourceString[LubeConfig.CANSource]);
 | 
			
		||||
#endif
 | 
			
		||||
  if (var == "CONFIG_CHECKSUM")
 | 
			
		||||
  {
 | 
			
		||||
    char buffer[7];
 | 
			
		||||
    sprintf(buffer, "0x%04X", LubeConfig.checksum);
 | 
			
		||||
    return String(buffer);
 | 
			
		||||
  }
 | 
			
		||||
  if (var == "WRITE_CYCLE_COUNT")
 | 
			
		||||
    return String(PersistenceData.writeCycleCounter);
 | 
			
		||||
  if (var == "PERSISTENCE_MARKER")
 | 
			
		||||
    return String(getPersistanceAddress());
 | 
			
		||||
  if (var == "TANK_REMAIN_UL")
 | 
			
		||||
    return String(PersistenceData.tankRemain_µl);
 | 
			
		||||
  if (var == "TRAVEL_DISTANCE_HIGHRES")
 | 
			
		||||
    return String(PersistenceData.TravelDistance_highRes_mm);
 | 
			
		||||
  if (var == "ODOMETER")
 | 
			
		||||
    return String(PersistenceData.odometer);
 | 
			
		||||
  if (var == "ODOMETER_M")
 | 
			
		||||
    return String(PersistenceData.odometer_mm / 1000);
 | 
			
		||||
  if (var == "PERSISTANCE_CHECKSUM")
 | 
			
		||||
  {
 | 
			
		||||
    char buffer[7];
 | 
			
		||||
    sprintf(buffer, "0x%04X", PersistenceData.checksum);
 | 
			
		||||
    return String(buffer);
 | 
			
		||||
  }
 | 
			
		||||
  if (var == "SHOW_IMPULSE_SETTINGS")
 | 
			
		||||
    return LubeConfig.SpeedSource == SOURCE_IMPULSE ? "" : "hidden";
 | 
			
		||||
#ifdef FEATURE_ENABLE_CAN
 | 
			
		||||
  if (var == "SHOW_CAN_SETTINGS")
 | 
			
		||||
    return LubeConfig.SpeedSource == SOURCE_CAN ? "" : "hidden";
 | 
			
		||||
#endif
 | 
			
		||||
#ifdef FEATURE_ENABLE_GPS
 | 
			
		||||
  if (var == "SHOW_GPS_SETTINGS")
 | 
			
		||||
    return LubeConfig.SpeedSource == SOURCE_GPS ? "" : "hidden";
 | 
			
		||||
#endif
 | 
			
		||||
  if (var == "SHOW_DTC_TABLE")
 | 
			
		||||
    return globals.systemStatus == sysStat_Error ? "" : "hidden";
 | 
			
		||||
 | 
			
		||||
  if (var == "DTC_TABLE")
 | 
			
		||||
  {
 | 
			
		||||
    String temp;
 | 
			
		||||
    char buff_timestamp[16]; // Format: DD-hh:mm:ss:xxx
 | 
			
		||||
 | 
			
		||||
    for (uint32_t i = 0; i < MAX_DTC_STORAGE; i++)
 | 
			
		||||
    {
 | 
			
		||||
      if (DTCStorage[i].Number < DTC_LAST_DTC)
 | 
			
		||||
      {
 | 
			
		||||
        sprintf(buff_timestamp, "%02d-%02d:%02d:%02d:%03d",
 | 
			
		||||
                DTCStorage[i].timestamp / 86400000,    // Days
 | 
			
		||||
                DTCStorage[i].timestamp / 360000 % 24, // Hours
 | 
			
		||||
                DTCStorage[i].timestamp / 60000 % 60,  // Minutes
 | 
			
		||||
                DTCStorage[i].timestamp / 1000 % 60,   // Seconds
 | 
			
		||||
                DTCStorage[i].timestamp % 1000);       // milliseconds
 | 
			
		||||
 | 
			
		||||
        temp = "<tr><td>" + String(buff_timestamp);
 | 
			
		||||
        temp = temp + "</td><td>" + String(DTCStorage[i].Number) + "</td><td>";
 | 
			
		||||
 | 
			
		||||
        if (DTCStorage[i].active == DTC_ACTIVE)
 | 
			
		||||
          temp = temp + "active";
 | 
			
		||||
        else if (DTCStorage[i].active == DTC_PREVIOUS)
 | 
			
		||||
          temp = temp + "previous";
 | 
			
		||||
        else
 | 
			
		||||
          temp = temp + "none";
 | 
			
		||||
 | 
			
		||||
        temp = temp + "</td></tr>";
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    return temp;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (var == "SOURCE_SELECT_OPTIONS")
 | 
			
		||||
  {
 | 
			
		||||
    String temp;
 | 
			
		||||
    for (uint32_t i = 0; i < SpeedSourceString_Elements; i++)
 | 
			
		||||
    {
 | 
			
		||||
      String selected = LubeConfig.SpeedSource == i ? " selected " : "";
 | 
			
		||||
      temp = temp + "<option value=\"" + i + "\"" + selected + ">" + SpeedSourceString[i] + "</option>";
 | 
			
		||||
    }
 | 
			
		||||
    return temp;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
#ifdef FEATURE_ENABLE_CAN
 | 
			
		||||
  if (var == "CANSOURCE_SELECT_OPTIONS")
 | 
			
		||||
  {
 | 
			
		||||
    String temp;
 | 
			
		||||
    for (uint32_t i = 0; i < CANSourceString_Elements; i++)
 | 
			
		||||
    {
 | 
			
		||||
      String selected = LubeConfig.CANSource == i ? " selected " : "";
 | 
			
		||||
      temp = temp + "<option value=\"" + i + "\"" + selected + ">" + CANSourceString[i] + "</option>";
 | 
			
		||||
    }
 | 
			
		||||
    return temp;
 | 
			
		||||
  }
 | 
			
		||||
#endif
 | 
			
		||||
#ifdef FEATURE_EABLE_GPS
 | 
			
		||||
  if (var == "GPSBAUD_SELECT_OPTIONS")
 | 
			
		||||
  {
 | 
			
		||||
    String temp;
 | 
			
		||||
    for (uint32_t i = 0; i < GPSBaudRateString_Elements; i++)
 | 
			
		||||
    {
 | 
			
		||||
      String selected = LubeConfig.GPSBaudRate == i ? " selected " : "";
 | 
			
		||||
      temp = temp + "<option value=\"" + i + "\"" + selected + ">" + GPSBaudRateString[i] + "</option>";
 | 
			
		||||
    }
 | 
			
		||||
    return temp;
 | 
			
		||||
  }
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
  if (var == "SYSTEM_STATUS")
 | 
			
		||||
    return String(globals.systemStatustxt);
 | 
			
		||||
  if (var == "SW_VERSION")
 | 
			
		||||
  {
 | 
			
		||||
    char buffer[7];
 | 
			
		||||
    sprintf(buffer, "%d.%02d", SW_VERSION_MAJOR, SW_VERSION_MINOR);
 | 
			
		||||
    return String(buffer);
 | 
			
		||||
  }
 | 
			
		||||
  if (var == "FS_VERSION")
 | 
			
		||||
    return String(GetFlashVersion());
 | 
			
		||||
 | 
			
		||||
  if (var == "PLACEHOLDER")
 | 
			
		||||
    return "placeholder";
 | 
			
		||||
 | 
			
		||||
  return String();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Webserver_Callback(AsyncWebServerRequest *request)
 | 
			
		||||
{
 | 
			
		||||
  request->send(LittleFS, "/index.htm", "text/html", false, processor);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void WebserverPOST_Callback(AsyncWebServerRequest *request)
 | 
			
		||||
{
 | 
			
		||||
  request->send(LittleFS, "/post.htm", "text/html", false, processor);
 | 
			
		||||
 | 
			
		||||
  Serial.print("POST:\n");
 | 
			
		||||
  int paramsNr = request->params();
 | 
			
		||||
  for (int i = 0; i < paramsNr; i++)
 | 
			
		||||
  {
 | 
			
		||||
    AsyncWebParameter *p = request->getParam(i);
 | 
			
		||||
    Serial.printf("%s : %s\n", p->name().c_str(), p->value().c_str());
 | 
			
		||||
 | 
			
		||||
    // begin: POST Form Source Changed
 | 
			
		||||
    if (p->name() == "sourceselect")
 | 
			
		||||
    {
 | 
			
		||||
      SpeedSource_t temp = (SpeedSource_t)p->value().toInt();
 | 
			
		||||
      Serial.printf("temp: %d", temp);
 | 
			
		||||
      Serial.printf("SpeedSource: %d", LubeConfig.SpeedSource);
 | 
			
		||||
      if (LubeConfig.SpeedSource != temp)
 | 
			
		||||
      {
 | 
			
		||||
        LubeConfig.SpeedSource = temp;
 | 
			
		||||
        globals.systemStatus = sysStat_Shutdown;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    // end: POST Form Source Changed
 | 
			
		||||
    // begin: POST Form Source Pulse Settings
 | 
			
		||||
    if (p->name() == "tirewidth")
 | 
			
		||||
      LubeConfig.TireWidth_mm = p->value().toInt();
 | 
			
		||||
    if (p->name() == "tireratio")
 | 
			
		||||
      LubeConfig.TireWidthHeight_Ratio = p->value().toInt();
 | 
			
		||||
    if (p->name() == "tiredia")
 | 
			
		||||
      LubeConfig.RimDiameter_Inch = p->value().toInt();
 | 
			
		||||
    if (p->name() == "pulserev")
 | 
			
		||||
      LubeConfig.PulsePerRevolution = p->value().toInt();
 | 
			
		||||
    if (p->name() == "pulsesave")
 | 
			
		||||
      globals.requestEEAction = EE_CFG_SAVE;
 | 
			
		||||
      // end: POST Form Source Pulse Settings
 | 
			
		||||
#ifdef FEATURE_EABLE_GPS
 | 
			
		||||
    // begin: POST Form Source GPS Settings
 | 
			
		||||
    if (p->name() == "gpsbaud")
 | 
			
		||||
      LubeConfig.GPSBaudRate = (GPSBaudRate_t)p->value().toInt();
 | 
			
		||||
    if (p->name() == "gpssave")
 | 
			
		||||
      globals.requestEEAction = EE_CFG_SAVE;
 | 
			
		||||
// end: POST Form Source GPS Settings
 | 
			
		||||
#endif
 | 
			
		||||
#ifdef FEATURE_EABLE_CAN
 | 
			
		||||
    // begin: POST Form Source CAN Settings
 | 
			
		||||
    if (p->name() == "cansource")
 | 
			
		||||
      LubeConfig.CANSource = (CANSource_t)p->value().toInt();
 | 
			
		||||
    if (p->name() == "cansave")
 | 
			
		||||
      globals.requestEEAction = EE_CFG_SAVE;
 | 
			
		||||
// end: POST Form Source CAN Settings
 | 
			
		||||
#endif
 | 
			
		||||
    // begin: POST Form Lubrication
 | 
			
		||||
    if (p->name() == "lubedistancenormal")
 | 
			
		||||
      LubeConfig.DistancePerLube_Default = p->value().toInt();
 | 
			
		||||
    if (p->name() == "lubedistancerain")
 | 
			
		||||
      LubeConfig.DistancePerLube_Rain = p->value().toInt();
 | 
			
		||||
    if (p->name() == "lubesave")
 | 
			
		||||
      globals.requestEEAction = EE_CFG_SAVE;
 | 
			
		||||
    // end: POST Form Lubrication
 | 
			
		||||
    // begin: POST Form Oiltank
 | 
			
		||||
    if (p->name() == "tankcap")
 | 
			
		||||
      LubeConfig.tankCapacity_ml = p->value().toInt();
 | 
			
		||||
    if (p->name() == "tankwarn")
 | 
			
		||||
      LubeConfig.TankRemindAtPercentage = p->value().toInt();
 | 
			
		||||
    if (p->name() == "pumppulse")
 | 
			
		||||
      LubeConfig.amountPerDose_µl = p->value().toInt();
 | 
			
		||||
    if (p->name() == "oilsave")
 | 
			
		||||
      globals.requestEEAction = EE_CFG_SAVE;
 | 
			
		||||
    // end: POST Form Oiltank
 | 
			
		||||
    // begin: POST Form Maintenance
 | 
			
		||||
    if (p->name() == "purgepulse")
 | 
			
		||||
      LubeConfig.BleedingPulses = p->value().toInt();
 | 
			
		||||
    if (p->name() == "maintsave")
 | 
			
		||||
      globals.requestEEAction = EE_CFG_SAVE;
 | 
			
		||||
    if (p->name() == "resettank")
 | 
			
		||||
    {
 | 
			
		||||
      PersistenceData.tankRemain_µl = LubeConfig.tankCapacity_ml * 1000;
 | 
			
		||||
      globals.requestEEAction = EE_PDS_SAVE;
 | 
			
		||||
    }
 | 
			
		||||
    // end: POST Form Maintenance
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void WebserverNotFound_Callback(AsyncWebServerRequest *request)
 | 
			
		||||
{
 | 
			
		||||
  request->send(404, "text/html", "Not found");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint32_t GetFlashVersion()
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
  char buffer[20];
 | 
			
		||||
  File this_file = LittleFS.open("version", "r");
 | 
			
		||||
  if (!this_file)
 | 
			
		||||
  { // failed to open the file, retrn empty result
 | 
			
		||||
    return 0;
 | 
			
		||||
  }
 | 
			
		||||
  while (this_file.available())
 | 
			
		||||
  {
 | 
			
		||||
    this_file.readBytesUntil('\r', buffer, sizeof(buffer));
 | 
			
		||||
  }
 | 
			
		||||
  this_file.close();
 | 
			
		||||
  return atoi(buffer);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void WebserverFirmwareUpdate_Callback(AsyncWebServerRequest *request, const String &filename, size_t index, uint8_t *data, size_t len, bool final)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
  if (!index)
 | 
			
		||||
  {
 | 
			
		||||
    Serial.println("Update");
 | 
			
		||||
    size_t content_len = request->contentLength();
 | 
			
		||||
    // if filename includes spiffs, update the spiffs partition
 | 
			
		||||
    int cmd = (filename.indexOf(".fs") > -1) ? U_FS : U_FLASH;
 | 
			
		||||
    Update.runAsync(true);
 | 
			
		||||
    if (!Update.begin(content_len, cmd))
 | 
			
		||||
    {
 | 
			
		||||
      Update.printError(Serial);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (Update.write(data, len) != len)
 | 
			
		||||
  {
 | 
			
		||||
    Update.printError(Serial);
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    Serial.printf("Progress: %d%%\n", (Update.progress() * 100) / Update.size());
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (final)
 | 
			
		||||
  {
 | 
			
		||||
    AsyncWebServerResponse *response = request->beginResponse(302, "text/plain", "Please wait while the device reboots");
 | 
			
		||||
    response->addHeader("Refresh", "20");
 | 
			
		||||
    response->addHeader("Location", "/");
 | 
			
		||||
    request->send(response);
 | 
			
		||||
    if (!Update.end(true))
 | 
			
		||||
    {
 | 
			
		||||
      Update.printError(Serial);
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
      Serial.println("Update complete");
 | 
			
		||||
      Serial.flush();
 | 
			
		||||
      ESP.restart();
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										19
									
								
								Software/src/webui.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,19 @@
 | 
			
		||||
#ifndef _WEBUI_H_
 | 
			
		||||
#define _WEBUI_H_
 | 
			
		||||
 | 
			
		||||
#include <Arduino.h>
 | 
			
		||||
#include <FS.h>
 | 
			
		||||
#include <LittleFS.h>
 | 
			
		||||
#include <ESPAsyncTCP.h>
 | 
			
		||||
#include <ESPAsyncWebServer.h>
 | 
			
		||||
#include <Updater.h>
 | 
			
		||||
#include <ESP8266mDNS.h>
 | 
			
		||||
 | 
			
		||||
#include "config.h"
 | 
			
		||||
#include "globals.h"
 | 
			
		||||
#include "dtc.h"
 | 
			
		||||
#include "common.h"
 | 
			
		||||
 | 
			
		||||
void initWebUI();
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||