Skip to content

Commit

Permalink
more stable...
Browse files Browse the repository at this point in the history
  • Loading branch information
murataka committed Apr 11, 2018
1 parent 3a160df commit 54eb937
Show file tree
Hide file tree
Showing 24 changed files with 232 additions and 272 deletions.
66 changes: 46 additions & 20 deletions watchX/lib/SSD1306/oled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
#include <SPI.h>

#include "oled.h"
unsigned char animation_offsetY=0;
unsigned char mbuf[1024]={0};

uint8_t uiX,uiY;

/*
Expand All @@ -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
};

Expand Down Expand Up @@ -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<strlen_P(s);a++){
c=pgm_read_byte_near(s+a);

// strtmpbuf[a]= pgm_read_byte_near(months[month]+a);
// draw_bitmap( 0, 32, font_mid, 19, 24, false, 0);

draw_bitmap( x+(a*6), y, font+((startindex+c)*5), 5, 8, false, 0);


}

}
void drawString(uint8_t x,uint8_t y,const char*s,const byte* font,char startindex){
char a=0;
if(!s)return;
Expand Down Expand Up @@ -222,7 +248,7 @@ void draw_bitmap(byte x, byte yy, const byte* bitmap, byte w, byte h, bool inver
byte h2 = h / 8;

//
byte pixelOffset = (y % 8);


byte thing3 = (yy+h);

Expand Down Expand Up @@ -253,7 +279,7 @@ void draw_bitmap(byte x, byte yy, const byte* bitmap, byte w, byte h, bool inver

// If() outside of loop makes it faster (doesn't have to keep re-evaluating it)
// Downside is code duplication
if(!pixelOffset && hhh < FRAME_HEIGHT)
if(!(y % 8) && hhh < FRAME_HEIGHT)
{
//
LOOP(w, ww)
Expand Down Expand Up @@ -292,13 +318,13 @@ void draw_bitmap(byte x, byte yy, const byte* bitmap, byte w, byte h, bool inver

//
if(hhh < FRAME_HEIGHT)
mbuf[xx + aa] |= pixels << pixelOffset;
//setBuffByte(buff, xx, hhh, pixels << pixelOffset, colour);
mbuf[xx + aa] |= pixels << (y % 8);
//setBuffByte(buff, xx, hhh, pixels << (y % 8), colour);

//
if(hhhh < FRAME_HEIGHT)
mbuf[xx + aaa] |= pixels >> (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);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions watchX/lib/SSD1306/oled.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion watchX/lib/battery/battery.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 7 additions & 12 deletions watchX/lib/mpu6050/tinyMpu6050.cpp
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
#include <Wire.h>
#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);

}
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)

}
4 changes: 2 additions & 2 deletions watchX/lib/mpu6050/tinyMpu6050.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef MPU6050_H
#define MPU6050_H
#include <Arduino.h>
extern int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;

extern int16_t ac[7];
void updateMpu6050();
void startMpu6050();
#endif
3 changes: 2 additions & 1 deletion watchX/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion watchX/src/BluefruitConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
13 changes: 0 additions & 13 deletions watchX/src/batteryui.cpp

This file was deleted.

6 changes: 0 additions & 6 deletions watchX/src/batteryui.h

This file was deleted.

11 changes: 6 additions & 5 deletions watchX/src/bluetooth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ if(ble.available()){ i=0;

strtmpbuf[i++]=ble.read();



}

Expand All @@ -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);

}
Expand All @@ -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!

Expand Down
6 changes: 3 additions & 3 deletions watchX/src/bluetooth.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
#include <SoftwareSerial.h>
#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();

Expand All @@ -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
4 changes: 2 additions & 2 deletions watchX/src/diag.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef DIAG_H
#define DIAG_H
#include "usb.h"

void drawDiag();


#endif
22 changes: 11 additions & 11 deletions watchX/src/english.h
Original file line number Diff line number Diff line change
Expand Up @@ -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")



Expand All @@ -42,7 +42,7 @@
#define STR_DOWCHARS "MTWTFSS"



/*
// Days
// Also see BUFFSIZE_STR_DAYS
#define STR_MON "Mon"
Expand All @@ -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"
Expand Down Expand Up @@ -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
/*
Expand Down
24 changes: 13 additions & 11 deletions watchX/src/gyrocube.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "gyrocube.h"
#include "oled.h"
#include <tinyMpu6050.h>

#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.
Expand All @@ -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;
Expand All @@ -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; //
Expand Down
Loading

0 comments on commit 54eb937

Please sign in to comment.