diff --git a/.clang-format b/.clang-format new file mode 100644 index 000000000..8190c6206 --- /dev/null +++ b/.clang-format @@ -0,0 +1,19 @@ +BasedOnStyle: LLVM +UseTab: false +IndentWidth: 4 +AllowShortIfStatementsOnASingleLine: false +IndentCaseLabels: false +ColumnLimit: 132 +DerivePointerAlignment: false +PointerAlignment: Middle +AllowShortFunctionsOnASingleLine: None +BreakBeforeBraces: Custom +BraceWrapping: + AfterEnum: true + AfterStruct: true + AfterFunction: true + AfterNamespace: true + AfterUnion: true + AfterExternBlock: true + SplitEmptyFunction: false +SpaceAfterCStyleCast: true diff --git a/components/bm1397/include/common.h b/components/bm1397/include/common.h index 610d0b10f..4434ae9b6 100644 --- a/components/bm1397/include/common.h +++ b/components/bm1397/include/common.h @@ -1,6 +1,8 @@ #ifndef COMMON_H_ #define COMMON_H_ +#include + typedef struct __attribute__((__packed__)) { uint8_t job_id; @@ -13,8 +15,7 @@ static unsigned char _reverse_bits(unsigned char num) unsigned char reversed = 0; int i; - for (i = 0; i < 8; i++) - { + for (i = 0; i < 8; i++) { reversed <<= 1; // Left shift the reversed variable by 1 reversed |= num & 1; // Use bitwise OR to set the rightmost bit of reversed to the current bit of num num >>= 1; // Right shift num by 1 to get the next bit @@ -27,8 +28,7 @@ static int _largest_power_of_two(int num) { int power = 0; - while (num > 1) - { + while (num > 1) { num = num >> 1; power++; } diff --git a/main/http_server/axe-os/.gitignore b/main/http_server/axe-os/.gitignore index 0711527ef..8b8553c7d 100644 --- a/main/http_server/axe-os/.gitignore +++ b/main/http_server/axe-os/.gitignore @@ -22,7 +22,7 @@ yarn-error.log # Visual Studio Code .vscode/* -!.vscode/settings.json +# !.vscode/settings.json !.vscode/tasks.json !.vscode/launch.json !.vscode/extensions.json diff --git a/main/http_server/axe-os/src/app/app.module.ts b/main/http_server/axe-os/src/app/app.module.ts index 9795227f3..62be30878 100644 --- a/main/http_server/axe-os/src/app/app.module.ts +++ b/main/http_server/axe-os/src/app/app.module.ts @@ -13,6 +13,7 @@ import { HeaderComponent } from './components/header/header.component'; import { HomeComponent } from './components/home/home.component'; import { LoadingComponent } from './components/loading/loading.component'; import { ANSIPipe } from './pipes/ansi.pipe'; +import { DateAgoPipe } from './pipes/date-ago.pipe'; const components = [ AppComponent, @@ -25,7 +26,8 @@ const components = [ EditComponent, HomeComponent, LoadingComponent, - ANSIPipe + ANSIPipe, + DateAgoPipe ], imports: [ BrowserModule, diff --git a/main/http_server/axe-os/src/app/components/edit/edit.component.html b/main/http_server/axe-os/src/app/components/edit/edit.component.html index 0b6f2596a..813172e69 100644 --- a/main/http_server/axe-os/src/app/components/edit/edit.component.html +++ b/main/http_server/axe-os/src/app/components/edit/edit.component.html @@ -25,6 +25,7 @@

Edit

+
You must restart this device after saving for changes to take effect.
diff --git a/main/http_server/axe-os/src/app/components/home/home.component.html b/main/http_server/axe-os/src/app/components/home/home.component.html index e9adb65bf..0a07c3517 100644 --- a/main/http_server/axe-os/src/app/components/home/home.component.html +++ b/main/http_server/axe-os/src/app/components/home/home.component.html @@ -17,8 +17,8 @@

Overview

{{info.ASICModel}} - Uptime (seconds): - {{info.uptimeSeconds}} + Uptime: + {{info.uptimeSeconds | dateAgo}} diff --git a/main/http_server/axe-os/src/app/pipes/date-ago.pipe.spec.ts b/main/http_server/axe-os/src/app/pipes/date-ago.pipe.spec.ts new file mode 100644 index 000000000..47ac2978c --- /dev/null +++ b/main/http_server/axe-os/src/app/pipes/date-ago.pipe.spec.ts @@ -0,0 +1,8 @@ +import { DateAgoPipe } from './date-ago.pipe'; + +describe('DateAgoPipe', () => { + it('create an instance', () => { + const pipe = new DateAgoPipe(); + expect(pipe).toBeTruthy(); + }); +}); diff --git a/main/http_server/axe-os/src/app/pipes/date-ago.pipe.ts b/main/http_server/axe-os/src/app/pipes/date-ago.pipe.ts new file mode 100644 index 000000000..48659dd0b --- /dev/null +++ b/main/http_server/axe-os/src/app/pipes/date-ago.pipe.ts @@ -0,0 +1,38 @@ +import { Pipe, PipeTransform } from '@angular/core'; + +@Pipe({ + name: 'dateAgo', + pure: true +}) +export class DateAgoPipe implements PipeTransform { + + transform(value: any, args?: any): any { + if (value) { + value = new Date().getTime() - value * 1000; + const seconds = Math.floor((+new Date() - +new Date(value)) / 1000); + if (seconds < 29) // less than 30 seconds ago will show as 'Just now' + return 'Just now'; + const intervals: { [key: string]: number } = { + 'year': 31536000, + 'month': 2592000, + 'week': 604800, + 'day': 86400, + 'hour': 3600, + 'minute': 60, + 'second': 1 + }; + let counter; + for (const i in intervals) { + counter = Math.floor(seconds / intervals[i]); + if (counter > 0) + if (counter === 1) { + return counter + ' ' + i + ''; // singular (1 day ago) + } else { + return counter + ' ' + i + 's'; // plural (2 days ago) + } + } + } + return value; + } + +} \ No newline at end of file