battery-minus

Pebble activity tracker that records battery events
git clone https://git.instinctive.eu/battery-minus.git
Log | Files | Refs | README | LICENSE

storage.h (1635B)


      1 /*
      2  * Copyright (c) 2015, Natacha Porté
      3  *
      4  * Permission to use, copy, modify, and distribute this software for any
      5  * purpose with or without fee is hereby granted, provided that the above
      6  * copyright notice and this permission notice appear in all copies.
      7  *
      8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
      9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
     10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
     11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
     13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
     14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     15  */
     16 
     17 #ifndef BATTERY_STORAGE_H
     18 #define BATTERY_STORAGE_H
     19 
     20 /* a single entry in the event log */
     21 struct __attribute__((__packed__)) event {
     22 	time_t time;
     23 	uint8_t before;
     24 	uint8_t after;
     25 };
     26 
     27 /*
     28  * after field has the following format:
     29  *  - the most significant is 1 when charging, 0 when discharging
     30  *  - the remaining 7 bits hold the battery percentage value
     31  *
     32  * before either the value before the event, using the same format as after,
     33  * or one of the following special value:
     34  *  - UNKNOWN (update from anomalous to normal value)
     35  *  - APP_STARTED
     36  *  - APP_CLOSED
     37  *  - ANOMALOUS_VALUE  (then after has the whole 8-bit value)
     38  */
     39 
     40 #define UNKNOWN         0xF0
     41 #define APP_STARTED     0xF1
     42 #define APP_CLOSED      0xF2
     43 #define ANOMALOUS_VALUE 0xF3
     44 
     45 #define PAGE_LENGTH (PERSIST_DATA_MAX_LENGTH / sizeof(struct event))
     46 
     47 #endif /* defined BATTERY_STORAGE_H */