diff --git a/watchX/lib/SSD1306/oled.cpp b/watchX/lib/SSD1306/oled.cpp index a824431..a19e3ef 100644 --- a/watchX/lib/SSD1306/oled.cpp +++ b/watchX/lib/SSD1306/oled.cpp @@ -3,8 +3,7 @@ #include #include "oled.h" - unsigned char animation_offsetY=0; - unsigned char mbuf[1024]={0}; + uint8_t uiX,uiY; /* @@ -18,22 +17,23 @@ void ssd1306_configure(){ const uint8_t s_oled128x64_initData[] = { - SSD1306_DISPLAYOFF, // display off + // SSD1306_DISPLAYOFF, // display off SSD1306_MEMORYMODE, HORIZONTAL_ADDRESSING_MODE, // Page Addressing mode SSD1306_COMSCANDEC, // Scan from 127 to 0 (Reverse scan) - SSD1306_SETSTARTLINE | 0x00, // First line to start scanning from - SSD1306_SETCONTRAST, 0x7F, // contast value to 0x7F according to datasheet +// SSD1306_SETSTARTLINE | 0x00, // First line to start scanning from + SSD1306_SETCONTRAST, 0xFF, // contast value to 0x7F according to datasheet SSD1306_SEGREMAP | 0x01, // Use reverse mapping. 0x00 - is normal mapping - SSD1306_NORMALDISPLAY, - SSD1306_SETMULTIPLEX, 63, // Reset to default MUX. See datasheet - SSD1306_SETDISPLAYOFFSET, 0x00, // no offset - SSD1306_SETDISPLAYCLOCKDIV, 0x80,// set to default ratio/osc frequency - SSD1306_SETPRECHARGE, 0xF1, // switch precharge to 0x22 // 0xF1 - SSD1306_SETCOMPINS, 0x12, // set divide ratio - SSD1306_SETVCOMDETECT, 0x40, // vcom deselect to 0x20 // 0x40 + // SSD1306_NORMALDISPLAY, + // SSD1306_SETMULTIPLEX, 63, // Reset to default MUX. See datasheet +// SSD1306_SETDISPLAYOFFSET, 0x00, // no offset +// SSD1306_SETDISPLAYCLOCKDIV, 0x80,// set to default ratio/osc frequency + // SSD1306_SETPRECHARGE, 0xF1, // switch precharge to 0x22 // 0xF1 +// SSD1306_SETCOMPINS, 0x12, // set divide ratio + // SSD1306_SETVCOMDETECT, 0x40, // vcom deselect to 0x20 // 0x40 SSD1306_CHARGEPUMP, 0x14, // Enable charge pump + // 0X20,0X80, - SSD1306_DISPLAYALLON_RESUME, + // SSD1306_DISPLAYALLON_RESUME, SSD1306_DISPLAYON }; @@ -96,9 +96,35 @@ void ssd1306_sendData(uint8_t data) void clearAll(){ //if(animation_offsetY==0) - memset(mbuf, 0x00, 128*8); + memset(mbuf, 0x00, 1024); +//for(uint16_t i=0;i<1024;i++) mbuf[i]=0; } + +/* + +for (k = 0; k < strlen_P(signMessage); k++) + { + myChar = pgm_read_byte_near(signMessage + k); + Serial.print(myChar); + } + +*/ +void drawString_P(uint8_t x,uint8_t y,const byte*s,const byte* font,char startindex){ + char c; +if(!s)return; +for(int a=0;a> (8 - pixelOffset); - //setBuffByte(buff, xx, hhhh, pixels >> (8 - pixelOffset), colour); + mbuf[xx + aaa] |= pixels >> (8 - (y % 8)); + //setBuffByte(buff, xx, hhhh, pixels >> (8 - (y % 8)), colour); } } } diff --git a/watchX/lib/SSD1306/oled.h b/watchX/lib/SSD1306/oled.h index 4c00c04..576a664 100644 --- a/watchX/lib/SSD1306/oled.h +++ b/watchX/lib/SSD1306/oled.h @@ -79,6 +79,7 @@ extern uint8_t uiX,uiY; extern unsigned char animation_offsetY; void ssd1306_drawBuffer(byte x, byte y, byte w, byte h, const byte *buf); void drawString(uint8_t x,uint8_t y,const char*s,const byte* font,char startindex=-32); +void drawString_P(uint8_t x,uint8_t y,const byte*s,const byte* font,char startindex=-32); void ssd1306_sendCommand(uint8_t command); void ssd1306_configure(); diff --git a/watchX/lib/battery/battery.h b/watchX/lib/battery/battery.h index f056d3a..2525895 100644 --- a/watchX/lib/battery/battery.h +++ b/watchX/lib/battery/battery.h @@ -10,7 +10,7 @@ -#define CHARGE_PIN PC6 +#define CHARGE_PIN 5 unsigned long readBattery(uint8_t b_en_pin,uint8_t bat_pin); extern unsigned long batterylevel; diff --git a/watchX/lib/mpu6050/tinyMpu6050.cpp b/watchX/lib/mpu6050/tinyMpu6050.cpp index 6500437..324a274 100644 --- a/watchX/lib/mpu6050/tinyMpu6050.cpp +++ b/watchX/lib/mpu6050/tinyMpu6050.cpp @@ -1,12 +1,11 @@ #include #include "tinyMpu6050.h" -int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ; -const int MPU_addr=0x69; + void startMpu6050(){ Wire.begin(); - Wire.beginTransmission(MPU_addr); + Wire.beginTransmission(0x69); Wire.write(0x6B); // PWR_MGMT_1 register Wire.write(0); // set to zero (wakes up the MPU-6050) Wire.endTransmission(true); @@ -14,15 +13,11 @@ void startMpu6050(){ } void updateMpu6050(){ - Wire.beginTransmission(MPU_addr); + Wire.beginTransmission(0x69); Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H) Wire.endTransmission(false); - Wire.requestFrom(MPU_addr,14,true); // request a total of 14 registers - AcX=Wire.read()<<8|Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L) - AcY=Wire.read()<<8|Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L) - AcZ=Wire.read()<<8|Wire.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L) - Tmp=Wire.read()<<8|Wire.read(); // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L) - GyX=Wire.read()<<8|Wire.read(); // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L) - GyY=Wire.read()<<8|Wire.read(); // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L) - GyZ=Wire.read()<<8|Wire.read(); // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L) + Wire.requestFrom(0x69,14,true); // request a total of 14 registers +for(uint8_t a=0;a<7;a++) + ac[a]=Wire.read()<<8|Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L) + } diff --git a/watchX/lib/mpu6050/tinyMpu6050.h b/watchX/lib/mpu6050/tinyMpu6050.h index 88fde53..fee329c 100644 --- a/watchX/lib/mpu6050/tinyMpu6050.h +++ b/watchX/lib/mpu6050/tinyMpu6050.h @@ -1,8 +1,8 @@ #ifndef MPU6050_H #define MPU6050_H #include - -extern int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ; + +extern int16_t ac[7]; void updateMpu6050(); void startMpu6050(); #endif diff --git a/watchX/platformio.ini b/watchX/platformio.ini index b48bc7c..b670f75 100644 --- a/watchX/platformio.ini +++ b/watchX/platformio.ini @@ -12,4 +12,5 @@ platform = atmelavr board = leonardo framework = arduino -;build_flags = -Winvalid-pch -Wall -Wno-long-long -pedantic -Os -ggdb -gstabs -fdata-sections -ffunction-sections -fsigned-char -Wl,-gc-sections +;build_flags= -Os +;build_flags = -Winvalid-pch -Wall -Wno-long-long -pedantic -Os -ggdb -gstabs -fdata-sections -ffunction-sections -fsigned-char -Wl,-gc-sections diff --git a/watchX/src/BluefruitConfig.h b/watchX/src/BluefruitConfig.h index f0fb537..9750e02 100644 --- a/watchX/src/BluefruitConfig.h +++ b/watchX/src/BluefruitConfig.h @@ -2,7 +2,7 @@ // ---------------------------------------------------------------------------------------------- // These settings are used in both SW UART, HW UART and SPI mode // ---------------------------------------------------------------------------------------------- -#define BUFSIZE 128 // Size of the read buffer for incoming data +#define BUFSIZE 64//128 // Size of the read buffer for incoming data #define VERBOSE_MODE true // If set to 'true' enables debug output diff --git a/watchX/src/batteryui.cpp b/watchX/src/batteryui.cpp deleted file mode 100644 index 43abab7..0000000 --- a/watchX/src/batteryui.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include "oled.h" -#include "battery.h" -#include "resources.h" - - void drawBattery(){ - - - -draw_bitmap( 0, 56, watchXui+(unsigned)(((batterylevel-500)/40)*16), 16, 8, false, 0); - - -} diff --git a/watchX/src/batteryui.h b/watchX/src/batteryui.h deleted file mode 100644 index 4dd5e84..0000000 --- a/watchX/src/batteryui.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef BATTERY_UI -#define BATTERY_UI - -void drawBattery(); - -#endif diff --git a/watchX/src/bluetooth.cpp b/watchX/src/bluetooth.cpp index ed4d990..acf78e1 100644 --- a/watchX/src/bluetooth.cpp +++ b/watchX/src/bluetooth.cpp @@ -24,7 +24,7 @@ if(ble.available()){ i=0; strtmpbuf[i++]=ble.read(); - + } @@ -36,9 +36,10 @@ if(ble.available()){ i=0; } } } + const char title[] PROGMEM="< INCOMING MESSAGE >"; void drawBle(){ /// TODO do we need ? - drawString(4,0,"< INCOMING MESSAGE >",smallFont); + drawString_P(4,0,title,smallFont); drawString(0,8,strtmpbuf,smallFont); } @@ -51,15 +52,15 @@ void ble_connect(){ //error(F("Couldn't find Bluefruit, make sure it's in CoMmanD mode & check wiring?")); } -/* + /* if ( FACTORYRESET_ENABLE ) { if ( ! ble.factoryReset() ){ // error(F("Couldn't factory reset")); } } -*/ - /* Disable command echo from Bluefruit */ + + Disable command echo from Bluefruit */ // ble.echo(false); // ble.verbose(false); // debug info is a little annoying after this point! diff --git a/watchX/src/bluetooth.h b/watchX/src/bluetooth.h index ec4aa91..4f41bcf 100644 --- a/watchX/src/bluetooth.h +++ b/watchX/src/bluetooth.h @@ -17,8 +17,8 @@ #include #endif -#define MINIMUM_FIRMWARE_VERSION "0.6.6" -#define MODE_LED_BEHAVIOUR "MODE" +//#define MINIMUM_FIRMWARE_VERSION "0.6.6" +//#define MODE_LED_BEHAVIOUR "MODE" void drawBle(); @@ -27,6 +27,6 @@ void handleBle(); void ble_connect(); void ble_sw1(); /* ...hardware SPI, using SCK/MOSI/MISO hardware SPI pins and then user selected CS/IRQ/RST */ - + #endif diff --git a/watchX/src/diag.h b/watchX/src/diag.h index 31dadd3..424d2cc 100644 --- a/watchX/src/diag.h +++ b/watchX/src/diag.h @@ -1,8 +1,8 @@ #ifndef DIAG_H #define DIAG_H -#include "usb.h" + void drawDiag(); - + #endif diff --git a/watchX/src/english.h b/watchX/src/english.h index 944e632..eb3af2b 100644 --- a/watchX/src/english.h +++ b/watchX/src/english.h @@ -13,18 +13,18 @@ // String buffer sizes // Don't forget to add 1 for null terminator -#define BUFFSIZE_STR_MENU 24 -#define BUFFSIZE_STR_DAYS 4 -#define BUFFSIZE_STR_MONTHS 4 +#define BUFFSIZE_STR_MENU 0x18 +#define BUFFSIZE_STR_DAYS 0x4 +#define BUFFSIZE_STR_MONTHS 0x4 -#define BUFFSIZE_DATE_FORMAT ((BUFFSIZE_STR_DAYS - 1) + (BUFFSIZE_STR_MONTHS - 1) + 12) -#define BUFFSIZE_TIME_FORMAT_SMALL 9 +//#define BUFFSIZE_DATE_FORMAT ((BUFFSIZE_STR_DAYS - 1) + (BUFFSIZE_STR_MONTHS - 1) + 12) +//#define BUFFSIZE_TIME_FORMAT_SMALL 9 // String formats -#define DATE_FORMAT ("%s %02hhu %s 20%02hhu") -#define TIME_FORMAT_SMALL ("%02hhu:%02hhu%c") +//#define DATE_FORMAT ("%s %02hhu %s 20%02hhu") +//#define TIME_FORMAT_SMALL ("%02hhu:%02hhu%c") @@ -42,7 +42,7 @@ #define STR_DOWCHARS "MTWTFSS" - +/* // Days // Also see BUFFSIZE_STR_DAYS #define STR_MON "Mon" @@ -68,10 +68,10 @@ #define STR_NOV "Nov" #define STR_DEC "Dec" - +*/ // Menu strings // Also see BUFFSIZE_STR_MENU - +/* #define STR_MAINMENU "< MAIN MENU >" #define STR_ALARMS "Alarms" #define STR_FLASHLIGHT "Flashlight" @@ -135,7 +135,7 @@ #define STR_HIGHSCORE "Highscore:" #define STR_NEWHIGHSCORE "!NEW HIGHSCORE!" - +*/ // Little images (8x8) for showing day of week of next alarm on main screen /* diff --git a/watchX/src/gyrocube.cpp b/watchX/src/gyrocube.cpp index 8a7fd76..8379bd8 100644 --- a/watchX/src/gyrocube.cpp +++ b/watchX/src/gyrocube.cpp @@ -1,6 +1,7 @@ #include "gyrocube.h" #include "oled.h" #include + #include "watchX.h" //3D_Cube for Arduino OLED module by Colin Ord, 9/1/2015 //A port of my original JustBasic Cube_3D demo to the Arduino Uno using U8G library. @@ -9,23 +10,24 @@ float r, x1, ya, z1, x2, y2, z2, x3, y3, z3; // int f[8][2]; // Draw box -int x = 64; // 64=128/2 -int y = 32; // 32= 64/2 -int c[8][3] = { // Cube - {-20,-20, 20},{20,-20, 20},{20,20, 20},{-20,20, 20}, // - {-20,-20,-20},{20,-20,-20},{20,20,-20},{-20,20,-20} }; // - - +//int x = 64; // 64=128/2 +//int y = 32; +int16_t a; // 32= 64/2 -int16_t a; void gyroCube(uint8_t scale){ float sinr,cosr; + +int8_t c[8][3] = { // Cube + {-20,-20, 20},{20,-20, 20},{20,20, 20},{-20,20, 20}, // + {-20,-20,-20},{20,-20,-20},{20,20,-20},{-20,20,-20} }; // + + if(functions[uiFunc]!=drawGyroCube) a++; else if(animation_offsetY==0) - a=GyX; + a=ac[4]/50; for(uint8_t i=0;i<8;i++){ c[i][0]=c[i][0]>0?scale:-scale; @@ -46,8 +48,8 @@ c[i][0]=c[i][0]>0?scale:-scale; x3 = x2 * cosr - y2 * sinr; // rotate Z y3 = x2 * sinr + y2 * cosr; // z3 = z2; // - x3 = x3 + x ; // - y3 = y3 + y ; // + x3 = x3 + 64 ; // + y3 = y3 + 32 ; // f[i][0] = x3; // store new values f[i][1] = y3; // f[i][2] = z3; // diff --git a/watchX/src/menu.cpp b/watchX/src/menu.cpp index 603cd68..8a08e3f 100644 --- a/watchX/src/menu.cpp +++ b/watchX/src/menu.cpp @@ -15,7 +15,7 @@ int scrollto=0; int menuindex=0; - +int targetmenuindex=0; void menusw1( ){ @@ -38,7 +38,7 @@ void menusw1( ){ gotoBlueTooth(); break; case MENU_DIAGNOSTIC: - gotoDiagnostic(); + // gotoDiagnostic(); break; case MENU_SETTINGS: @@ -66,25 +66,38 @@ void menusw1( ){ void menusw2( ){ //if(animation_offsetY==0) - menuspeed=-2; - +if(animation_offsetY==0) + if(menuindex0){ - menuspeed=2; + targetmenuindex=menuindex-1; + menuspeed=3; + }else{ +targetmenuindex=MENUCOUNT-1; + menuspeed=-5; } } /* When memory is dynamically allocated, the atmega chip cannot allocate memory ... */ -const char menuCap[][15] ={"Exit","Stopwatch","Gyrocube","Diagnostic","Bluetooth","Settings"}; +const char title[] PROGMEM= "< MAIN MENU >"; +const char menuCap[][15] PROGMEM ={"Exit","Stopwatch","Gyrocube","Diagnostic","Bluetooth","Settings","About","Help"}; void drawMenus(){ ///char menuCap[][15]={"Exit","Stopwatch","Gyrocube","Diagnostic","Bluetooth","Settings"}; - drawString(26,0,"< MAIN MENU >",smallFont); - drawString(0,56,menuCap[menuindex%(sizeof(menuCap)/15)],smallFont); +//const char* title PROGMEM= "< MAIN MENU >"; + + drawString_P(26,0,title,smallFont); + drawString_P(0,56,menuCap[menuindex%MENUCOUNT],smallFont); drawLine(48,12,80,12); @@ -100,30 +113,33 @@ for( char a=-1;a<4;a++) -if(menuindex+a-1>=0){ +if(menuindex+a-1>=0&&menuindex+a-1=48){ + if(targetmenuindex==menuindex-1) menuspeed=0; _x=0; menuindex--; } - if(_x==-48){ + if(_x<=-48){ + if(targetmenuindex==menuindex+1) menuspeed=0; _x=0; menuindex++; diff --git a/watchX/src/menu.h b/watchX/src/menu.h index ddb1fa2..4a8be3f 100644 --- a/watchX/src/menu.h +++ b/watchX/src/menu.h @@ -6,6 +6,7 @@ //#define MENU_LENGTH 8 extern int menuindex; extern int menuspeed; + #define MENUCOUNT 0x08 #define MENU_WATCH 0 #define MENU_STOPWATCH 1 #define MENU_GYROCUBE 2 diff --git a/watchX/src/resources.h b/watchX/src/resources.h index cbe6966..b69059a 100644 --- a/watchX/src/resources.h +++ b/watchX/src/resources.h @@ -294,7 +294,7 @@ const byte menus_bits[] PROGMEM ={ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, }; - +/* const byte dow_bits[] PROGMEM ={ 0x0F,0x01,0x02,0x01,0x6F,0x90,0x90,0x60, 0x01,0x1F,0x01,0x00,0x78,0x80,0x80,0x78, @@ -304,7 +304,7 @@ const byte dow_bits[] PROGMEM ={ 0x12,0x15,0x09,0x00,0xF0,0x28,0x28,0xF0, 0x12,0x15,0x09,0x00,0x78,0x80,0x80,0x78, }; - +*/ // 5x8 const byte smallFont[] PROGMEM ={ diff --git a/watchX/src/settings.cpp b/watchX/src/settings.cpp index f1efb00..7c1d02b 100644 --- a/watchX/src/settings.cpp +++ b/watchX/src/settings.cpp @@ -2,10 +2,10 @@ #include #include "oled.h" #include "watchX.h" - +const char title[] PROGMEM = "< SETTINGS >"; void drawSettings(){ - drawString(28,0,"< SETTINGS >",smallFont); + drawString_P(28,0,title,smallFont); @@ -19,5 +19,5 @@ void settingsSw1(){ void settingsSw2(){ - + } diff --git a/watchX/src/soundfx.cpp b/watchX/src/soundfx.cpp index 87214ff..0a62028 100644 --- a/watchX/src/soundfx.cpp +++ b/watchX/src/soundfx.cpp @@ -1,9 +1,9 @@ #include -bool soundenabled=false; + bool outEnabled(){ - return soundenabled; + return true; } Tones sound(outEnabled); diff --git a/watchX/src/usb.cpp b/watchX/src/usb.cpp deleted file mode 100644 index af24762..0000000 --- a/watchX/src/usb.cpp +++ /dev/null @@ -1,37 +0,0 @@ - -//#include - - #include "usb.h" -#include "battery.h" -#include "oled.h" -#include "resources.h" - - - - -void drawUsb( ){ - - - -//uint8_t buf[32*2]; - - //NanoCanvas c(24,8,buf); - if(DEVICESTATE&128){ - // draw_bitmap(40, 0, watchXui,8,8,false,0); -//if(digitalRead(CHARGE_PIN)==LOW&& batterylevel<630) -draw_bitmap( 36, 56, watchXui+64, 8, 8, false, 0); -// -draw_bitmap(18, 56, watchXui+80,16,8,false,0); - -// - - } - - -// sprite = ssd1306_createSprite( 112, 56, 16, usbIcon ); - - /* Draw sprite on the display */ -// sprite.draw(); - - -} diff --git a/watchX/src/usb.h b/watchX/src/usb.h deleted file mode 100644 index 63a24d8..0000000 --- a/watchX/src/usb.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef USB_H -#define USB_H -//#include -//#include "resources.h" - -void drawUsb( ); - -#endif diff --git a/watchX/src/watchX.cpp b/watchX/src/watchX.cpp index edbed72..9f45141 100644 --- a/watchX/src/watchX.cpp +++ b/watchX/src/watchX.cpp @@ -1,6 +1,6 @@ -#include +//#include #include #include //#include @@ -14,7 +14,7 @@ //#include "pressure.h" #include "resources.h" -#include "usb.h" + #include "watchface.h" #include "menu.h" @@ -30,8 +30,8 @@ #include "bluetooth.h" //#include "watchXmpu6050.h" -//#include "tinyMpu6050.h" -#include +#include "tinyMpu6050.h" +//#include #include "settings.h" @@ -69,14 +69,16 @@ int main(void) //BMP280 bmp280; - +int16_t ac[7]; +unsigned char animation_offsetY=0; + unsigned char mbuf[1024]; volatile uint8_t animating=1; const uint8_t melody[]={NOTE_B0}; -volatile uint8_t mpuIsReady=1; +//volatile uint8_t mpuIsReady=1; extern volatile uint8_t animating; volatile unsigned long lastcolon; -unsigned long _tm=millis(); + char strtmpbuf[15]; //extern volatile unsigned long lastcolon; @@ -131,13 +133,16 @@ if(animating){ void updateThings( ){ +// handleBle(); //get3231Date(); // dt =Rtc.GetDateTime();// RtcDateTime(__DATE__, __TIME__); // if(seconds==0) { /// TODO change batteryread to something more global - if(millis()-batteryread>1000){ + if(millis()-batteryread>50){ + updateMpu6050(); + handleBle(); batterylevel=readBattery(BATTERY_EN,BATTERY_PIN); //updateMpu6050(); // updateMpu6050(); @@ -157,18 +162,14 @@ if(batterylevel<530){ batteryread=millis(); }else{ - if(0){ - // digitalWrite(13,HIGH); - //delay(1000); - mpuIsReady=0; - } } //} } -void gotoWatchFace(){ +void gotoWatchFace(){ + stopSqw(); watchMode=0; nextUIFunc= drawWatchFace;//printWatchFace;//printWatchFace;// drawWatchFace;// printWatchFace; @@ -176,27 +177,30 @@ watchMode=0; functions[sw2Func]=NULL; functions[sw3Func]=NULL; - functions[usbFunc]=drawUsb; - functions[batteryFunc]=drawBattery; + // functions[usbFunc]=drawUsb; + // functions[batteryFunc]=drawBattery; // functions[updateFunc]=updateThings; // } } + void gotoMenu( ){ stopSqw(); menuspeed=0; + nextUIFunc=drawMenus; functions[sw1Func]=menusw1; functions[sw2Func]=menusw2; functions[sw3Func]=menusw3; - functions[batteryFunc]=NULL; + // functions[batteryFunc]=NULL; - functions[usbFunc]=NULL; +// functions[usbFunc]=NULL; // Old_DEVICESTATE=DEVICESTATE; /// TODO DEFINE ACTIONCOMPLETE } + void gotoSettings( ){ stopSqw(); if( (~SW1_WASPUSHED)&SW1_PUSHED){ @@ -208,9 +212,9 @@ stopSqw(); functions[sw2Func]=menusw2; functions[sw3Func]=menusw3; // speed=0; - functions[batteryFunc]=NULL; + // functions[batteryFunc]=NULL; // batteryFunc=drawBattery; - functions[usbFunc]=NULL; + //functions[usbFunc]=NULL; // Old_DEVICESTATE=DEVICESTATE; /// TODO DEFINE ACTIONCOMPLETE @@ -229,10 +233,10 @@ stopSqw(); // nextUIFunc=functions[ uiFunc]; // sw2Func=gotoMenu; // sw3Func=NULL; - functions[ bleFunc] =handleBle; - functions[usbFunc]=NULL; - functions[batteryFunc]=NULL; - functions[updateFunc]=updateThings; + // functions[ bleFunc] =handleBle; + // functions[usbFunc]=NULL; + // functions[batteryFunc]=NULL; + // functions[updateFunc]=updateThings; } } void gotoStopWatch(){ @@ -270,16 +274,17 @@ void gotoDiagnostic(){ - +/* void intUpdate(){ mpuIsReady=1; } +*/ void setup() { /// stopSqw(); menuspeed=0; -soundenabled=true; + sound.tone(1200, 100,1000, 50,1800, 200); //setPrescale(); //while(!Serial); @@ -295,113 +300,76 @@ sound.tone(1200, 100,1000, 50,1800, 200); //Serial.begin(115200); -pinMode(rstPin, OUTPUT); +pinMode(MPU_INT,INPUT_PULLUP); pinMode(CHARGE_PIN,INPUT); + pinMode(13,OUTPUT); +pinMode(rstPin, OUTPUT); pinMode(LED1, OUTPUT); pinMode(LED2, OUTPUT); -pinMode(MPU_INT,INPUT_PULLUP); - pinMode(cesPin, OUTPUT); - pinMode(dcPin, OUTPUT); +pinMode(cesPin, OUTPUT); +pinMode(dcPin, OUTPUT); digitalWrite(rstPin, HIGH); digitalWrite(MPU_INT,LOW); digitalWrite(rstPin, HIGH); digitalWrite(dcPin, HIGH); digitalWrite(cesPin, HIGH); + pinMode(SW1,INPUT_PULLUP); + pinMode(SW2,INPUT_PULLUP); + pinMode(SW3,INPUT_PULLUP); - pinMode(13,OUTPUT); pinMode(BATTERY_EN, OUTPUT); digitalWrite(BATTERY_EN,LOW); pinMode(PIN_INTERRUPT, INPUT_PULLUP); -//wdt_enable (WDTO_250MS); - // wdt_disable(); -//wdt_enable(WDTO_2S); Wire.begin(); - //ssd1306_sendCommand(SSD1306_SEGREMAP | 0x2); - /* Set range of the SpritePool field on the screen in blocks. * - * Use whole LCD display * - * 0,0 means left-top block of lcd display. * - * that is 0*8=0 - pixel * - * 0*8=0 - pixel * - * 15,7 means right-bottom block of lcd: * - * that is 15*8+7=127-th pixel * - * 7*8+7=63-rd pixel */ -//setDateTime(); - -// ble_connect(); // TODO: bluetoot enable / disable - attachInterrupt(digitalPinToInterrupt(PIN_INTERRUPT), nextSecond, CHANGE); - attachInterrupt(digitalPinToInterrupt(MPU_INT), intUpdate, RISING); -//MPU6050_Initialize(); -//MPU6050_begin(); + attachInterrupt(digitalPinToInterrupt(PIN_INTERRUPT), nextSecond, CHANGE); -//startMpu6050(); - /* - mpu.begin(); -mpu.setAccelPowerOnDelay(MPU6050_DELAY_3MS); -mpu.setIntFreeFallEnabled(true); -mpu.setIntZeroMotionEnabled(true); -mpu.setIntMotionEnabled(true); + startSqw(); /// Starts 1 second SquareWave from DS3231 -mpu.setDHPFMode(MPU6050_DHPF_5HZ); -mpu.setMotionDetectionThreshold(2); -mpu.setMotionDetectionDuration(5); +setDateTime(); -mpu.setZeroMotionDetectionThreshold(4); -mpu.setZeroMotionDetectionDuration(2); -MAG3110_begin(); -/**/ -// mpu6050.calcGyroOffsets(true); - startSqw(); /// Starts 1 second SquareWave from DS3231 +ble_connect(); +//functions[ bleFunc] =handleBle; + ssd1306_configure(); -//get3231Temp(); -setDateTime(); - - pinMode(SW1,INPUT_PULLUP); - pinMode(SW2,INPUT_PULLUP); - pinMode(SW3,INPUT_PULLUP); - ssd1306_configure(); + gotoWatchFace(); -//goto -//functions[uiFunc]=drawWatchFace; - functions[ bleFunc] =handleBle; - gotoWatchFace(); - // gotoDiagnostic(true); startMpu6050(); updateThings(); -//Serial.println("."); //// TODO: idkw serial must print something for stability. -//delay(100); -//cli(); + } -//uint8_t buffer[64*128/8]; + uint8_t anmof=0; void drawLoop( ){ -clearAll(); + memset(mbuf, 0x00, 1024); +//return; +//clearAll(); if(nextUIFunc!=NULL){ animation_offsetY=anmof-64; - handleFunction(nextUIFunc); ///// todo draw not stable !!! + handleFunction(nextUIFunc); animation_offsetY=anmof; handleFunction(functions[uiFunc]); @@ -409,8 +377,7 @@ animation_offsetY=anmof; anmof+=(64-anmof)/16+1; -//Serial.println("."); -//delay(5); + if(anmof>64){ anmof=0; @@ -424,13 +391,13 @@ anmof+=(64-anmof)/16+1; }else{ animation_offsetY=0; -for(int a=0;a>4); -// buttons = buttons | (((~PIND) & B00010000) >>3); ///B00011000 => SQW pin _BV(4) -// DEVICESTATE=(USBDEVICE )|((digitalRead(SW1)==LOW))|((digitalRead(SW2)==LOW)<<1)|((digitalRead(SW3)==LOW)<<2); - DEVICESTATE= (USBDEVICE)|((((~PINB) & B11010000)+B00010000)>>5);//;//|((digitalRead(SW2)==LOW)<<1)|((digitalRead(SW3)==LOW)<<2); + + DEVICESTATE= (USBDEVICE)|((((~PINB) & B11010000)+B00010000)>>5);//;//|((digitalRead(SW2)==LOW)<<1)|((digitalRead(SW3)==LOW)<<2); + if(DEVICESTATE!=Old_DEVICESTATE){ -// ssd1306_fillScreen(0x00); -// interact(); -//buttonFX(2400); if(DEVICESTATE&B00000111){ -//Serial.println(DEVICESTATE&B00000111); -// if(animation_offsetY==0) switch(DEVICESTATE&B00000111){ case 1: @@ -463,7 +424,6 @@ if(DEVICESTATE&B00000111){ handleFunction(functions[sw1Func]); } - // gotoMenu(); break; case 2: if(~(SW2_WASPUSHED)&&SW2_PUSHED) @@ -487,11 +447,9 @@ buttonFX(500|((DEVICESTATE&B00000111)*300)); } digitalWrite(LED2,sound.playing()?HIGH: LOW); +updateThings(); drawLoop(); -if(millis()-_tm>300){ -// updateMpu6050(); - _tm=millis(); -} + diff --git a/watchX/src/watchX.h b/watchX/src/watchX.h index db5d4de..321f660 100644 --- a/watchX/src/watchX.h +++ b/watchX/src/watchX.h @@ -2,11 +2,12 @@ #define WATCHX_H #include -#include "batteryui.h" + #include "watchface.h" #include "menu.h" #include "temperature.h" -#include +//#include +#include "watchXmpu6050.h" #define SW1 8 #define SW2 11 @@ -50,7 +51,7 @@ enum CMD{END=0,TEXT,BITMAP,LINE,STATE,ANIMATE,RECT}; enum STATES{PROGRESS=0,DONE}; enum ANIMATIONS{LINEARX=0,LINEARY,SWINGX,SWINGY}; -enum WATCHKEYS{PREVKEY=10,NEXTKEY=11,SELECTKEY=8}; +//enum WATCHKEYS{PREVKEY=10,NEXTKEY=11,SELECTKEY=8}; typedef void (*func_type)( ); @@ -74,15 +75,15 @@ typedef void (*func_type)( ); #define SECOND_CHANGED DEVICESTATE&8 #define SECOND_WASCHANGED Old_DEVICESTATE&8 -#define HANDLEDFUNCTIONS_COUNT 5 -#define usbFunc 0 -#define sw1Func 7 -#define sw2Func 6 -#define sw3Func 5 -#define uiFunc 4 -#define batteryFunc 2 -#define bleFunc 1 -#define updateFunc 3 +#define HANDLEDFUNCTIONS_COUNT 2 +//#define usbFunc 0 +#define sw1Func 4 +#define sw2Func 3 +#define sw3Func 2 +#define uiFunc 1 +//#define batteryFunc 2 +#define bleFunc 0 +//#define updateFunc 3 extern volatile uint8_t animating; extern volatile unsigned long lastcolon; @@ -101,6 +102,7 @@ void handleFunction(func_type f); void gotoMenu( ); void gotoWatchFace( ); + void gotoGyroFace( ); void gotoDiagnostic(); void gotoStopWatch( ); diff --git a/watchX/src/watchface.cpp b/watchX/src/watchface.cpp index ce8d80d..3212f2b 100644 --- a/watchX/src/watchface.cpp +++ b/watchX/src/watchface.cpp @@ -3,6 +3,7 @@ #include "rtc.h" #include "oled.h" #include "cpu.h" +#include "battery.h" //#include @@ -11,13 +12,13 @@ //uint8_t buf2[16*2]; - int speed; + int8_t speed; //unsigned int i=0; - const char months[12][BUFFSIZE_STR_MONTHS] = { + const char months[12][BUFFSIZE_STR_MONTHS] PROGMEM = { "JAN", "FEB", "MAR", @@ -33,7 +34,7 @@ }; - const char days[7][BUFFSIZE_STR_DAYS] = { + const char days[7][BUFFSIZE_STR_DAYS] PROGMEM = { "MON", "TUE", "WED", @@ -46,9 +47,12 @@ void drawWatchFace( ){ if(watchMode==0){ unsigned char b[16] =" 00 2000"; -memcpy(b,days[day],3); +for(byte i=0;i<3;i++){ -memcpy(b+7,months[month],3); + b[i]=pgm_read_byte(days[day]+i); + b[i+7]=pgm_read_byte(months[month]+i); + +} b[13]+=year/10; b[14]+=year%10; @@ -145,4 +149,21 @@ if(lastcolon<256){ lastcolon+=speed; } //else lastcolon=0; + +////usbFunc +if(DEVICESTATE&128){ +// draw_bitmap(40, 0, watchXui,8,8,false,0); +if(digitalRead(CHARGE_PIN)==LOW) +draw_bitmap( 36, 56, watchXui+64, 8, 8, false, 0); + +draw_bitmap(18, 56, watchXui+80,16,8,false,0); + +// + +} + +/// battery +// +draw_bitmap( 0, 56, watchXui+(unsigned)(((batterylevel-500)/40)*16), 16, 8, false, 0); + }