initial commit
This commit is contained in:
22
agents.md
Normal file
22
agents.md
Normal file
@@ -0,0 +1,22 @@
|
||||
Complete echo_bot build/flash/reset/UART workflow (user-provided commands):
|
||||
|
||||
# 1. Build
|
||||
cd ~/ncs/v3.0.2 && nrfutil toolchain-manager launch --ncs-version v3.0.2 -- west build --build-dir /home/paul/Documents/echo_bot/build /home/paul/Documents/echo_bot --board Scout/nrf5340/cpuapp -- -DBOARD_ROOT="/home/paul/Documents/custom_boards_nrf"
|
||||
|
||||
# 2. Flash
|
||||
cd ~/ncs/v3.0.2 && nrfutil toolchain-manager launch --ncs-version v3.0.2 -- west flash --build-dir /home/paul/Documents/echo_bot/build
|
||||
|
||||
# 3. Reset device
|
||||
nrfutil device reset --serial-number <SERIAL_NUMBER>
|
||||
|
||||
# 4. UART capture (30s timeout)
|
||||
We use Uart for logging!
|
||||
timeout 30 minicom --device /dev/serial/by-id/<id> --baudrate 115200
|
||||
|
||||
Notes:
|
||||
- Use nrfutil toolchain-manager launch wrapper for NCS v3.0.2
|
||||
- Board: Scout/nrf5340/cpuapp with custom BOARD_ROOT
|
||||
- Serial number for reset: <SERIAL_NUMBER>
|
||||
- UART device: /dev/serial/by-id/<id>
|
||||
- Timeout 30s on minicom to auto-exit
|
||||
- Start the UART and directly after that reset, to get the output
|
||||
2
prj.conf
2
prj.conf
@@ -1,2 +1,4 @@
|
||||
# Application-specific configs
|
||||
CONFIG_SERIAL=y
|
||||
CONFIG_UART_INTERRUPT_DRIVEN=y
|
||||
CONFIG_GPIO=y
|
||||
|
||||
19
src/battery_model.inc
Normal file
19
src/battery_model.inc
Normal file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Nordic Semiconductor ASA
|
||||
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
|
||||
*/
|
||||
|
||||
.param_1 = {0.0, 0.005, 0.01, 0.015, 0.02, 0.025, 0.03, 0.035, 0.04, 0.045, 0.05, 0.055, 0.06, 0.065, 0.07, 0.075, 0.08, 0.085, 0.09, 0.095, 0.1, 0.105, 0.11, 0.115, 0.12, 0.125, 0.13, 0.135, 0.14, 0.145, 0.15, 0.155, 0.16, 0.165, 0.17, 0.17500000000000002, 0.18, 0.185, 0.19, 0.195, 0.2, 0.20500000000000002, 0.21, 0.215, 0.22, 0.225, 0.23, 0.23500000000000001, 0.24, 0.245, 0.25, 0.255, 0.26, 0.265, 0.27, 0.275, 0.28, 0.28500000000000003, 0.29, 0.295, 0.3, 0.305, 0.31, 0.315, 0.32, 0.325, 0.33, 0.335, 0.34, 0.34500000000000003, 0.35000000000000003, 0.355, 0.36, 0.365, 0.37, 0.375, 0.38, 0.385, 0.39, 0.395, 0.4, 0.405, 0.41000000000000003, 0.41500000000000004, 0.42, 0.425, 0.43, 0.435, 0.44, 0.445, 0.45, 0.455, 0.46, 0.465, 0.47000000000000003, 0.47500000000000003, 0.48, 0.485, 0.49, 0.495, 0.5, 0.505, 0.51, 0.515, 0.52, 0.525, 0.53, 0.535, 0.54, 0.545, 0.55, 0.555, 0.56, 0.5650000000000001, 0.5700000000000001, 0.5750000000000001, 0.58, 0.585, 0.59, 0.595, 0.6, 0.605, 0.61, 0.615, 0.62, 0.625, 0.63, 0.635, 0.64, 0.645, 0.65, 0.655, 0.66, 0.665, 0.67, 0.675, 0.68, 0.685, 0.6900000000000001, 0.6950000000000001, 0.7000000000000001, 0.705, 0.71, 0.715, 0.72, 0.725, 0.73, 0.735, 0.74, 0.745, 0.75, 0.755, 0.76, 0.765, 0.77, 0.775, 0.78, 0.785, 0.79, 0.795, 0.8, 0.805, 0.81, 0.8150000000000001, 0.8200000000000001, 0.8250000000000001, 0.8300000000000001, 0.835, 0.84, 0.845, 0.85, 0.855, 0.86, 0.865, 0.87, 0.875, 0.88, 0.885, 0.89, 0.895, 0.9, 0.905, 0.91, 0.915, 0.92, 0.925, 0.93, 0.935, 0.9400000000000001, 0.9450000000000001, 0.9500000000000001, 0.9550000000000001, 0.96, 0.965, 0.97, 0.975, 0.98, 0.985, 0.99, 0.995, 1.0},
|
||||
.temps = {5, 25, 45},
|
||||
.param_2 = {2.99, 3.0, 3.01, 3.0199999999999996, 3.0299999999999994, 3.039999999999999, 3.049999999999999, 3.0599999999999987, 3.0699999999999985, 3.0799999999999983, 3.089999999999998, 3.099999999999998, 3.1099999999999977, 3.1199999999999974, 3.1299999999999972, 3.139999999999997, 3.149999999999997, 3.1599999999999966, 3.1699999999999964, 3.179999999999996, 3.189999999999996, 3.1999999999999957, 3.2099999999999955, 3.2199999999999953, 3.229999999999995, 3.239999999999995, 3.2499999999999947, 3.2599999999999945, 3.2699999999999942, 3.279999999999994, 3.289999999999994, 3.2999999999999936, 3.3099999999999934, 3.319999999999993, 3.329999999999993, 3.3399999999999928, 3.3499999999999925, 3.3599999999999923, 3.369999999999992, 3.379999999999992, 3.3899999999999917, 3.3999999999999915, 3.4099999999999913, 3.419999999999991, 3.429999999999991, 3.4399999999999906, 3.4499999999999904, 3.45999999999999, 3.46999999999999, 3.4799999999999898, 3.4899999999999896, 3.4999999999999893, 3.509999999999989, 3.519999999999989, 3.5299999999999887, 3.5399999999999885, 3.5499999999999883, 3.559999999999988, 3.569999999999988, 3.5799999999999876, 3.5899999999999874, 3.599999999999987, 3.609999999999987, 3.619999999999987, 3.6299999999999866, 3.6399999999999864, 3.649999999999986, 3.659999999999986, 3.6699999999999857, 3.6799999999999855, 3.6899999999999853, 3.699999999999985, 3.709999999999985, 3.7199999999999847, 3.7299999999999844, 3.7399999999999842, 3.749999999999984, 3.759999999999984, 3.7699999999999836, 3.7799999999999834, 3.789999999999983, 3.799999999999983, 3.8099999999999827, 3.8199999999999825, 3.8299999999999823, 3.839999999999982, 3.849999999999982, 3.8599999999999817, 3.8699999999999815, 3.8799999999999812, 3.889999999999981, 3.899999999999981, 3.9099999999999806, 3.9199999999999804, 3.92999999999998, 3.93999999999998, 3.9499999999999797, 3.9599999999999795, 3.9699999999999793, 3.979999999999979, 3.989999999999979, 3.9999999999999787, 4.0099999999999785, 4.019999999999978, 4.029999999999978, 4.039999999999978, 4.049999999999978, 4.059999999999977, 4.069999999999977, 4.079999999999977, 4.089999999999977, 4.0999999999999766, 4.109999999999976, 4.119999999999976, 4.129999999999976, 4.139999999999976, 4.1499999999999755, 4.159999999999975, 4.169999999999975, 4.179999999999975, 4.189999999999975, 4.199999999999974},
|
||||
.param_3 = {-0.002420346451342266, -0.0021008431246098574, -0.0018606034835038396, -0.0016798095056542069, -0.0015380444343691029, -0.001419299567172311, -0.0013175012321380547, -0.001225653849165642, -0.001139615734749306, -0.0010496449971018932, -0.0009478573810920241, -0.0008257494412378883, -0.0006778737673721529, -0.0005171353041969488, -0.00036804030714503015, -0.00025131734128107223, -0.0001717319819526326, -0.00012095625675209936, -9.011898689630018e-05, -7.16870383866877e-05, -6.051207597447544e-05, -5.3791049466690855e-05, -5.0705528804525664e-05, -5.145999000093411e-05, -5.5057329226009876e-05, -6.261489298605003e-05, -7.496650607820114e-05, -9.146838320420544e-05, -0.000113476470950206, -0.00014000483970617454, -0.00016753607969772317, -0.00019141410780926913, -0.00020913420324122846, -0.00022022935462249587, -0.00022478053732324005, -0.0002242708922533014, -0.00022074661970613224, -0.00021876245628930273, -0.0002180142220333573, -0.00021862968437267653, -0.0002196711916100664, -0.00021964866441512892, -0.00021956369438375908, -0.00021882092354703284, -0.00021761463621403055, -0.0002136220965931003, -0.00020677294018554742, -0.00020200833539481267, -0.00019421682490890227, -0.0001881664683983747, -0.0001895986526112283, -0.00019421441783755523, -0.00019795638320206722, -0.00020071883546509962, -0.00020344476367321562, -0.0002062673001455598, -0.00020856323543024324, -0.0002098079695813975, -0.00020985144481818906, -0.0002086124675975052, -0.0002060155422277739, -0.00020199147824993022, -0.00019655535495930395, -0.00018991922418073063, -0.00018229324968835892, -0.00017358784845745534, -0.000163540712939697, -0.00015196462582480882, -0.00013878786521954567, -0.00012394837949852023, -0.00010744771050144605, -8.934496991280475e-05, -6.998279603770359e-05, -5.029364343741649e-05, -3.126247198830465e-05, -1.3751795924961079e-05, 1.4184166631495088e-06, 1.3619725600016816e-05, 2.265617420879496e-05, 2.8432158203155174e-05, 3.119193677004536e-05, 3.135985680188924e-05, 2.9386749607969216e-05, 2.5680968592329397e-05, 2.06325298940093e-05, 1.4610211110225783e-05, 7.981481154203013e-06, 1.044738767184397e-06, -6.077119082440496e-06, -1.319961085615437e-05, -1.998622374434444e-05, -2.6106371683376697e-05, -3.1671169535094746e-05, -3.7387727602387425e-05, -4.378498329453583e-05, -5.0517736924695797e-05, -5.696729416831665e-05, -6.262604516222209e-05, -6.680062230541004e-05, -6.881659605370563e-05, -6.895523798406324e-05, -6.799635414202802e-05, -6.648293540223552e-05, -6.435904775098273e-05, -6.16470206190775e-05, -5.861352848940726e-05, -5.5550872570767216e-05, -5.239594882926211e-05, -4.8752675456797696e-05, -4.502125124164334e-05, -4.246577369240065e-05, -4.175178627875383e-05, -4.194625278507503e-05, -4.1847302708125026e-05, -4.128820926111074e-05, -4.05406921967075e-05, -3.987946193552284e-05, -3.964029679263124e-05, -4.015201857022808e-05, -4.1344945932359896e-05, -4.303138412368835e-05, -4.502510054995288e-05, -4.718696460118733e-05, -4.948455177905052e-05, -5.2054710003163426e-05, -5.506807971287682e-05, -5.869721308014017e-05, -6.316586464843278e-05, -6.885026652697488e-05, -7.635391113500497e-05, -8.631176257940023e-05, -9.932375513677464e-05, -0.00011520123197951227, -0.00013280212571322323, -0.00015065737096250876, -0.0001672703523173878, -0.00018119967702109557, -0.00019205610666244197, -0.00020026451175773633, -0.0002061210985714427, -0.00020991247841953303, -0.0002119336589804564, -0.00021260679741024065, -0.00021226514195801414, -0.00021106857706018668, -0.00020917103556818153, -0.00020673092560894054, -0.00020396557560053353, -0.0002010819824696416, -0.00019825131398146925, -0.00019564414544332202, -0.0001933784067947226, -0.0001909845486269367, -0.00018807869456860746, -0.0001845122573109084, -0.00018013790983269115, -0.0001748232324336095, -0.0001685618965444326, -0.00016125339471768796, -0.00015273546286736475, -0.00014284580467137685, -0.0001314469662898801, -0.00011882762445613092, -0.000106079693109345, -9.444718605391026e-05, -8.517411709447219e-05, -7.937802163044094e-05, -7.713405498657364e-05, -7.80825072499244e-05, -8.187821813978588e-05, -8.817602737565681e-05, -9.670041685073913e-05, -0.00010747191625899087, -0.0001202990915346767, -0.00013494248687827002, -0.00015116264649014122, -0.00016873008186381712, -0.00018743059592666672, -0.00020699919088514428, -0.00022716527567144773, -0.00024765825921774064, -0.00026825059873490154, -0.00028899720887406473, -0.0003100749045625401, -0.0003316616688944306, -0.0003539354849640967, -0.0003770540252457987, -0.00040104794218725044, -0.0004258950402320867, -0.00045157271936552355, -0.0004780583795725025, -0.0005053727857614847, -0.000533864118196986, -0.0005640344462747546, -0.000596386881692369, -0.0006314245361471157, -0.0006696505213368137, -0.0007115679489588009, -0.0007576799307106044, -0.0008084895782897856, -0.0008645000033938027},
|
||||
.param_4 = {3.138768358677945, 3.188888383205696, 3.231057678817057, 3.2670071519914985, 3.298424111673665, 3.3263073172269584, 3.351116260235774, 3.3736348672342276, 3.3938643521125287, 3.411812406897564, 3.42756227136897, 3.440773398851908, 3.45118208693967, 3.459045224329814, 3.465107768310881, 3.4700371510066454, 3.4742112655036266, 3.477960824153601, 3.481450766521923, 3.4847392321692428, 3.4878634330105784, 3.4908382634657613, 3.493692914700353, 3.496530783681051, 3.499372700941198, 3.5022923364889222, 3.505350763692766, 3.5085825048772943, 3.512060833635507, 3.5158562286464914, 3.5199038567587673, 3.5240567347244625, 3.5282335672525376, 3.5323550308496143, 3.5363610004029207, 3.540245940824795, 3.5440253394261307, 3.547755649605548, 3.551418404234056, 3.5550535664366434, 3.55867657933785, 3.5622465802077374, 3.5657854471242647, 3.5692928818739285, 3.5727327414853365, 3.5760559683986006, 3.5792790850475202, 3.582444267012988, 3.5853709396199718, 3.5883465457606527, 3.5915910319925795, 3.594907579430762, 3.598139845774975, 3.6013141941421254, 3.6044957073783257, 3.6077067713078113, 3.6109377308017914, 3.614183117253564, 3.617449639617546, 3.6207447788348737, 3.624070013394462, 3.6274231942246122, 3.6308005710198863, 3.6342024824099033, 3.6376328437802044, 3.6410929724243184, 3.64457940190002, 3.648086559161912, 3.6516127782008816, 3.6551600429232503, 3.6587331272305055, 3.6623363588444806, 3.6659759759593893, 3.669665940875385, 3.673417262909056, 3.6772342712563586, 3.6811245338129033, 3.685107675819824, 3.6892002278057667, 3.6934018036335585, 3.697696217988446, 3.702070495362343, 3.7065235271646886, 3.711054923685624, 3.715659828529598, 3.72033135643606, 3.7250590287126006, 3.7298255782572824, 3.7346166544562247, 3.7394304877629336, 3.7442664151804808, 3.749112035207367, 3.7539456858151605, 3.758755184355408, 3.7635373368090166, 3.7682788688991176, 3.7729638263002863, 3.777583795033179, 3.7821278005569456, 3.786572482595884, 3.7909004677930103, 3.795106606599054, 3.7991923212584697, 3.803155136864345, 3.807002470091649, 3.810747498635457, 3.814394212215081, 3.8179334230353055, 3.8213591315914437, 3.8247093365974476, 3.82804441444883, 3.831384825116393, 3.8346872395583746, 3.8379087321655425, 3.8410538139822417, 3.844144694756539, 3.847203657001168, 3.850253671997599, 3.8533138242430645, 3.8563854000431177, 3.859464951217159, 3.8625490462586476, 3.8656348224768107, 3.868722662559725, 3.8718201364815164, 3.8749361572704877, 3.8780796602584897, 3.8812604088188434, 3.8844971094507943, 3.8878214089312717, 3.8912663282494884, 3.894864479713304, 3.898638763467132, 3.902590076156103, 3.9067031954585585, 3.91096174229129, 3.9153499818353787, 3.919864271330296, 3.924506153878256, 3.929270948481532, 3.934153602071876, 3.9391491595386094, 3.94425236255844, 3.9494411350925427, 3.9546822462305684, 3.959942220664062, 3.96518763529611, 3.9703866701104453, 3.9755112348857127, 3.980533564338391, 3.9854258712528137, 3.990159754224642, 3.994703863250308, 3.999049799814421, 4.003200259352585, 4.007157985611427, 4.010925894507145, 4.0145057467803404, 4.017888364311316, 4.02106134180385, 4.024012272725989, 4.026729081372752, 4.0292170086947365, 4.03152443884595, 4.033707621241018, 4.03582280529457, 4.037924695129448, 4.040051936800477, 4.042232822001559, 4.044495523402502, 4.046868213673126, 4.049379776856646, 4.052054591932041, 4.054900720794279, 4.057924260330857, 4.061131307429265, 4.064527973930105, 4.06811754336104, 4.071899190246934, 4.075871818116593, 4.0800343304988305, 4.0843861292781245, 4.088930068319431, 4.093670678033197, 4.098612518740377, 4.103760150761935, 4.1091178887613875, 4.114688326287613, 4.120473220701564, 4.126474318043803, 4.132693364354878, 4.139133414092452, 4.145808194328643, 4.152736698018403, 4.159937957146172, 4.167431003696379, 4.175234869653474, 4.183368587001883, 4.191851187726047, 4.200701703810405, 4.209939167239391},
|
||||
.param_5 = {10.024004905550221, 9.228932013911217, 7.811876878580248, 6.7366432856607705, 5.930016523545989, 5.269214856210924, 4.732755000726918, 4.274809187675466, 3.817753966333637, 3.3697919256441278, 2.8960991954344095, 2.361981557069992, 1.8271825477905956, 1.3925681371210974, 1.0991926676831465, 0.9103497192745724, 0.7923673146955412, 0.7239501018296401, 0.677840801564189, 0.6412666488655461, 0.6099031296518564, 0.5829481689774596, 0.5692520215289765, 0.5679786240845086, 0.5761552807871162, 0.5978062751567759, 0.6290168388372042, 0.6710069942740926, 0.7273723769197105, 0.7843023123260462, 0.820050607797107, 0.8329710493770293, 0.8298296125151872, 0.8127433150383112, 0.7890909975180715, 0.7664339023210065, 0.7509708780752966, 0.7393064807925231, 0.7297916831095375, 0.7258175103793896, 0.7193013771094048, 0.7108867786414841, 0.7046301666191024, 0.6947294361071776, 0.6763086524672168, 0.6546343562183754, 0.6388298614387278, 0.6091854572451538, 0.5902278747664802, 0.6220092372607677, 0.6561033670109406, 0.654881378239569, 0.6406614711363279, 0.6355861603350554, 0.6392577165685864, 0.644202342346567, 0.6476345945752637, 0.6511908815754808, 0.6561661581309775, 0.6620373776915933, 0.6678415389738568, 0.6730557625424183, 0.6779288185291055, 0.6832272760318059, 0.6890490014415107, 0.6946558119815816, 0.6993586737593649, 0.7033376300861427, 0.7073483761338206, 0.7120349029623885, 0.7176315921230358, 0.7242848728883811, 0.732958203090428, 0.7441286949666726, 0.7568330380973709, 0.7707270903847263, 0.7873404563465414, 0.8075693992863453, 0.8294127813734509, 0.8495990182679325, 0.8668691728784594, 0.8827309176242526, 0.8984428323280724, 0.9136301364909283, 0.9276432750436214, 0.9399200183002776, 0.9494221821222393, 0.9557625743624065, 0.9604909505651182, 0.9649760724256051, 0.9681547444433392, 0.9679270634679771, 0.9643149148041097, 0.959165099385606, 0.9523684543709443, 0.9426489491269674, 0.9304926134061642, 0.916397425665938, 0.8988687562704989, 0.8772667236064624, 0.8534124003169996, 0.8291853465459464, 0.8048530265290843, 0.7810148833179209, 0.7592361771112, 0.7391742123432188, 0.7185924399848442, 0.6964919376362566, 0.6775913562142133, 0.6685282857386454, 0.6675488518945283, 0.6642825109544503, 0.6523907049149624, 0.6366574423867011, 0.6235962590996458, 0.6149843018926404, 0.6108977241059854, 0.6110167241896391, 0.6131728045518869, 0.6151126974094367, 0.6163646215529894, 0.6169871259651849, 0.6173616301077267, 0.6185314004705678, 0.6213494710762824, 0.6259523776973364, 0.6324251548355697, 0.6417449192304581, 0.6561000112428328, 0.6769218798694077, 0.7043070782032146, 0.7372435217643414, 0.7725596442799354, 0.8064431991426702, 0.8371666135186917, 0.8646786376820259, 0.8902529039005902, 0.915617204287722, 0.9406677151235776, 0.9647448193620178, 0.9878211057077646, 1.0098760486563663, 1.0291975553933241, 1.0429883672128604, 1.0501085571519297, 1.050538906554177, 1.0444449446383341, 1.0323599589602495, 1.014689422794568, 0.9914636367100993, 0.962618988625108, 0.927799199749435, 0.8890045589779128, 0.8496396102277259, 0.8108185797006229, 0.7725635154559818, 0.7347761168913003, 0.6962469804171256, 0.655559502350922, 0.6123908414672918, 0.5667739568901986, 0.5204735968747265, 0.47953574731982584, 0.44906125462818025, 0.429836644862025, 0.421707388842929, 0.4229131505907091, 0.4308126872111018, 0.4443586602024929, 0.4635391671567568, 0.4884253454143561, 0.5186378258914992, 0.5520943937633582, 0.5869668398815975, 0.6230586634985436, 0.6603713599247385, 0.6986235931774942, 0.7371216316829354, 0.7754274755553681, 0.8135140251896544, 0.8514311161531118, 0.8895737820600935, 0.9284548755072564, 0.9682450420945621, 1.0089472728737725, 1.0505370021010485, 1.0928175525678263, 1.1355331940176683, 1.1785991756189773, 1.2220143653314253, 1.2659096048649232, 1.311482997376423, 1.3603283925951004, 1.4129762817529645, 1.4694305677975805, 1.5296912507301919, 1.5937583305504432, 1.661631807257269, 1.7333116808521787, 1.8087979513343733, 1.8474926857971141},
|
||||
.param_6 = {0.06390066534648171, 0.055974296783842636, 0.04210336189556505, 0.03225590491347367, 0.026050993848189583, 0.02205432022310482, 0.019364571800666898, 0.017788549738874868, 0.017600885206374883, 0.019175835365728183, 0.02238955558640049, 0.026998361371987127, 0.030861413704093947, 0.03098334602271227, 0.02658179629158766, 0.019630832519239756, 0.013036108452897287, 0.008161299505633242, 0.004926921836541165, 0.002960691092182473, 0.0017895988919996845, 0.0009806547169949778, 0.00023310594657567426, -0.0004351800421484212, -0.0011154902985115922, -0.0019909176852191267, -0.0028853490218155404, -0.0038509964872004854, -0.00485364565019691, -0.005405960874751717, -0.005140926810309458, -0.004159812354350529, -0.0028815246813226744, -0.0015646334082011586, -0.0004041537630805527, 0.00040339176171078073, 0.0005508435963998669, 0.00027323976727749457, 1.3277191662620469e-05, -0.00016569695767090938, -0.00010189800424523937, 1.0749722630730538e-05, 8.277408680960766e-05, 0.0001949058169728533, 0.0005198826953932537, 0.0010841696028483128, 0.001161376119828764, 0.0012556115276645156, 0.0013841866996437972, 0.0004618172297673974, -0.0006047949439180533, -0.0008357730590838927, -0.0006504417627544394, -0.0005488380471148401, -0.0005548464680460175, -0.0005118471757027622, -0.0003540669435837693, -0.00012882093879458165, 0.00011955019838922839, 0.00038359025904151616, 0.0006620989347574989, 0.0009460187268469945, 0.0012072254069199588, 0.001426210527094503, 0.001633137572327529, 0.0018752536748661928, 0.002162322263264652, 0.0024752847720151327, 0.0028016246326288585, 0.0031340154718099613, 0.0034603409585715478, 0.003746491446374246, 0.0039051326475388263, 0.003872032404939894, 0.003654184751245541, 0.0032680888651454155, 0.002737152152497789, 0.002123775754564545, 0.0014812432603138357, 0.0008535762561250397, 0.0002927698598734065, -0.00018051871620761414, -0.0005678888209559842, -0.0008754219713959918, -0.0011070757482103614, -0.0012651048739806285, -0.0013565472343041386, -0.001405860023664351, -0.0014244349623338767, -0.0013909104661903944, -0.0012906760827222329, -0.0011684945790750305, -0.0011281355919010726, -0.001211381375944108, -0.0013130009322308372, -0.0013182310873780822, -0.001210830823752629, -0.000983332813709339, -0.0006190550891483547, -0.00021546156786531945, 8.202419116776157e-05, 0.00024723025818277163, 0.00036373063910452857, 0.00048359147831580137, 0.0005745519261575469, 0.0006096148048310289, 0.0006217579660145151, 0.000679819711396952, 0.0007374697587618767, 0.0006286901764397048, 0.0003269464962889512, 5.195209073256151e-05, -9.551642937119563e-06, 6.580435239642919e-05, 0.0001306610511417527, 0.00014087473255878987, 9.003954040762564e-05, -2.7255663470524108e-05, -0.00017046491397286535, -0.0002879365553460268, -0.00036801546175929857, -0.0004155580477498978, -0.00044594512290976375, -0.0004867745401976098, -0.0005583527933826298, -0.0006642503076976745, -0.0008097784935555958, -0.0010153053446834708, -0.0013188046486572198, -0.0017461496052425347, -0.0022969844001769664, -0.002888946940011204, -0.0033478370576448587, -0.003545613898299649, -0.003446822660416456, -0.0030542306058586807, -0.002478575434505418, -0.0019064834736640763, -0.001406499190900073, -0.0009647966661796694, -0.0005812560409013687, -0.0002694318990707626, -3.3148297755774886e-05, 0.00015382203500539698, 0.0003094106389832607, 0.0004337651451246147, 0.0005205459967647997, 0.0005648943139298943, 0.0005714261619064282, 0.0005437837026319575, 0.0004872907186746653, 0.0004659596816385304, 0.0005299712226115139, 0.0006472291316028309, 0.0007940784735916312, 0.0009689024877298905, 0.0011576013288258553, 0.0013569837715921539, 0.0015826433677067842, 0.0018407590046311114, 0.0021288496577484646, 0.0024018180215245924, 0.0025367273180535105, 0.002438043840222066, 0.002090557601487281, 0.001506916442346932, 0.0008040062107898547, 0.00012955143805165408, -0.0004744163153212234, -0.0010093520125732413, -0.0014822198710953251, -0.0019295888883334054, -0.002359867468393757, -0.0027470570619279157, -0.0030863554955464522, -0.00337875949855471, -0.0036267949436525502, -0.003826910902132716, -0.0039734679744781, -0.004065906833259636, -0.004108532306345381, -0.004133894965632409, -0.004182430582763854, -0.004266446002036586, -0.004386058040155663, -0.004539235635136812, -0.0047112457223153735, -0.004884101498628796, -0.00505247771782731, -0.005216333934041583, -0.005380006639596111, -0.005580573862448354, -0.005866166051326995, -0.006252276349538299, -0.006739008987236114, -0.007326363964444468, -0.008014341281168519, -0.008802940937379072, -0.00969216293309847, -0.010682007268319832, -0.011202085020803419},
|
||||
.param_7 = {0.0, 0.0, 0.0, 0.0, 0.0, 4.589664155663656e-06, 2.4622425624491888e-05, 4.465518709332012e-05, 6.468794856214834e-05, 8.472071003097656e-05, 0.0001047534714998048, 0.00012478623296863304, 0.00014892432660508053, 0.0001731067002211716, 0.0001972890738372627, 0.00020767287844226882, 0.000206662606300453, 0.00020950383104841917, 0.0002131889320992167, 0.00021687403315001418, 0.0002179152965350532, 0.00021942616518329038, 0.00022335389837744893, 0.00022728163157160745, 0.00022933313050615346, 0.00023184151607508975, 0.00023537924908356982, 0.00023891698209205025, 0.00024094327906176342, 0.00024415982946391973, 0.0002473763798660759, 0.0002502646318005391, 0.0002532038619411588, 0.0002561430920817784, 0.00025966232006033335, 0.0002624532716404896, 0.0002664914979099664, 0.0002688503103649192, 0.0002729802646056261, 0.0002741896507378643, 0.00027749839374428885, 0.00027642949375037253, 0.0002768085436336016, 0.0002721168301686504, 0.00026645710510934603, 0.0002563090164021092, 0.0002371716245619384, 0.00020726564577319456, 0.0001660480235067462, 0.00011518066996049285, 9.148973164434705e-05, 0.00011919493893618105, 0.0002050156385597259, 0.000261213963197227, 0.000283633929529793, 0.0002940419314819351, 0.0003060615897809799, 0.00031144656966395555, 0.000310787434342282, 0.00031482673866895633, 0.00031127059362731147, 0.00033067312874271026, 0.000324360928988764, 0.0002980836178499905, 0.00026000216427733767, 0.00021443944199333513, 0.00015952373568418277, 9.89137726756004e-05, 4.097671475264453e-05, -4.162746264938769e-06, -2.9685401867836742e-05, -3.6076841028852895e-05, -2.841964902423192e-05, -1.3731655049568225e-05, 2.938544758519417e-06, 1.9105743435440834e-05, 3.263092800019189e-05, 4.7032611415550215e-05, 6.410488822663757e-05, 7.656163306871036e-05, 7.996608634790817e-05, 8.002596021529934e-05, 7.524545398860452e-05, 6.75269305268009e-05, 6.285803974112887e-05, 6.539035247652072e-05, 6.534931888845442e-05, 7.394250001335406e-05, 8.674954515172349e-05, 0.00010726998668227427, 0.00015047281481139787, 0.0002044091095358446, 0.00022595972777076097, 0.00022511493560439547, 0.00021769413198664204, 0.00020933868880660729, 0.0002029023522709163, 0.00019906454401806615, 0.0001993257177439922, 0.00020585748814484862, 0.0002161605513416413, 0.0002231854324894868, 0.00022457622169123003, 0.00021304231689499647, 0.0001798419578124575, 0.00019050799119098058, 0.0002465194771556287, 0.00030320193311034633, 0.00034177455764355984, 0.0003677771315750484, 0.00038865219779758275, 0.0004076245342936212, 0.00042481904315509045, 0.00044040178399620773, 0.0004560727436781822, 0.0004716259933966117, 0.00048754111755368524, 0.0005054551108751308, 0.000446041365240528, 0.00029059164095576664, 0.00014297642986878278, 2.6513780838961244e-06},
|
||||
.param_8 = {0.0, 0.0, 0.0, 0.0, 0.0, -5.354608181607611e-05, -0.00028726163228573936, -0.0005209771827554024, -0.0005553421488133927, -0.0005215666486331328, -0.0004877911484528724, -0.0004540156482726125, -0.0004681356900479111, -0.00048277233158571745, -0.0004660807381101149, 0.0001091157190085829, 0.00112108511808879, 0.0020881203867882075, 0.0030453104319545896, 0.004032273234544439, 0.005158616512485668, 0.006329298786164226, 0.007471784306807044, 0.008629126843234629, 0.009907491114414942, 0.011262903027411193, 0.012606305886946105, 0.013988004856403275, 0.015515153034412319, 0.01705886231512021, 0.01863438757996438, 0.020340368971211078, 0.022096137310633455, 0.023884973419801055, 0.025800014592768764, 0.027752704526964506, 0.029803732766828128, 0.03197439654843555, 0.0341929900735225, 0.0366188858505792, 0.03907616946286763, 0.041806063831270904, 0.04466082563788864, 0.04780946452947749, 0.051366534996538996, 0.055429949393572486, 0.060389548420481276, 0.06682460206547235, 0.07563167482342388, 0.0880822477724201, 0.10362884845561667, 0.12084838967641315, 0.13644177622962433, 0.1496562183708567, 0.16199623289669354, 0.17465604038709703, 0.18797139030446855, 0.20181074864585535, 0.21609499862311346, 0.23119559354650457, 0.24732345826153507, 0.26276462860564587, 0.2785204132991132, 0.294036035677315, 0.30913366261728903, 0.3238449765036891, 0.338227662566263, 0.3522659280015699, 0.36579729755308626, 0.37873129017677454, 0.3910390801896328, 0.4026804700836469, 0.4138218763986154, 0.42460232231902656, 0.4351052590434777, 0.4454818175398851, 0.4558357365071543, 0.46618415040572836, 0.4767044115449421, 0.48757795195102444, 0.4989573442640563, 0.5110340959636758, 0.5240523756887242, 0.5380744495054993, 0.5529005931101967, 0.5683197423141702, 0.584557695359627, 0.6007947139911333, 0.6169731626329407, 0.6328669659556952, 0.6478152188828319, 0.6612353420694584, 0.6735481017209193, 0.6850284324258193, 0.6957584142341554, 0.7059063591899498, 0.7156288360527459, 0.7251635611534106, 0.7347212272023823, 0.7445133851422729, 0.7548714603812718, 0.7662516960199388, 0.7789585263964247, 0.7937144035611228, 0.8121345912448474, 0.8345285064497837, 0.8554015179573848, 0.8723445639502414, 0.8866213705553317, 0.8991507573113925, 0.9103502517001649, 0.9205585370110717, 0.9299847385380092, 0.9387829032314969, 0.9470169278760265, 0.9547767692184588, 0.962103716934853, 0.969014771058139, 0.9764550940283204, 0.9846956822786447, 0.9925593328551042, 0.9998983638401178},
|
||||
.param_9 = {1.1333265433289479, 0.7126364226894844, 0.4902940361270024},
|
||||
.param_10 = {67.20511187549674, 58.9137828346277, 50.1488285833026, 1029.72378355516, 1049.97048702506, 977.148982320782},
|
||||
.param_11 = {0.6445595366332179, 0.342264806674364, 0.2145355532702, 0.514446954779002, 0.262602991900322, 0.160144933890648},
|
||||
.param_12 = {0.273949348856685, 0.2728026137921193, 0.2692334313708398},
|
||||
.name = {'E', 'x', 'a', 'm', 'p', 'l', 'e'},
|
||||
309
src/main.c
309
src/main.c
@@ -1,107 +1,262 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Libre Solar Technologies GmbH
|
||||
*
|
||||
* Scout Battery Test - nPM1300 Fuel Gauge Monitor
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/device.h>
|
||||
#include <zephyr/drivers/uart.h>
|
||||
|
||||
#include <zephyr/drivers/sensor.h>
|
||||
#include <zephyr/drivers/sensor/npm1300_charger.h>
|
||||
#include <nrf_fuel_gauge.h>
|
||||
#include <string.h>
|
||||
|
||||
/* change this to any other UART peripheral if desired */
|
||||
#define UART_DEVICE_NODE DT_CHOSEN(zephyr_shell_uart)
|
||||
|
||||
#define MSG_SIZE 32
|
||||
|
||||
/* queue to store up to 10 messages (aligned to 4-byte boundary) */
|
||||
K_MSGQ_DEFINE(uart_msgq, MSG_SIZE, 10, 4);
|
||||
#define MSG_SIZE 256
|
||||
#define BATTERY_CAPACITY_MAH 500.0f
|
||||
|
||||
static const struct device *const uart_dev = DEVICE_DT_GET(UART_DEVICE_NODE);
|
||||
static const struct device *charger_dev;
|
||||
static int64_t ref_time;
|
||||
|
||||
/* receive buffer used in UART ISR callback */
|
||||
static char rx_buf[MSG_SIZE];
|
||||
static int rx_buf_pos;
|
||||
/* Battery model from SDK sample */
|
||||
static const struct battery_model battery_model = {
|
||||
#include "battery_model.inc"
|
||||
};
|
||||
|
||||
/*
|
||||
* Read characters from UART until line end is detected. Afterwards push the
|
||||
* data to the message queue.
|
||||
*/
|
||||
void serial_cb(const struct device *dev, void *user_data)
|
||||
{
|
||||
uint8_t c;
|
||||
/* nPM1300 charger status bitmasks */
|
||||
#define NPM1300_CHG_STATUS_COMPLETE_MASK BIT(1)
|
||||
#define NPM1300_CHG_STATUS_TRICKLE_MASK BIT(2)
|
||||
#define NPM1300_CHG_STATUS_CC_MASK BIT(3)
|
||||
#define NPM1300_CHG_STATUS_CV_MASK BIT(4)
|
||||
|
||||
if (!uart_irq_update(uart_dev)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!uart_irq_rx_ready(uart_dev)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* read until FIFO empty */
|
||||
while (uart_fifo_read(uart_dev, &c, 1) == 1) {
|
||||
if ((c == '\n' || c == '\r') && rx_buf_pos > 0) {
|
||||
/* terminate string */
|
||||
rx_buf[rx_buf_pos] = '\0';
|
||||
|
||||
/* if queue is full, message is silently dropped */
|
||||
k_msgq_put(&uart_msgq, &rx_buf, K_NO_WAIT);
|
||||
|
||||
/* reset the buffer (it was copied to the msgq) */
|
||||
rx_buf_pos = 0;
|
||||
} else if (rx_buf_pos < (sizeof(rx_buf) - 1)) {
|
||||
rx_buf[rx_buf_pos++] = c;
|
||||
}
|
||||
/* else: characters beyond buffer size are dropped */
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Print a null-terminated string character by character to the UART interface
|
||||
*/
|
||||
void print_uart(char *buf)
|
||||
static void print_uart(const char *buf)
|
||||
{
|
||||
int msg_len = strlen(buf);
|
||||
|
||||
for (int i = 0; i < msg_len; i++) {
|
||||
uart_poll_out(uart_dev, buf[i]);
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
static int read_sensors(float *voltage, float *current, float *temp, int32_t *chg_status)
|
||||
{
|
||||
char tx_buf[MSG_SIZE];
|
||||
|
||||
if (!device_is_ready(uart_dev)) {
|
||||
printk("UART device not found!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* configure interrupt and callback to receive data */
|
||||
int ret = uart_irq_callback_user_data_set(uart_dev, serial_cb, NULL);
|
||||
struct sensor_value value;
|
||||
int ret;
|
||||
|
||||
ret = sensor_sample_fetch(charger_dev);
|
||||
if (ret < 0) {
|
||||
if (ret == -ENOTSUP) {
|
||||
printk("Interrupt-driven UART API support not enabled\n");
|
||||
} else if (ret == -ENOSYS) {
|
||||
printk("UART device does not support interrupt-driven API\n");
|
||||
} else {
|
||||
printk("Error setting UART callback: %d\n", ret);
|
||||
}
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
uart_irq_rx_enable(uart_dev);
|
||||
|
||||
print_uart("Hello! I'm your echo bot.\r\n");
|
||||
print_uart("Tell me something and press enter:\r\n");
|
||||
sensor_channel_get(charger_dev, SENSOR_CHAN_GAUGE_VOLTAGE, &value);
|
||||
*voltage = (float)value.val1 + ((float)value.val2 / 1000000);
|
||||
|
||||
/* Use die temp since no thermistor connected, clamp to model range 5-45C */
|
||||
sensor_channel_get(charger_dev, SENSOR_CHAN_DIE_TEMP, &value);
|
||||
*temp = (float)value.val1 + ((float)value.val2 / 1000000);
|
||||
if (*temp < 5.0f) *temp = 5.0f;
|
||||
if (*temp > 45.0f) *temp = 45.0f;
|
||||
|
||||
sensor_channel_get(charger_dev, SENSOR_CHAN_GAUGE_AVG_CURRENT, &value);
|
||||
*current = (float)value.val1 + ((float)value.val2 / 1000000);
|
||||
|
||||
sensor_channel_get(charger_dev, SENSOR_CHAN_NPM1300_CHARGER_STATUS, &value);
|
||||
*chg_status = value.val1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const char *charge_status_str(int32_t chg_status)
|
||||
{
|
||||
if (chg_status & NPM1300_CHG_STATUS_COMPLETE_MASK) return "FULL";
|
||||
if (chg_status & NPM1300_CHG_STATUS_CV_MASK) return "CHARGING(topping)";
|
||||
if (chg_status & NPM1300_CHG_STATUS_CC_MASK) return "CHARGING(fast)";
|
||||
if (chg_status & NPM1300_CHG_STATUS_TRICKLE_MASK) return "CHARGING(trickle)";
|
||||
return "NOT_CHARGING";
|
||||
}
|
||||
|
||||
static void print_init_config(void)
|
||||
{
|
||||
char buf[MSG_SIZE];
|
||||
struct sensor_value val;
|
||||
|
||||
print_uart("\r\n=== nPM1300 Configuration ===\r\n");
|
||||
|
||||
/* DTS Config */
|
||||
snprintk(buf, sizeof(buf), "Battery capacity: %.0f mAh (configured)\r\n",
|
||||
(double)BATTERY_CAPACITY_MAH);
|
||||
print_uart(buf);
|
||||
|
||||
snprintk(buf, sizeof(buf), "Term voltage: %d mV\r\n",
|
||||
DT_PROP(DT_NODELABEL(charger), term_microvolt) / 1000);
|
||||
print_uart(buf);
|
||||
|
||||
snprintk(buf, sizeof(buf), "Charge current: %d mA\r\n",
|
||||
DT_PROP(DT_NODELABEL(charger), current_microamp) / 1000);
|
||||
print_uart(buf);
|
||||
|
||||
snprintk(buf, sizeof(buf), "Discharge limit: %d mA\r\n",
|
||||
DT_PROP(DT_NODELABEL(charger), dischg_limit_microamp) / 1000);
|
||||
print_uart(buf);
|
||||
|
||||
snprintk(buf, sizeof(buf), "VBUS limit: %d mA\r\n",
|
||||
DT_PROP(DT_NODELABEL(charger), vbus_limit_microamp) / 1000);
|
||||
print_uart(buf);
|
||||
|
||||
snprintk(buf, sizeof(buf), "Thermistor: %d ohms (0=disabled)\r\n",
|
||||
DT_PROP(DT_NODELABEL(charger), thermistor_ohms));
|
||||
print_uart(buf);
|
||||
|
||||
/* Runtime config from sensor - read after fetch */
|
||||
if (sensor_sample_fetch(charger_dev) == 0) {
|
||||
sensor_channel_get(charger_dev, SENSOR_CHAN_GAUGE_DESIRED_CHARGING_CURRENT, &val);
|
||||
snprintk(buf, sizeof(buf), "Actual charge current limit: %d mA\r\n",
|
||||
val.val1 * 1000 + val.val2 / 1000);
|
||||
print_uart(buf);
|
||||
}
|
||||
|
||||
if (sensor_attr_get(charger_dev, SENSOR_CHAN_NPM1300_CHARGER_VBUS_STATUS,
|
||||
SENSOR_ATTR_NPM1300_CHARGER_VBUS_PRESENT, &val) == 0) {
|
||||
snprintk(buf, sizeof(buf), "VBUS present: %s\r\n", val.val1 ? "yes" : "no");
|
||||
print_uart(buf);
|
||||
}
|
||||
|
||||
print_uart("==============================\r\n\r\n");
|
||||
}
|
||||
|
||||
static int fuel_gauge_init_custom(void)
|
||||
{
|
||||
char buf[MSG_SIZE];
|
||||
struct nrf_fuel_gauge_init_parameters parameters = {
|
||||
.model = &battery_model,
|
||||
.opt_params = NULL,
|
||||
.state = NULL,
|
||||
};
|
||||
float max_charge_current;
|
||||
float term_charge_current;
|
||||
int32_t chg_status;
|
||||
int ret;
|
||||
|
||||
snprintk(buf, sizeof(buf), "nRF Fuel Gauge version: %s\r\n", nrf_fuel_gauge_version);
|
||||
print_uart(buf);
|
||||
|
||||
/* Read initial sensor values */
|
||||
ret = read_sensors(¶meters.v0, ¶meters.i0, ¶meters.t0, &chg_status);
|
||||
if (ret < 0) {
|
||||
snprintk(buf, sizeof(buf), "Error reading sensors: %d\r\n", ret);
|
||||
print_uart(buf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
snprintk(buf, sizeof(buf), "Initial: V=%.3fV I=%.3fA T=%.1fC status=%s\r\n",
|
||||
(double)parameters.v0, (double)parameters.i0, (double)parameters.t0,
|
||||
charge_status_str(chg_status));
|
||||
print_uart(buf);
|
||||
|
||||
/* Initialize fuel gauge */
|
||||
ret = nrf_fuel_gauge_init(¶meters, NULL);
|
||||
if (ret < 0) {
|
||||
snprintk(buf, sizeof(buf), "Fuel gauge init error: %d\r\n", ret);
|
||||
print_uart(buf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Set charge current limit info */
|
||||
struct sensor_value val;
|
||||
sensor_channel_get(charger_dev, SENSOR_CHAN_GAUGE_DESIRED_CHARGING_CURRENT, &val);
|
||||
max_charge_current = (float)val.val1 + ((float)val.val2 / 1000000);
|
||||
term_charge_current = max_charge_current / 10.0f;
|
||||
|
||||
nrf_fuel_gauge_ext_state_update(NRF_FUEL_GAUGE_EXT_STATE_INFO_CHARGE_CURRENT_LIMIT,
|
||||
&(union nrf_fuel_gauge_ext_state_info_data){.charge_current_limit = max_charge_current});
|
||||
|
||||
nrf_fuel_gauge_ext_state_update(NRF_FUEL_GAUGE_EXT_STATE_INFO_TERM_CURRENT,
|
||||
&(union nrf_fuel_gauge_ext_state_info_data){.charge_term_current = term_charge_current});
|
||||
|
||||
print_uart("Fuel gauge initialized OK\r\n");
|
||||
snprintk(buf, sizeof(buf), "NOTE: Using SDK example model, capacity=%.0f mAh\r\n",
|
||||
(double)BATTERY_CAPACITY_MAH);
|
||||
print_uart(buf);
|
||||
|
||||
ref_time = k_uptime_get();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char buf[MSG_SIZE];
|
||||
int ret;
|
||||
int tick = 0;
|
||||
|
||||
if (!device_is_ready(uart_dev)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
print_uart("\r\n*** Scout Battery Test - Fuel Gauge ***\r\n");
|
||||
|
||||
charger_dev = DEVICE_DT_GET_OR_NULL(DT_NODELABEL(charger));
|
||||
if (charger_dev == NULL || !device_is_ready(charger_dev)) {
|
||||
print_uart("ERROR: Charger device not available\r\n");
|
||||
while (1) { k_sleep(K_FOREVER); }
|
||||
}
|
||||
print_uart("Charger device: OK\r\n");
|
||||
|
||||
print_init_config();
|
||||
|
||||
ret = fuel_gauge_init_custom();
|
||||
if (ret < 0) {
|
||||
print_uart("Fuel gauge init failed, continuing without SoC\r\n");
|
||||
}
|
||||
|
||||
print_uart("\r\nStarting monitoring (3s interval)...\r\n\r\n");
|
||||
|
||||
while (1) {
|
||||
float voltage, current, temp;
|
||||
int32_t chg_status;
|
||||
struct sensor_value dietemp;
|
||||
|
||||
tick++;
|
||||
snprintk(buf, sizeof(buf), "[%d] ", tick);
|
||||
print_uart(buf);
|
||||
|
||||
ret = read_sensors(&voltage, ¤t, &temp, &chg_status);
|
||||
if (ret < 0) {
|
||||
snprintk(buf, sizeof(buf), "sensor err=%d\r\n", ret);
|
||||
print_uart(buf);
|
||||
} else {
|
||||
/* Get die temperature */
|
||||
sensor_channel_get(charger_dev, SENSOR_CHAN_DIE_TEMP, &dietemp);
|
||||
|
||||
/* Update fuel gauge */
|
||||
float delta = (float)k_uptime_delta(&ref_time) / 1000.0f;
|
||||
if (delta < 0.1f) delta = 3.0f; /* Ensure minimum delta on first call */
|
||||
float soc = nrf_fuel_gauge_process(voltage, current, temp, delta, NULL);
|
||||
float tte = nrf_fuel_gauge_tte_get();
|
||||
|
||||
/* Convert floats to integers for printing (avoid float printf issues) */
|
||||
int soc_int = (int)soc;
|
||||
int soc_frac = (int)((soc - soc_int) * 10) % 10;
|
||||
if (soc_frac < 0) soc_frac = -soc_frac;
|
||||
int v_int = (int)voltage;
|
||||
int v_frac = (int)((voltage - v_int) * 1000);
|
||||
int i_ma = (int)(current * 1000);
|
||||
int t_int = (int)temp;
|
||||
|
||||
snprintk(buf, sizeof(buf),
|
||||
"SoC=%d.%d%% V=%d.%03dV I=%dmA T=%dC die=%dC %s",
|
||||
soc_int, soc_frac, v_int, v_frac, i_ma, t_int,
|
||||
dietemp.val1, charge_status_str(chg_status));
|
||||
print_uart(buf);
|
||||
|
||||
if (tte > 0 && tte < 1000000) {
|
||||
snprintk(buf, sizeof(buf), " TTE=%ds", (int)tte);
|
||||
print_uart(buf);
|
||||
}
|
||||
print_uart("\r\n");
|
||||
}
|
||||
|
||||
k_sleep(K_SECONDS(3));
|
||||
}
|
||||
|
||||
/* indefinitely wait for input from the user */
|
||||
while (k_msgq_get(&uart_msgq, &tx_buf, K_FOREVER) == 0) {
|
||||
print_uart("Echo: ");
|
||||
print_uart(tx_buf);
|
||||
print_uart("\r\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user