-
Notifications
You must be signed in to change notification settings - Fork 25
Added mutability checks for Gfx #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from 14 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
8fbad7c
Added mutability checks for Gfx
Meziu 45bf4b5
Separate screens and internal mutability for Gfx
Meziu 53aa05a
Split Screen enum into structs and trait
Meziu 04a35e4
Fixed Screen accessibility
Meziu ae00883
Update ctru-rs/src/gfx.rs
Meziu 0927167
Fixed ownership of Screen borrow for Console
Meziu 2ed31e5
Removed PhantomData dependency
Meziu a879e02
Update ctru-rs/src/console.rs
Meziu 526f7cc
Console requires mutable Screen
Meziu 38fef16
Simple examples working with new Screen impl
Meziu 4a48926
gfx-wide-mode example working
Meziu 46a615c
Substituted hello-world example
Meziu 29b7a7d
Added network-sockets example
Meziu 2bc475d
Formatting
Meziu 366db9e
Fixed clippy suggestions
Meziu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,44 @@ | ||
extern crate ctru; | ||
Meziu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
use ctru::console::Console; | ||
use ctru::gfx::{Gfx, Screen}; | ||
use ctru::gfx::Gfx; | ||
use ctru::services::apt::Apt; | ||
use ctru::services::hid::{Hid, KeyPad}; | ||
|
||
fn main() { | ||
// Initialize ctrulib service handles. | ||
// Service handles are internally reference-counted. When all instances of a | ||
// service handle go out of scope, the service will be closed. | ||
ctru::init(); | ||
extern crate ferris_says; | ||
Meziu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// The APT service handles application management functions, such as enabling sleep | ||
// mode and jumping to the home menu or to other applications | ||
let apt = Apt::init().unwrap(); | ||
use std::io::BufWriter; | ||
|
||
// The HID service handles button and touch screen inputs. | ||
let hid = Hid::init().unwrap(); | ||
|
||
// The GFX service manages the framebuffers for the top and bottom screens. | ||
fn main() { | ||
ctru::init(); | ||
let gfx = Gfx::default(); | ||
let hid = Hid::init().expect("Couldn't obtain HID controller"); | ||
let apt = Apt::init().expect("Couldn't obtain APT controller"); | ||
let _console = Console::init(gfx.top_screen.borrow_mut()); | ||
|
||
// Initialize a ctrulib console and direct standard output to it. | ||
// Consoles can be initialized on both the top and bottom screens. | ||
let _console = Console::init(&gfx, Screen::Top); | ||
let out = b"Hello fellow Rustaceans, I'm on the Nintendo 3DS!"; | ||
let width = 24; | ||
|
||
// Now we can print to stdout! | ||
println!("Hello, world!"); | ||
let mut writer = BufWriter::new(Vec::new()); | ||
ferris_says::say(out, width, &mut writer).unwrap(); | ||
|
||
// We can use escape sequences to move the cursor around the terminal. | ||
// The following text will be moved down 29 rows and right 16 characters | ||
// before printing begins. | ||
println!("\x1b[29;16HPress Start to exit"); | ||
println!( | ||
"\x1b[0;0H{}", | ||
String::from_utf8_lossy(&writer.into_inner().unwrap()) | ||
); | ||
|
||
// Main application loop. | ||
// Main loop | ||
while apt.main_loop() { | ||
// Flushes and swaps the framebuffers when double-buffering | ||
// is enabled | ||
gfx.flush_buffers(); | ||
gfx.swap_buffers(); | ||
|
||
// Wait for the next frame to begin | ||
gfx.wait_for_vblank(); | ||
|
||
// Scan for user input. | ||
//Scan all the inputs. This should be done once for each frame | ||
hid.scan_input(); | ||
|
||
// Check if the user has pressed the given button on this frame. | ||
// If so, break out of the loop. | ||
if hid.keys_down().contains(KeyPad::KEY_START) { | ||
break; | ||
} | ||
} | ||
// Flush and swap framebuffers | ||
gfx.flush_buffers(); | ||
gfx.swap_buffers(); | ||
|
||
// All of our service handles will drop out of scope at this point, | ||
// triggering the end of our application. | ||
//Wait for VBlank | ||
gfx.wait_for_vblank(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
extern crate ctru; | ||
Meziu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
use ctru::console::Console; | ||
use ctru::gfx::Gfx; | ||
use ctru::services::apt::Apt; | ||
use ctru::services::hid::{Hid, KeyPad}; | ||
use ctru::services::soc::Soc; | ||
|
||
use std::io::{Read, Write}; | ||
use std::net::{Shutdown, TcpListener}; | ||
use std::time::Duration; | ||
|
||
fn main() { | ||
ctru::init(); | ||
let gfx = Gfx::default(); | ||
let _console = Console::init(gfx.top_screen.borrow_mut()); | ||
let hid = Hid::init().unwrap(); | ||
let apt = Apt::init().unwrap(); | ||
|
||
println!("\nlibctru sockets demo\n"); | ||
|
||
let soc = Soc::init().unwrap(); | ||
|
||
let server = TcpListener::bind("0.0.0.0:80").unwrap(); | ||
server.set_nonblocking(true).unwrap(); | ||
|
||
println!("Point your browser to http://{}/\n", soc.host_address()); | ||
|
||
while apt.main_loop() { | ||
gfx.wait_for_vblank(); | ||
|
||
match server.accept() { | ||
Ok((mut stream, socket_addr)) => { | ||
println!("Got connection from {}", socket_addr); | ||
|
||
let mut buf = [0u8; 4096]; | ||
match stream.read(&mut buf) { | ||
Ok(_) => { | ||
let req_str = String::from_utf8_lossy(&buf); | ||
println!("{}", req_str); | ||
} | ||
Err(e) => println!("Unable to read stream: {}", e), | ||
} | ||
|
||
let response = b"HTTP/1.1 200 OK\r\nContent-Type: text/html; charset=UTF-8\r\n\r\n<html><body>Hello world</body></html>\r\n"; | ||
|
||
if let Err(e) = stream.write(response) { | ||
println!("Error writing http response: {}", e); | ||
} | ||
|
||
stream.shutdown(Shutdown::Both).unwrap(); | ||
} | ||
Err(e) => match e.kind() { | ||
std::io::ErrorKind::WouldBlock => {} | ||
_ => { | ||
println!("Error accepting connection: {}", e); | ||
std::thread::sleep(Duration::from_secs(2)); | ||
} | ||
}, | ||
} | ||
|
||
hid.scan_input(); | ||
if hid.keys_down().contains(KeyPad::KEY_START) { | ||
break; | ||
}; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.