watchX library 101


#1

Here is the basic (101) library for watchX. Basic codes sniplets for every project and all pin assignments are handled in the library. No more programming or copying codes from your previous watchX projects.

Usage

all names are self described in the code. Here is the basic ones. Also check for example folder.

Functions

  • inline void setup_buttons() sets pinmodes for buttons
  • inline void setup_leds() sets pinmodes for leds
  • void setup_watchx() sets buttons and leds, and initiate i2c
  • unsigned int get_batteryRaw() get battery voltage raw value from digital read. from 0 to 1024
  • float get_batteryVoltage() get battery voltage. calculated by voltage divider.
  • get_batteryPercentance() get battery capacity as percent with %5 precision. actual percent may vary on your battery condition and 3rd party batteries. This function is optimized for original watchX battery in good condition.
  • bool get_usbStatus() returns the status of usb
  • bool get_chargeStatus() returns the charging status

Defined pin names and variables

Part Defined Names
Oled OLED_CS, OLED_DC, OLED_RESET
Led LEDL, LEDR
Buttons BUTTON1 BUTTON2 BUTTON3
Buzzer BUZZER
Bluetooth BLUEFRUIT_SPI_CS, BLUEFRUIT_SPI_IRQ, BLUEFRUIT_SPI_RST
Charge CHARGESTATUS
Bmp to-do
Battery BATTERY_POWER, BATTERY_READ

const unsigned char logoWatchX [] PROGMEM this is watchX logo as bitmap image. You can use it on your favorite oled library bitmap drawer. The array size is 128x29px and uses 464bytes of memory.

FAQ

What is this library for ?

Every watchX project has repeated first lines such as pin assignments or basic battery functions. This library defines all available pins and gives you the low level fuction you need for project.

What is this library NOT for ?

This library aims the only basic level stuffs and does not deal with higher levels suchs as using OLED screen. The reason for this is since there are hardware limitations in every arduino proccessor and there is no perfect library for every hardware (OLED, bluetooth, BPM etc). So if there is something that limits some use case of minority of watchX user or not for every use case, basicly it will not include in the library for now.

Why should I use ?

  • Save time while programing basic functions and defining pins in your projects
  • Global names for pins and functions in your project for you and community, makes your project readable
  • Make your projects for future update and changes proof

There is something wrong or missing functionality ?

If you are thinking that this is why we are in this forum and this topic.

So where is this wonderful Library ?

Of course on Github. Library Link


USB Data Connection Detection with WatchX
Battery Voltage Measurement with watchX
#2

Hi,
nice Job and very well documented :+1:
Any chance you add defines for the other hardware Pins and the USB Power detection?
And maybe move the logo to an separated code part for setups with less free memory.


#3

Hi @venice1200

The aim for this library is to define all available Pins and hardware. If there are missing parts please fell free point out. As far as i know bmp is missing right now.

USB power detection should be added. I have checked your topic last night. I can add by myself or you can fork - add - send pull request to mine repo.

For the logo suggestion; we don’t have to. Compiler are design to optimise your code during compile time. So for those who are not using logo in their project, they are not wasting one (1) bit of memory in their project for logo array. You can test. Compiler simply does not add the unused arrays, functions definition, etc into your binary.

But; In the future constant arrays and other constant things should separate into another file for more code readability as you suggested.


#4

Interrupt Pins from MPU and RTC.

Please add the changes by yourself.