batt display, low batt shutdown, timeout shutdown
This commit is contained in:
6
README.txt
Normal file
6
README.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
flashing
|
||||
|
||||
macos:
|
||||
brewl install stlink
|
||||
|
||||
st-flash --reset --freq=4M write firmware.bin 0x8000000
|
||||
74
lib/BatterySense/src/Battery.cpp
Normal file
74
lib/BatterySense/src/Battery.cpp
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
Battery.cpp - Battery library
|
||||
Copyright (c) 2014 Roberto Lo Giacco.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "Battery.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
Battery::Battery(uint16_t minVoltage, uint16_t maxVoltage, uint8_t sensePin) {
|
||||
this->sensePin = sensePin;
|
||||
this->activationPin = 0xFF;
|
||||
this->minVoltage = minVoltage;
|
||||
this->maxVoltage = maxVoltage;
|
||||
}
|
||||
|
||||
void Battery::begin(uint16_t refVoltage, float dividerRatio, mapFn_t mapFunction) {
|
||||
this->refVoltage = refVoltage;
|
||||
this->dividerRatio = dividerRatio;
|
||||
pinMode(this->sensePin, INPUT);
|
||||
if (this->activationPin < 0xFF) {
|
||||
pinMode(this->activationPin, OUTPUT);
|
||||
}
|
||||
this->mapFunction = mapFunction ? mapFunction : &linear;
|
||||
}
|
||||
|
||||
void Battery::onDemand(uint8_t activationPin, uint8_t activationMode) {
|
||||
if (activationPin < 0xFF) {
|
||||
this->activationPin = activationPin;
|
||||
this->activationMode = activationMode;
|
||||
pinMode(this->activationPin, OUTPUT);
|
||||
digitalWrite(activationPin, !activationMode);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t Battery::level() {
|
||||
return this->level(this->voltage());
|
||||
}
|
||||
|
||||
uint8_t Battery::level(uint16_t voltage) {
|
||||
if (voltage <= minVoltage) {
|
||||
return 0;
|
||||
} else if (voltage >= maxVoltage) {
|
||||
return 100;
|
||||
} else {
|
||||
return (*mapFunction)(voltage, minVoltage, maxVoltage);
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t Battery::voltage() {
|
||||
if (activationPin != 0xFF) {
|
||||
digitalWrite(activationPin, activationMode);
|
||||
delayMicroseconds(10); // copes with slow switching activation circuits
|
||||
}
|
||||
analogRead(sensePin);
|
||||
delay(2); // allow the ADC to stabilize
|
||||
uint16_t reading = analogRead(sensePin) * dividerRatio * refVoltage / 1024;
|
||||
if (activationPin != 0xFF) {
|
||||
digitalWrite(activationPin, !activationMode);
|
||||
}
|
||||
return reading;
|
||||
}
|
||||
129
lib/BatterySense/src/Battery.h
Normal file
129
lib/BatterySense/src/Battery.h
Normal file
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
Battery.h - Battery library
|
||||
Copyright (c) 2014 Roberto Lo Giacco.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef BATTERY_H_
|
||||
#define BATTERY_H_
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
typedef uint8_t(*mapFn_t)(uint16_t, uint16_t, uint16_t);
|
||||
|
||||
class Battery {
|
||||
public:
|
||||
/**
|
||||
* Creates an instance to monitor battery voltage and level.
|
||||
* Initialization parameters depend on battery type and configuration.
|
||||
*
|
||||
* @param minVoltage is the voltage, expressed in millivolts, corresponding to an empty battery
|
||||
* @param maxVoltage is the voltage, expressed in millivolts, corresponding to a full battery
|
||||
* @param sensePin is the analog pin used for sensing the battery voltage
|
||||
*/
|
||||
Battery(uint16_t minVoltage, uint16_t maxVoltage, uint8_t sensePin);
|
||||
|
||||
/**
|
||||
* Initializes the library by optionally setting additional parameters.
|
||||
* To obtain the best results use a calibrated reference using the VoltageReference library or equivalent.
|
||||
*
|
||||
* @param refVoltage is the board reference voltage, expressed in millivolts
|
||||
* @param dividerRatio is the multiplier used to obtain the real battery voltage
|
||||
* @param mapFunction is a pointer to the function used to map the battery voltage to the remaining capacity percentage (defaults to linear mapping)
|
||||
*/
|
||||
void begin(uint16_t refVoltage, float dividerRatio, mapFn_t = 0);
|
||||
|
||||
/**
|
||||
* Enables on-demand activation of the sensing circuit to limit battery consumption.
|
||||
*
|
||||
* @param activationPin is the pin which will be turned HIGH or LOW before starting the battery sensing
|
||||
* @param activationMode is the optional value to set on the activationPin to enable battery sensing, defaults to LOW
|
||||
* useful when using a resistor divider to save on battery consumption, but it can be changed to HIGH in case
|
||||
* you are using a P-CH MOSFET or a PNP BJT
|
||||
*/
|
||||
void onDemand(uint8_t activationPin, uint8_t activationMode = LOW);
|
||||
|
||||
/**
|
||||
* Activation pin value disabling the on-demand feature.
|
||||
*/
|
||||
static const uint8_t ON_DEMAND_DISABLE = 0xFF;
|
||||
|
||||
/**
|
||||
* Returns the current battery level as a number between 0 and 100, with 0 indicating an empty battery and 100 a
|
||||
* full battery.
|
||||
*/
|
||||
uint8_t level();
|
||||
uint8_t level(uint16_t voltage);
|
||||
|
||||
/**
|
||||
* Returns the current battery voltage in millivolts.
|
||||
*/
|
||||
uint16_t voltage();
|
||||
|
||||
private:
|
||||
uint16_t refVoltage;
|
||||
uint16_t minVoltage;
|
||||
uint16_t maxVoltage;
|
||||
float dividerRatio;
|
||||
uint8_t sensePin;
|
||||
uint8_t activationPin;
|
||||
uint8_t activationMode;
|
||||
mapFn_t mapFunction;
|
||||
};
|
||||
|
||||
//
|
||||
// Plots of the functions below available at
|
||||
// https://www.desmos.com/calculator/x0esk5bsrk
|
||||
//
|
||||
|
||||
/**
|
||||
* Symmetric sigmoidal approximation
|
||||
* https://www.desmos.com/calculator/7m9lu26vpy
|
||||
*
|
||||
* c - c / (1 + k*x/v)^3
|
||||
*/
|
||||
static inline uint8_t sigmoidal(uint16_t voltage, uint16_t minVoltage, uint16_t maxVoltage) {
|
||||
// slow
|
||||
// uint8_t result = 110 - (110 / (1 + pow(1.468 * (voltage - minVoltage)/(maxVoltage - minVoltage), 6)));
|
||||
|
||||
// steep
|
||||
// uint8_t result = 102 - (102 / (1 + pow(1.621 * (voltage - minVoltage)/(maxVoltage - minVoltage), 8.1)));
|
||||
|
||||
// normal
|
||||
uint8_t result = 105 - (105 / (1 + pow(1.724 * (voltage - minVoltage)/(maxVoltage - minVoltage), 5.5)));
|
||||
return result >= 100 ? 100 : result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Asymmetric sigmoidal approximation
|
||||
* https://www.desmos.com/calculator/oyhpsu8jnw
|
||||
*
|
||||
* c - c / [1 + (k*x/v)^4.5]^3
|
||||
*/
|
||||
static inline uint8_t asigmoidal(uint16_t voltage, uint16_t minVoltage, uint16_t maxVoltage) {
|
||||
uint8_t result = 101 - (101 / pow(1 + pow(1.33 * (voltage - minVoltage)/(maxVoltage - minVoltage) ,4.5), 3));
|
||||
return result >= 100 ? 100 : result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Linear mapping
|
||||
* https://www.desmos.com/calculator/sowyhttjta
|
||||
*
|
||||
* x * 100 / v
|
||||
*/
|
||||
static inline uint8_t linear(uint16_t voltage, uint16_t minVoltage, uint16_t maxVoltage) {
|
||||
return (unsigned long)(voltage - minVoltage) * 100 / (maxVoltage - minVoltage);
|
||||
}
|
||||
#endif // BATTERY_H_
|
||||
@@ -196,6 +196,28 @@ X ~ 2 0 -150 50 U 50 50 1 1 P
|
||||
ENDDRAW
|
||||
ENDDEF
|
||||
#
|
||||
# Jumper_SolderJumper_2_Open
|
||||
#
|
||||
DEF Jumper_SolderJumper_2_Open JP 0 0 Y N 1 F N
|
||||
F0 "JP" 0 80 50 H V C CNN
|
||||
F1 "Jumper_SolderJumper_2_Open" 0 -100 50 H V C CNN
|
||||
F2 "" 0 0 50 H I C CNN
|
||||
F3 "" 0 0 50 H I C CNN
|
||||
$FPLIST
|
||||
SolderJumper*Open*
|
||||
$ENDFPLIST
|
||||
DRAW
|
||||
A -10 0 40 901 -901 0 1 0 N -10 40 -10 -40
|
||||
A -10 0 40 901 -901 0 1 0 F -10 40 -10 -40
|
||||
A 10 0 40 -899 899 0 1 0 N 10 -40 10 40
|
||||
A 10 0 40 -899 899 0 1 0 F 10 -40 10 40
|
||||
P 2 0 1 0 -10 40 -10 -40 N
|
||||
P 2 0 1 0 10 40 10 -40 N
|
||||
X A 1 -150 0 100 R 50 50 1 1 P
|
||||
X B 2 150 0 100 L 50 50 1 1 P
|
||||
ENDDRAW
|
||||
ENDDEF
|
||||
#
|
||||
# Regulator_Linear_TPS76333
|
||||
#
|
||||
DEF Regulator_Linear_TPS76333 U 0 10 Y Y 1 F N
|
||||
@@ -236,6 +258,38 @@ X 3 3 200 -100 100 L 50 50 1 1 P
|
||||
ENDDRAW
|
||||
ENDDEF
|
||||
#
|
||||
# Transistor_FET_BSS84
|
||||
#
|
||||
DEF Transistor_FET_BSS84 Q 0 20 Y N 1 F N
|
||||
F0 "Q" 200 75 50 H V L CNN
|
||||
F1 "Transistor_FET_BSS84" 200 0 50 H V L CNN
|
||||
F2 "Package_TO_SOT_SMD:SOT-23" 200 -75 50 H I L CIN
|
||||
F3 "" 0 0 50 H I L CNN
|
||||
ALIAS VP0610T BSS84 NTR2101P BSS83P Si2319CDS IRLML6401 IRLML6402 DMG2301L AO3401A IRLML9301 IRLML5203 Si2371EDS TSM2301ACX FDN340P
|
||||
$FPLIST
|
||||
SOT?23*
|
||||
$ENDFPLIST
|
||||
DRAW
|
||||
C 65 0 110 0 1 10 N
|
||||
C 100 -70 10 0 1 0 F
|
||||
C 100 70 10 0 1 0 F
|
||||
P 2 0 1 0 10 0 -100 0 N
|
||||
P 2 0 1 10 10 75 10 -75 N
|
||||
P 2 0 1 10 30 -50 30 -90 N
|
||||
P 2 0 1 10 30 20 30 -20 N
|
||||
P 2 0 1 10 30 90 30 50 N
|
||||
P 2 0 1 0 100 100 100 70 N
|
||||
P 3 0 1 0 100 -100 100 0 30 0 N
|
||||
P 4 0 1 0 30 70 130 70 130 -70 30 -70 N
|
||||
P 4 0 1 0 90 0 50 15 50 -15 90 0 F
|
||||
P 4 0 1 0 110 -20 115 -15 145 -15 150 -10 N
|
||||
P 4 0 1 0 130 -15 115 10 145 10 130 -15 N
|
||||
X G 1 -200 0 100 R 50 50 1 1 I
|
||||
X S 2 100 -200 100 U 50 50 1 1 P
|
||||
X D 3 100 200 100 D 50 50 1 1 P
|
||||
ENDDRAW
|
||||
ENDDEF
|
||||
#
|
||||
# dk_Barrel-Audio-Connectors_SJ1-3523N
|
||||
#
|
||||
DEF dk_Barrel-Audio-Connectors_SJ1-3523N CON 0 2 Y Y 1 F N
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,4 @@
|
||||
update=2021 March 23, Tuesday 22:13:16
|
||||
update=2021 March 26, Friday 20:53:07
|
||||
version=1
|
||||
last_client=kicad
|
||||
[general]
|
||||
@@ -38,31 +38,31 @@ MinViaDrill=0.3
|
||||
MinMicroViaDiameter=0.2
|
||||
MinMicroViaDrill=0.09999999999999999
|
||||
MinHoleToHole=0.25
|
||||
TrackWidth1=0.25
|
||||
TrackWidth1=0.254
|
||||
TrackWidth2=0.3048
|
||||
ViaDiameter1=0.8
|
||||
ViaDrill1=0.4
|
||||
dPairWidth1=0.2
|
||||
dPairGap1=0.25
|
||||
ViaDiameter1=0.8128
|
||||
ViaDrill1=0.4064
|
||||
dPairWidth1=0.2032
|
||||
dPairGap1=0.254
|
||||
dPairViaGap1=0.25
|
||||
SilkLineWidth=0.12
|
||||
SilkTextSizeV=1
|
||||
SilkTextSizeH=1
|
||||
SilkTextSizeThickness=0.15
|
||||
SilkLineWidth=0.127
|
||||
SilkTextSizeV=0.635
|
||||
SilkTextSizeH=0.635
|
||||
SilkTextSizeThickness=0.1016
|
||||
SilkTextItalic=0
|
||||
SilkTextUpright=1
|
||||
CopperLineWidth=0.2
|
||||
CopperTextSizeV=1.5
|
||||
CopperTextSizeH=1.5
|
||||
CopperTextThickness=0.3
|
||||
CopperLineWidth=0.2032
|
||||
CopperTextSizeV=0.635
|
||||
CopperTextSizeH=0.635
|
||||
CopperTextThickness=0.1016
|
||||
CopperTextItalic=0
|
||||
CopperTextUpright=1
|
||||
EdgeCutLineWidth=0.05
|
||||
CourtyardLineWidth=0.05
|
||||
OthersLineWidth=0.15
|
||||
OthersTextSizeV=1
|
||||
OthersTextSizeH=1
|
||||
OthersTextSizeThickness=0.15
|
||||
EdgeCutLineWidth=0.0508
|
||||
CourtyardLineWidth=0.0508
|
||||
OthersLineWidth=0.1524
|
||||
OthersTextSizeV=0.635
|
||||
OthersTextSizeH=0.635
|
||||
OthersTextSizeThickness=0.1016
|
||||
OthersTextItalic=0
|
||||
OthersTextUpright=1
|
||||
SolderMaskClearance=0
|
||||
@@ -238,23 +238,23 @@ Enabled=0
|
||||
[pcbnew/Netclasses]
|
||||
[pcbnew/Netclasses/Default]
|
||||
Name=Default
|
||||
Clearance=0.2
|
||||
TrackWidth=0.25
|
||||
ViaDiameter=0.8
|
||||
ViaDrill=0.4
|
||||
uViaDiameter=0.3
|
||||
uViaDrill=0.1
|
||||
dPairWidth=0.2
|
||||
dPairGap=0.25
|
||||
Clearance=0.2032
|
||||
TrackWidth=0.254
|
||||
ViaDiameter=0.8128
|
||||
ViaDrill=0.4064
|
||||
uViaDiameter=0.3048
|
||||
uViaDrill=0.1016
|
||||
dPairWidth=0.2032
|
||||
dPairGap=0.254
|
||||
dPairViaGap=0.25
|
||||
[pcbnew/Netclasses/1]
|
||||
Name=POWER
|
||||
Clearance=0.2
|
||||
Clearance=0.2032
|
||||
TrackWidth=0.3048
|
||||
ViaDiameter=0.8
|
||||
ViaDrill=0.4
|
||||
uViaDiameter=0.3
|
||||
uViaDrill=0.1
|
||||
dPairWidth=0.2
|
||||
dPairGap=0.25
|
||||
ViaDiameter=0.8128
|
||||
ViaDrill=0.4064
|
||||
uViaDiameter=0.3048
|
||||
uViaDrill=0.1016
|
||||
dPairWidth=0.2032
|
||||
dPairGap=0.254
|
||||
dPairViaGap=0.25
|
||||
|
||||
@@ -4,12 +4,12 @@ EELAYER END
|
||||
$Descr A4 11693 8268
|
||||
encoding utf-8
|
||||
Sheet 1 1
|
||||
Title ""
|
||||
Date ""
|
||||
Rev ""
|
||||
Comp ""
|
||||
Comment1 ""
|
||||
Comment2 ""
|
||||
Title "Leo-Led-truck"
|
||||
Date "2021-03-26"
|
||||
Rev "v1.1"
|
||||
Comp "hollandtricks.com"
|
||||
Comment1 "designed by Willem"
|
||||
Comment2 "www.electronicareparaties.nl"
|
||||
Comment3 ""
|
||||
Comment4 ""
|
||||
$EndDescr
|
||||
@@ -631,60 +631,60 @@ Wire Wire Line
|
||||
$Comp
|
||||
L Device:R R13
|
||||
U 1 1 60403C7A
|
||||
P 6250 2950
|
||||
F 0 "R13" H 6320 2996 50 0000 L CNN
|
||||
F 1 "100K" H 6320 2905 50 0000 L CNN
|
||||
F 2 "Resistor_SMD:R_0603_1608Metric" V 6180 2950 50 0001 C CNN
|
||||
F 3 "~" H 6250 2950 50 0001 C CNN
|
||||
1 6250 2950
|
||||
P 6750 5600
|
||||
F 0 "R13" H 6820 5646 50 0000 L CNN
|
||||
F 1 "10K" H 6820 5555 50 0000 L CNN
|
||||
F 2 "Resistor_SMD:R_0603_1608Metric" V 6680 5600 50 0001 C CNN
|
||||
F 3 "~" H 6750 5600 50 0001 C CNN
|
||||
1 6750 5600
|
||||
1 0 0 -1
|
||||
$EndComp
|
||||
$Comp
|
||||
L Device:R R12
|
||||
U 1 1 6040529B
|
||||
P 6250 2500
|
||||
F 0 "R12" H 6320 2546 50 0000 L CNN
|
||||
F 1 "220K" H 6320 2455 50 0000 L CNN
|
||||
F 2 "Resistor_SMD:R_0603_1608Metric" V 6180 2500 50 0001 C CNN
|
||||
F 3 "~" H 6250 2500 50 0001 C CNN
|
||||
1 6250 2500
|
||||
P 6750 5150
|
||||
F 0 "R12" H 6820 5196 50 0000 L CNN
|
||||
F 1 "4k7" H 6820 5105 50 0000 L CNN
|
||||
F 2 "Resistor_SMD:R_0603_1608Metric" V 6680 5150 50 0001 C CNN
|
||||
F 3 "~" H 6750 5150 50 0001 C CNN
|
||||
1 6750 5150
|
||||
1 0 0 -1
|
||||
$EndComp
|
||||
Text GLabel 6400 2700 2 50 Input ~ 0
|
||||
Text GLabel 6900 5350 2 50 Input ~ 0
|
||||
MEAS_VBATT
|
||||
Wire Wire Line
|
||||
6400 2700 6250 2700
|
||||
6900 5350 6750 5350
|
||||
Wire Wire Line
|
||||
6250 2700 6250 2650
|
||||
6750 5350 6750 5300
|
||||
Wire Wire Line
|
||||
6250 2800 6250 2700
|
||||
Connection ~ 6250 2700
|
||||
6750 5450 6750 5350
|
||||
Connection ~ 6750 5350
|
||||
$Comp
|
||||
L power:+BATT #PWR0117
|
||||
U 1 1 60416333
|
||||
P 6250 2150
|
||||
F 0 "#PWR0117" H 6250 2000 50 0001 C CNN
|
||||
F 1 "+BATT" H 6265 2323 50 0000 C CNN
|
||||
F 2 "" H 6250 2150 50 0001 C CNN
|
||||
F 3 "" H 6250 2150 50 0001 C CNN
|
||||
1 6250 2150
|
||||
P 6750 4250
|
||||
F 0 "#PWR0117" H 6750 4100 50 0001 C CNN
|
||||
F 1 "+BATT" H 6765 4423 50 0000 C CNN
|
||||
F 2 "" H 6750 4250 50 0001 C CNN
|
||||
F 3 "" H 6750 4250 50 0001 C CNN
|
||||
1 6750 4250
|
||||
1 0 0 -1
|
||||
$EndComp
|
||||
Wire Wire Line
|
||||
6250 2150 6250 2350
|
||||
6750 4800 6750 4900
|
||||
$Comp
|
||||
L power:GND #PWR0118
|
||||
U 1 1 6041C5AA
|
||||
P 6250 3300
|
||||
F 0 "#PWR0118" H 6250 3050 50 0001 C CNN
|
||||
F 1 "GND" H 6255 3127 50 0000 C CNN
|
||||
F 2 "" H 6250 3300 50 0001 C CNN
|
||||
F 3 "" H 6250 3300 50 0001 C CNN
|
||||
1 6250 3300
|
||||
P 6750 5950
|
||||
F 0 "#PWR0118" H 6750 5700 50 0001 C CNN
|
||||
F 1 "GND" H 6755 5777 50 0000 C CNN
|
||||
F 2 "" H 6750 5950 50 0001 C CNN
|
||||
F 3 "" H 6750 5950 50 0001 C CNN
|
||||
1 6750 5950
|
||||
1 0 0 -1
|
||||
$EndComp
|
||||
Wire Wire Line
|
||||
6250 3300 6250 3100
|
||||
6750 5950 6750 5850
|
||||
Text GLabel 5500 1350 2 50 Input ~ 0
|
||||
MEAS_VBATT
|
||||
Wire Wire Line
|
||||
@@ -847,18 +847,6 @@ Wire Wire Line
|
||||
Wire Wire Line
|
||||
2100 7300 2000 7300
|
||||
$Comp
|
||||
L Device:R R14
|
||||
U 1 1 60310C7E
|
||||
P 1350 7400
|
||||
F 0 "R14" V 1450 7400 50 0000 C CNN
|
||||
F 1 "0E" V 1550 7400 50 0000 C CNN
|
||||
F 2 "Resistor_SMD:R_0603_1608Metric" V 1280 7400 50 0001 C CNN
|
||||
F 3 "~" H 1350 7400 50 0001 C CNN
|
||||
F 4 "DNP" V 1350 7400 50 0000 C CNN "DNP"
|
||||
1 1350 7400
|
||||
0 1 1 0
|
||||
$EndComp
|
||||
$Comp
|
||||
L power:VBUS #PWR0124
|
||||
U 1 1 603121CD
|
||||
P 900 7100
|
||||
@@ -983,7 +971,6 @@ NoConn ~ 4200 2350
|
||||
NoConn ~ 4200 2850
|
||||
NoConn ~ 5300 2450
|
||||
NoConn ~ 5300 2550
|
||||
NoConn ~ 5300 2150
|
||||
NoConn ~ 5300 2850
|
||||
Wire Wire Line
|
||||
4800 3050 4800 3450
|
||||
@@ -1268,4 +1255,100 @@ Wire Wire Line
|
||||
Connection ~ 8900 5000
|
||||
Text GLabel 7450 1100 0 50 Input ~ 0
|
||||
DET1
|
||||
$Comp
|
||||
L Transistor_FET:BSS84 Q1
|
||||
U 1 1 605F95CF
|
||||
P 6650 4600
|
||||
F 0 "Q1" H 6854 4646 50 0000 L CNN
|
||||
F 1 "BSS84" H 6854 4555 50 0000 L CNN
|
||||
F 2 "Package_TO_SOT_SMD:SOT-23" H 6850 4525 50 0001 L CIN
|
||||
F 3 "http://assets.nexperia.com/documents/data-sheet/BSS84.pdf" H 6650 4600 50 0001 L CNN
|
||||
F 4 "FARNELL-1972673" H 6650 4600 50 0001 C CNN "ordercode"
|
||||
1 6650 4600
|
||||
1 0 0 -1
|
||||
$EndComp
|
||||
Wire Wire Line
|
||||
6750 4250 6750 4300
|
||||
$Comp
|
||||
L Device:R R14
|
||||
U 1 1 6060550D
|
||||
P 6100 4450
|
||||
F 0 "R14" H 6170 4496 50 0000 L CNN
|
||||
F 1 "100K" H 6170 4405 50 0000 L CNN
|
||||
F 2 "Resistor_SMD:R_0603_1608Metric" V 6030 4450 50 0001 C CNN
|
||||
F 3 "~" H 6100 4450 50 0001 C CNN
|
||||
1 6100 4450
|
||||
1 0 0 -1
|
||||
$EndComp
|
||||
Wire Wire Line
|
||||
6100 4300 6750 4300
|
||||
Connection ~ 6750 4300
|
||||
Wire Wire Line
|
||||
6750 4300 6750 4400
|
||||
Wire Wire Line
|
||||
6450 4600 6100 4600
|
||||
Text GLabel 6000 4600 0 50 Input ~ 0
|
||||
MEAS_EN
|
||||
Wire Wire Line
|
||||
6000 4600 6100 4600
|
||||
Connection ~ 6100 4600
|
||||
$Comp
|
||||
L Device:C C10
|
||||
U 1 1 6061C058
|
||||
P 6350 5600
|
||||
F 0 "C10" H 6465 5646 50 0000 L CNN
|
||||
F 1 "C" H 6465 5555 50 0000 L CNN
|
||||
F 2 "Capacitor_SMD:C_0603_1608Metric" H 6388 5450 50 0001 C CNN
|
||||
F 3 "~" H 6350 5600 50 0001 C CNN
|
||||
1 6350 5600
|
||||
1 0 0 -1
|
||||
$EndComp
|
||||
Wire Wire Line
|
||||
6350 5450 6350 5350
|
||||
Wire Wire Line
|
||||
6350 5350 6750 5350
|
||||
Wire Wire Line
|
||||
6350 5750 6350 5850
|
||||
Wire Wire Line
|
||||
6350 5850 6750 5850
|
||||
Connection ~ 6750 5850
|
||||
Wire Wire Line
|
||||
6750 5850 6750 5750
|
||||
Wire Wire Line
|
||||
7300 4450 7300 4300
|
||||
Wire Wire Line
|
||||
7300 4300 6750 4300
|
||||
Wire Wire Line
|
||||
7300 4750 7300 4900
|
||||
Wire Wire Line
|
||||
7300 4900 6750 4900
|
||||
Connection ~ 6750 4900
|
||||
Wire Wire Line
|
||||
6750 4900 6750 5000
|
||||
$Comp
|
||||
L Jumper:SolderJumper_2_Open JP2
|
||||
U 1 1 6062BF4E
|
||||
P 7300 4600
|
||||
F 0 "JP2" V 7254 4668 50 0000 L CNN
|
||||
F 1 "SolderJumper_2_Open" V 7345 4668 50 0000 L CNN
|
||||
F 2 "Jumper:SolderJumper-2_P1.3mm_Open_Pad1.0x1.5mm" H 7300 4600 50 0001 C CNN
|
||||
F 3 "~" H 7300 4600 50 0001 C CNN
|
||||
1 7300 4600
|
||||
0 1 1 0
|
||||
$EndComp
|
||||
$Comp
|
||||
L Jumper:SolderJumper_2_Open JP1
|
||||
U 1 1 6064EF71
|
||||
P 1350 7400
|
||||
F 0 "JP1" H 1300 7150 50 0000 C CNN
|
||||
F 1 "SolderJumper_2_Open" H 1350 7250 50 0000 C CNN
|
||||
F 2 "Jumper:SolderJumper-2_P1.3mm_Open_Pad1.0x1.5mm" H 1350 7400 50 0001 C CNN
|
||||
F 3 "~" H 1350 7400 50 0001 C CNN
|
||||
1 1350 7400
|
||||
1 0 0 -1
|
||||
$EndComp
|
||||
Text GLabel 5500 2150 2 50 Input ~ 0
|
||||
MEAS_EN
|
||||
Wire Wire Line
|
||||
5500 2150 5300 2150
|
||||
$EndSCHEMATC
|
||||
|
||||
@@ -631,60 +631,60 @@ Wire Wire Line
|
||||
$Comp
|
||||
L Device:R R13
|
||||
U 1 1 60403C7A
|
||||
P 6250 2950
|
||||
F 0 "R13" H 6320 2996 50 0000 L CNN
|
||||
F 1 "100K" H 6320 2905 50 0000 L CNN
|
||||
F 2 "Resistor_SMD:R_0603_1608Metric" V 6180 2950 50 0001 C CNN
|
||||
F 3 "~" H 6250 2950 50 0001 C CNN
|
||||
1 6250 2950
|
||||
P 6750 5600
|
||||
F 0 "R13" H 6820 5646 50 0000 L CNN
|
||||
F 1 "10K" H 6820 5555 50 0000 L CNN
|
||||
F 2 "Resistor_SMD:R_0603_1608Metric" V 6680 5600 50 0001 C CNN
|
||||
F 3 "~" H 6750 5600 50 0001 C CNN
|
||||
1 6750 5600
|
||||
1 0 0 -1
|
||||
$EndComp
|
||||
$Comp
|
||||
L Device:R R12
|
||||
U 1 1 6040529B
|
||||
P 6250 2500
|
||||
F 0 "R12" H 6320 2546 50 0000 L CNN
|
||||
F 1 "220K" H 6320 2455 50 0000 L CNN
|
||||
F 2 "Resistor_SMD:R_0603_1608Metric" V 6180 2500 50 0001 C CNN
|
||||
F 3 "~" H 6250 2500 50 0001 C CNN
|
||||
1 6250 2500
|
||||
P 6750 5150
|
||||
F 0 "R12" H 6820 5196 50 0000 L CNN
|
||||
F 1 "4k7" H 6820 5105 50 0000 L CNN
|
||||
F 2 "Resistor_SMD:R_0603_1608Metric" V 6680 5150 50 0001 C CNN
|
||||
F 3 "~" H 6750 5150 50 0001 C CNN
|
||||
1 6750 5150
|
||||
1 0 0 -1
|
||||
$EndComp
|
||||
Text GLabel 6400 2700 2 50 Input ~ 0
|
||||
Text GLabel 6900 5350 2 50 Input ~ 0
|
||||
MEAS_VBATT
|
||||
Wire Wire Line
|
||||
6400 2700 6250 2700
|
||||
6900 5350 6750 5350
|
||||
Wire Wire Line
|
||||
6250 2700 6250 2650
|
||||
6750 5350 6750 5300
|
||||
Wire Wire Line
|
||||
6250 2800 6250 2700
|
||||
Connection ~ 6250 2700
|
||||
6750 5450 6750 5350
|
||||
Connection ~ 6750 5350
|
||||
$Comp
|
||||
L power:+BATT #PWR0117
|
||||
U 1 1 60416333
|
||||
P 6250 2150
|
||||
F 0 "#PWR0117" H 6250 2000 50 0001 C CNN
|
||||
F 1 "+BATT" H 6265 2323 50 0000 C CNN
|
||||
F 2 "" H 6250 2150 50 0001 C CNN
|
||||
F 3 "" H 6250 2150 50 0001 C CNN
|
||||
1 6250 2150
|
||||
P 6750 4250
|
||||
F 0 "#PWR0117" H 6750 4100 50 0001 C CNN
|
||||
F 1 "+BATT" H 6765 4423 50 0000 C CNN
|
||||
F 2 "" H 6750 4250 50 0001 C CNN
|
||||
F 3 "" H 6750 4250 50 0001 C CNN
|
||||
1 6750 4250
|
||||
1 0 0 -1
|
||||
$EndComp
|
||||
Wire Wire Line
|
||||
6250 2150 6250 2350
|
||||
6750 4800 6750 4900
|
||||
$Comp
|
||||
L power:GND #PWR0118
|
||||
U 1 1 6041C5AA
|
||||
P 6250 3300
|
||||
F 0 "#PWR0118" H 6250 3050 50 0001 C CNN
|
||||
F 1 "GND" H 6255 3127 50 0000 C CNN
|
||||
F 2 "" H 6250 3300 50 0001 C CNN
|
||||
F 3 "" H 6250 3300 50 0001 C CNN
|
||||
1 6250 3300
|
||||
P 6750 5950
|
||||
F 0 "#PWR0118" H 6750 5700 50 0001 C CNN
|
||||
F 1 "GND" H 6755 5777 50 0000 C CNN
|
||||
F 2 "" H 6750 5950 50 0001 C CNN
|
||||
F 3 "" H 6750 5950 50 0001 C CNN
|
||||
1 6750 5950
|
||||
1 0 0 -1
|
||||
$EndComp
|
||||
Wire Wire Line
|
||||
6250 3300 6250 3100
|
||||
6750 5950 6750 5850
|
||||
Text GLabel 5500 1350 2 50 Input ~ 0
|
||||
MEAS_VBATT
|
||||
Wire Wire Line
|
||||
@@ -847,18 +847,6 @@ Wire Wire Line
|
||||
Wire Wire Line
|
||||
2100 7300 2000 7300
|
||||
$Comp
|
||||
L Device:R R14
|
||||
U 1 1 60310C7E
|
||||
P 1350 7400
|
||||
F 0 "R14" V 1450 7400 50 0000 C CNN
|
||||
F 1 "0E" V 1550 7400 50 0000 C CNN
|
||||
F 2 "Resistor_SMD:R_0603_1608Metric" V 1280 7400 50 0001 C CNN
|
||||
F 3 "~" H 1350 7400 50 0001 C CNN
|
||||
F 4 "DNP" V 1350 7400 50 0000 C CNN "DNP"
|
||||
1 1350 7400
|
||||
0 1 1 0
|
||||
$EndComp
|
||||
$Comp
|
||||
L power:VBUS #PWR0124
|
||||
U 1 1 603121CD
|
||||
P 900 7100
|
||||
@@ -983,7 +971,6 @@ NoConn ~ 4200 2350
|
||||
NoConn ~ 4200 2850
|
||||
NoConn ~ 5300 2450
|
||||
NoConn ~ 5300 2550
|
||||
NoConn ~ 5300 2150
|
||||
NoConn ~ 5300 2850
|
||||
Wire Wire Line
|
||||
4800 3050 4800 3450
|
||||
@@ -1268,4 +1255,100 @@ Wire Wire Line
|
||||
Connection ~ 8900 5000
|
||||
Text GLabel 7450 1100 0 50 Input ~ 0
|
||||
DET1
|
||||
$Comp
|
||||
L Transistor_FET:BSS84 Q1
|
||||
U 1 1 605F95CF
|
||||
P 6650 4600
|
||||
F 0 "Q1" H 6854 4646 50 0000 L CNN
|
||||
F 1 "BSS84" H 6854 4555 50 0000 L CNN
|
||||
F 2 "Package_TO_SOT_SMD:SOT-23" H 6850 4525 50 0001 L CIN
|
||||
F 3 "http://assets.nexperia.com/documents/data-sheet/BSS84.pdf" H 6650 4600 50 0001 L CNN
|
||||
F 4 "FARNELL-1972673" H 6650 4600 50 0001 C CNN "ordercode"
|
||||
1 6650 4600
|
||||
1 0 0 -1
|
||||
$EndComp
|
||||
Wire Wire Line
|
||||
6750 4250 6750 4300
|
||||
$Comp
|
||||
L Device:R R14
|
||||
U 1 1 6060550D
|
||||
P 6100 4450
|
||||
F 0 "R14" H 6170 4496 50 0000 L CNN
|
||||
F 1 "100K" H 6170 4405 50 0000 L CNN
|
||||
F 2 "Resistor_SMD:R_0603_1608Metric" V 6030 4450 50 0001 C CNN
|
||||
F 3 "~" H 6100 4450 50 0001 C CNN
|
||||
1 6100 4450
|
||||
1 0 0 -1
|
||||
$EndComp
|
||||
Wire Wire Line
|
||||
6100 4300 6750 4300
|
||||
Connection ~ 6750 4300
|
||||
Wire Wire Line
|
||||
6750 4300 6750 4400
|
||||
Wire Wire Line
|
||||
6450 4600 6100 4600
|
||||
Text GLabel 6000 4600 0 50 Input ~ 0
|
||||
MEAS_EN
|
||||
Wire Wire Line
|
||||
6000 4600 6100 4600
|
||||
Connection ~ 6100 4600
|
||||
$Comp
|
||||
L Device:C C10
|
||||
U 1 1 6061C058
|
||||
P 6350 5600
|
||||
F 0 "C10" H 6465 5646 50 0000 L CNN
|
||||
F 1 "C" H 6465 5555 50 0000 L CNN
|
||||
F 2 "Capacitor_SMD:C_0603_1608Metric" H 6388 5450 50 0001 C CNN
|
||||
F 3 "~" H 6350 5600 50 0001 C CNN
|
||||
1 6350 5600
|
||||
1 0 0 -1
|
||||
$EndComp
|
||||
Wire Wire Line
|
||||
6350 5450 6350 5350
|
||||
Wire Wire Line
|
||||
6350 5350 6750 5350
|
||||
Wire Wire Line
|
||||
6350 5750 6350 5850
|
||||
Wire Wire Line
|
||||
6350 5850 6750 5850
|
||||
Connection ~ 6750 5850
|
||||
Wire Wire Line
|
||||
6750 5850 6750 5750
|
||||
Wire Wire Line
|
||||
7300 4450 7300 4300
|
||||
Wire Wire Line
|
||||
7300 4300 6750 4300
|
||||
Wire Wire Line
|
||||
7300 4750 7300 4900
|
||||
Wire Wire Line
|
||||
7300 4900 6750 4900
|
||||
Connection ~ 6750 4900
|
||||
Wire Wire Line
|
||||
6750 4900 6750 5000
|
||||
$Comp
|
||||
L Jumper:SolderJumper_2_Open JP2
|
||||
U 1 1 6062BF4E
|
||||
P 7300 4600
|
||||
F 0 "JP2" V 7254 4668 50 0000 L CNN
|
||||
F 1 "SolderJumper_2_Open" V 7345 4668 50 0000 L CNN
|
||||
F 2 "Jumper:SolderJumper-2_P1.3mm_Open_Pad1.0x1.5mm" H 7300 4600 50 0001 C CNN
|
||||
F 3 "~" H 7300 4600 50 0001 C CNN
|
||||
1 7300 4600
|
||||
0 1 1 0
|
||||
$EndComp
|
||||
$Comp
|
||||
L Jumper:SolderJumper_2_Open JP1
|
||||
U 1 1 6064EF71
|
||||
P 1350 7400
|
||||
F 0 "JP1" H 1300 7150 50 0000 C CNN
|
||||
F 1 "SolderJumper_2_Open" H 1350 7250 50 0000 C CNN
|
||||
F 2 "Jumper:SolderJumper-2_P1.3mm_Open_Pad1.0x1.5mm" H 1350 7400 50 0001 C CNN
|
||||
F 3 "~" H 1350 7400 50 0001 C CNN
|
||||
1 1350 7400
|
||||
1 0 0 -1
|
||||
$EndComp
|
||||
Text GLabel 5500 2150 2 50 Input ~ 0
|
||||
MEAS_EN
|
||||
Wire Wire Line
|
||||
5500 2150 5300 2150
|
||||
$EndSCHEMATC
|
||||
|
||||
@@ -8,10 +8,15 @@
|
||||
; Please visit documentation for the other options and examples
|
||||
; https://docs.platformio.org/page/projectconf.html
|
||||
|
||||
[env:nucleo_l031K6]
|
||||
[env:LedBoardV10]
|
||||
platform = ststm32
|
||||
board = STM32L031K6
|
||||
framework = arduino
|
||||
upload_port = stlink
|
||||
debug_tool = stlink
|
||||
boards_dir = boards
|
||||
#boards_dir = boards
|
||||
lib_ldf_mode = deep+
|
||||
build_flags =
|
||||
-DHARDWAREVERSION=10
|
||||
#lib_deps =
|
||||
# rlogiacco/Battery Sense@^1.1.2
|
||||
87
src/board.h
87
src/board.h
@@ -1,35 +1,11 @@
|
||||
#ifndef BOARDH
|
||||
#define BOARDH
|
||||
|
||||
#define HARDWAREVERSION 11
|
||||
|
||||
|
||||
#ifndef UNIT_TEST
|
||||
|
||||
#if HARDWAREVERSION==11
|
||||
|
||||
#define LED3 PB2 //D3
|
||||
#define LED2 PB8 //D4
|
||||
#define LED1 PB7 //D5
|
||||
|
||||
#define DETECT3 PA6 //A5
|
||||
#define DETECT2 PA5 //A4
|
||||
#define DETECT1 PA4 //A3
|
||||
|
||||
#define SWITCH3 PA7 //A6 TOGGLE1
|
||||
#define SWITCH32 PA2 //A7 MOMENTARY1
|
||||
#define SWITCH2 PA1 //A1 TOGGLE1
|
||||
#define SWITCH22 PA3 //A2 MOMENTARY1
|
||||
#define SWITCH1 PB6 //D11 TOGGLE1
|
||||
#define SWITCH12 PB5 //D12 MOMENTARY1
|
||||
|
||||
#define LD3LED PB3
|
||||
#define WAKEUPPIN PA2
|
||||
|
||||
#define REDLEDRES
|
||||
#define YELLOWLEDRES
|
||||
#define GREENLEDRES
|
||||
|
||||
#elif HARDWAREVERSION==10
|
||||
#if HARDWAREVERSION==9 //proto board with nucleo32l031 board
|
||||
|
||||
#define LED3 PB0 //D3
|
||||
#define LED2 PB7 //D4
|
||||
@@ -49,15 +25,70 @@
|
||||
#define LD3LED PB3
|
||||
#define WAKEUPPIN PA2
|
||||
|
||||
#define REDLEDRES
|
||||
#define YELLOWLEDRES
|
||||
#define GREENLEDRES
|
||||
|
||||
#elif HARDWAREVERSION==10 //v1.0 PCB
|
||||
|
||||
#define LED3 PB2
|
||||
#define LED2 PB8
|
||||
#define LED1 PB7
|
||||
|
||||
#define DETECT3 PA6
|
||||
#define DETECT2 PA5
|
||||
#define DETECT1 PA4
|
||||
|
||||
#define SWITCH3 PA7 //A6 TOGGLE1
|
||||
#define SWITCH32 PA2 //A7 MOMENTARY1
|
||||
#define SWITCH2 PA1 //A1 TOGGLE1
|
||||
#define SWITCH22 PA3 //A2 MOMENTARY1
|
||||
#define SWITCH1 PB6 //D11 TOGGLE1
|
||||
#define SWITCH12 PB5 //D12 MOMENTARY1
|
||||
|
||||
#define LD3LED PB3
|
||||
#define WAKEUPPIN PA2
|
||||
#define VBATTPIN PA0 //A0 VBATT
|
||||
#define R12 3.3
|
||||
#define R13 10
|
||||
|
||||
#define REDLEDRES
|
||||
#define YELLOWLEDRES
|
||||
#define GREENLEDRES
|
||||
|
||||
#elif HARDWAREVERSION==11
|
||||
|
||||
#define LED3 PB2
|
||||
#define LED2 PB8
|
||||
#define LED1 PB7
|
||||
|
||||
#define DETECT3 PA6
|
||||
#define DETECT2 PA5
|
||||
#define DETECT1 PA4
|
||||
|
||||
#define SWITCH3 PA7 //A6 TOGGLE1
|
||||
#define SWITCH32 PA2 //A7 MOMENTARY1
|
||||
#define SWITCH2 PA1 //A1 TOGGLE1
|
||||
#define SWITCH22 PA3 //A2 MOMENTARY1
|
||||
#define SWITCH1 PB6 //D11 TOGGLE1
|
||||
#define SWITCH12 PB5 //D12 MOMENTARY1
|
||||
|
||||
#define LD3LED PB3
|
||||
#define WAKEUPPIN PA2
|
||||
#define VBATTPIN PA0 //A0 VBATT
|
||||
#define R12 4.7
|
||||
#define R13 10
|
||||
#define MEASTRIGGER PA8
|
||||
|
||||
#define REDLEDRES
|
||||
#define YELLOWLEDRES
|
||||
#define GREENLEDRES
|
||||
#else
|
||||
#error No hardware version defined
|
||||
#error No hardware version defined!!
|
||||
|
||||
#endif
|
||||
|
||||
#else
|
||||
#else //UNIT_TEST
|
||||
|
||||
#define LED1 0 //D3
|
||||
#define LED2 1 //D4
|
||||
|
||||
79
src/main.cpp
79
src/main.cpp
@@ -8,9 +8,10 @@
|
||||
#include "simpleled.h"
|
||||
#include "buttons.h"
|
||||
#include "led.h"
|
||||
#include "power.h"
|
||||
|
||||
|
||||
#define TIMEOUT 300000 // 5min* 60 sec * 1000ms
|
||||
#define TIMEOUT 900000 // 15min* 60 sec * 1000ms
|
||||
#define GAMESELECTTIMEOUT 10000 // 7sec * 1000ms
|
||||
|
||||
typedef enum
|
||||
@@ -55,7 +56,7 @@ void HandleIdle(void)
|
||||
if (buttonIsPressed(YELLOW) && buttonIsPressed(RED) && !buttonIsPressed(GREEN) & (nextGame == none))
|
||||
{
|
||||
//prepare for next game
|
||||
nextGame = detectLED;
|
||||
nextGame = SimpleLed;
|
||||
turnOffLed(GREEN);
|
||||
}
|
||||
|
||||
@@ -70,8 +71,8 @@ void HandleIdle(void)
|
||||
void HandleGameSelectTimeout(void)
|
||||
{
|
||||
uint64_t currentmillis = millis();
|
||||
// yellow && red && green all on
|
||||
if (buttonIsPressed(YELLOW) && buttonIsPressed(RED) && buttonIsPressed(GREEN))
|
||||
//if (yellow && red && green)
|
||||
{
|
||||
//all buttons pressed, wait for next game
|
||||
if (!GameSelectTimer)
|
||||
@@ -95,35 +96,33 @@ void HandleGameSelectTimeout(void)
|
||||
}
|
||||
}
|
||||
|
||||
// void HandleTimeOut(void)
|
||||
// {
|
||||
// uint64_t currentmillis = millis();
|
||||
// if (!lasttimeOut)
|
||||
// {
|
||||
// lasttimeOut = currentmillis;
|
||||
// buttonChanged = anybutton();
|
||||
// }
|
||||
void HandleTimeOut(void)
|
||||
{
|
||||
uint64_t currentmillis = millis();
|
||||
if (!lasttimeOut)
|
||||
{
|
||||
lasttimeOut = currentmillis;
|
||||
buttonChanged = anybutton();
|
||||
}
|
||||
|
||||
// //check if lastTime is initialized or timeout expired
|
||||
// if ((currentmillis - lasttimeOut > TIMEOUT))
|
||||
// {
|
||||
// LowPower.shutdown();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (buttonChanged != anybutton())
|
||||
// {
|
||||
// buttonChanged = anybutton();
|
||||
// //game in progress, update timer
|
||||
// lasttimeOut = currentmillis;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//check if lastTime is initialized or timeout expired
|
||||
if ((currentmillis - lasttimeOut > TIMEOUT))
|
||||
{
|
||||
currentGame = sleep;
|
||||
turnOffAllLed();
|
||||
shutdown();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (buttonChanged != anybutton())
|
||||
{
|
||||
buttonChanged = anybutton();
|
||||
//game in progress, update timer
|
||||
lasttimeOut = currentmillis;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// void initSleep( void )
|
||||
// {
|
||||
// LowPower.begin();
|
||||
// }
|
||||
|
||||
void setup()
|
||||
{
|
||||
@@ -131,12 +130,14 @@ void setup()
|
||||
initButtons();
|
||||
initDetectLed();
|
||||
initSimpleLed();
|
||||
initLowPower();
|
||||
initBattery();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
handleButtons();
|
||||
//HandleTimeOut();
|
||||
HandleTimeOut();
|
||||
HandleGameSelectTimeout();
|
||||
|
||||
switch (currentGame)
|
||||
@@ -175,10 +176,13 @@ void loop()
|
||||
case none:
|
||||
{
|
||||
currentGame = SimpleLed;
|
||||
if (buttonIsPressed(YELLOW))
|
||||
batteryCheck();
|
||||
batterydisplay();
|
||||
delay(1000);
|
||||
if (buttonIsPressed(GREEN))
|
||||
{
|
||||
currentGame = ChainGame;
|
||||
turnOnLed(YELLOW);
|
||||
turnOnLed(GREEN);
|
||||
}
|
||||
if (buttonIsPressed(RED))
|
||||
{
|
||||
@@ -186,14 +190,15 @@ void loop()
|
||||
turnOnLed(RED);
|
||||
}
|
||||
|
||||
if (buttonIsPressed(GREEN))
|
||||
if (buttonIsPressed(YELLOW))
|
||||
{
|
||||
currentGame = detectLED;
|
||||
turnOnLed(GREEN);
|
||||
currentGame = SimpleLed;
|
||||
turnOnLed(YELLOW);
|
||||
}
|
||||
|
||||
//wait for all buttons idle
|
||||
while (anybutton())
|
||||
;
|
||||
{}
|
||||
|
||||
turnOffAllLed();
|
||||
}
|
||||
|
||||
75
src/power.cpp
Normal file
75
src/power.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
#include "power.h"
|
||||
#include "board.h"
|
||||
#include "rtc.h"
|
||||
#include "low_Power.h"
|
||||
#include "led.h"
|
||||
|
||||
#ifdef VBATTPIN
|
||||
#include "Battery.h"
|
||||
Battery battery(2500, 4160, VBATTPIN);
|
||||
#endif
|
||||
|
||||
void initBattery(void)
|
||||
{
|
||||
#ifdef VBATTPIN
|
||||
battery.begin(3300, (R12+R13)/R13); //R1 = 220K, R2 = 100K, factor = (R1+R2)/R2
|
||||
#endif
|
||||
}
|
||||
|
||||
uint16_t batteryGetVoltage( void )
|
||||
{
|
||||
return battery.voltage();
|
||||
}
|
||||
|
||||
void batterydisplay(void)
|
||||
{
|
||||
#ifdef VBATTPIN
|
||||
uint16_t currentlevel = battery.level();
|
||||
uint16_t currentvoltage = batteryGetVoltage();
|
||||
|
||||
if(currentvoltage)
|
||||
{
|
||||
if (currentlevel > 90)
|
||||
{
|
||||
turnOnLed(3);
|
||||
}
|
||||
if (currentlevel > 50)
|
||||
{
|
||||
turnOnLed(2);
|
||||
}
|
||||
if (currentlevel > 20)
|
||||
{
|
||||
turnOnLed(1);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void batteryCheck(void)
|
||||
{
|
||||
#ifdef VBATTPIN
|
||||
if (battery.level() < 10)
|
||||
{
|
||||
for( int i = 0; i < 10;i++)
|
||||
{
|
||||
turnOnLed(1);
|
||||
delay(300);
|
||||
turnOffLed(1);
|
||||
delay(300);
|
||||
}
|
||||
delay(5000);
|
||||
shutdown();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
//low power
|
||||
void initLowPower(void)
|
||||
{
|
||||
LowPower_init();
|
||||
}
|
||||
|
||||
void shutdown(void)
|
||||
{
|
||||
LowPower_shutdown();
|
||||
}
|
||||
10
src/power.h
Normal file
10
src/power.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
//battery
|
||||
void initBattery( void );
|
||||
void batterydisplay( void );
|
||||
void batteryCheck(void);
|
||||
|
||||
//low power
|
||||
void initLowPower( void );
|
||||
void shutdown( void );
|
||||
Reference in New Issue
Block a user